Skip to content

Conversation

Bruno-Danti
Copy link

Summary

Problem:

Some common gate-applying QuantumCircuit methods, such as rz and s did not accept a label argument.

This led to some inconsistencies, such as qc.rx(np.pi, 0, label = "gate 0") working as intended but qc.rz(np.pi, 0, label = "gate 1") raising an error.

Fix:

Fix: Added a label to some of those methods and passed it to the self._append_standard_gate call

Test:

Added test/python/circuit/test_gate_labels.py to check that some of the fixed gates don't raise an error when invoked with a label, and that they retain the label afterwards

Details and comments

@Bruno-Danti Bruno-Danti requested a review from a team as a code owner September 2, 2025 23:13
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Sep 2, 2025
@qiskit-bot
Copy link
Collaborator

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:

  • @Qiskit/terra-core

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Member

@jakelishman jakelishman left a 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).

Comment on lines +6 to +7
class TestGateLabels(QiskitTestCase):
def test_gate_labels_are_applied(self):
Copy link
Member

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.

Comment on lines +14 to +17
# 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"
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QuantumCircuit: some gates have no label attribute
4 participants