-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Added missing label
support for some QuantumCircuit
gate-applying methods
#14980
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
base: main
Are you sure you want to change the base?
Added missing label
support for some QuantumCircuit
gate-applying methods
#14980
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the following people are relevant to this code:
|
|
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.
Thanks for this, and sorry for the slow reply.
Please can you also add a release note (reno new <...>
) , and you'll need to run the code formatter too (tox -e black
).
class TestGateLabels(QiskitTestCase): | ||
def test_gate_labels_are_applied(self): |
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.
Could we put this test function in an existing class in test/python/circuit/test_circuit_operations.py
, just to avoid an extra stub file? There's no perfect place for it, but I think we can avoid the new file.
# Check labels are there | ||
assert qc.data[0].label == "rz_gate" | ||
assert qc.data[1].label == "rxx_gate" | ||
assert qc.data[2].label == "s_gate" |
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.
Qiskit uses the built-in unittest
runner, so these should be self.assertEqual(qc.data[0].label, "rz_gate")
to handle assertion failures / messages better.
Summary
Problem:
Some common gate-applying
QuantumCircuit
methods, such asrz
ands
did not accept alabel
argument.This led to some inconsistencies, such as
qc.rx(np.pi, 0, label = "gate 0")
working as intended butqc.rz(np.pi, 0, label = "gate 1")
raising an error.Fix:
Fix: Added a
label
to some of those methods and passed it to theself._append_standard_gate
callTest:
Added
test/python/circuit/test_gate_labels.py
to check that some of the fixed gates don't raise an error when invoked with alabel
, and that they retain the label afterwardsDetails and comments
QuantumCircuit
class, and this fix is by no means extensivelabel
attribute #14975