-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix barrier instructions in tomography experiments #1059
Changes from all commits
cb48af7
8e1cf67
844b160
9de472e
8bf8afe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fix qpy serialization and deserialization of tomography experiments. The | ||
barrier instructions in tomography experiments were created with the wrong | ||
Python type which qpy did not support. This issue was most acute when using | ||
`qiskit-ibm-provider` which submits circuits to the provider using qpy. | ||
There could have been subtler issues with circuit timing using a different | ||
provider if the barriers were not separating important circuit | ||
instructions. See `#1060 <https://github.com/Qiskit/qiskit-experiments/issues/1060>`_. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,18 @@ | |
""" | ||
StateTomography experiment tests | ||
""" | ||
import io | ||
from test.base import QiskitExperimentsTestCase | ||
from math import sqrt | ||
|
||
import ddt | ||
import numpy as np | ||
from qiskit import QuantumCircuit | ||
|
||
import qiskit.quantum_info as qi | ||
from qiskit import QuantumCircuit, qpy | ||
from qiskit.circuit.library import XGate | ||
from qiskit.result import LocalReadoutMitigator | ||
import qiskit.quantum_info as qi | ||
|
||
from qiskit_aer import AerSimulator | ||
from qiskit_aer.noise import NoiseModel | ||
|
||
|
@@ -191,6 +195,23 @@ def test_exp_circuits_measurement_indices(self, meas_qubits): | |
fid = qi.state_fidelity(target_state, qi.Statevector(target_circ)) | ||
self.assertGreater(fid, 0.99, msg="target_state is incorrect") | ||
|
||
def test_circuit_serialization(self): | ||
"""Test simple circuit serialization""" | ||
circ = QuantumCircuit(2) | ||
circ.h(0) | ||
circ.s(0) | ||
circ.cx(0, 1) | ||
|
||
exp = StateTomography(circ) | ||
circs = exp.circuits() | ||
|
||
qpy_file = io.BytesIO() | ||
qpy.dump(circs, qpy_file) | ||
qpy_file.seek(0) | ||
new_circs = qpy.load(qpy_file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beyond scope of this PR, but we should probably add similar tests for serialization of generated circuits for all experiments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opened #1063 to keep track of this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can probably use the round trip json serialization test function (like we use for experiment data), since json serializer should serialize a list of circuits via qpy. |
||
|
||
self.assertEqual(circs, new_circs) | ||
|
||
@ddt.data([0], [1], [2], [0, 1], [1, 0], [0, 2], [2, 0], [1, 2], [2, 1]) | ||
def test_full_exp_measurement_indices(self, meas_qubits): | ||
"""Test subset state tomography generation""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this one actually causing an issue? All 1-qubit instructions in terra are setup to broadcast over the arguments so shouldn't have any issues with qpy, and unless that changes I dont think we need to change this (And if there is specifically an issue with tuple, then it can be converted to a list)
eg reset doc string indicates it works with more than 1-qubit:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change it back. You and I put more weight on different parts of the quoted text 🙂 The
qubit: 'QubitSpecifier'
type annotation says to me that it accepts only a single qubit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just went with
qubit(s)
:D