Skip to content
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 qpy for controlled UnitaryGate #10809

Merged
merged 10 commits into from
Oct 13, 2023
Merged

Fix qpy for controlled UnitaryGate #10809

merged 10 commits into from
Oct 13, 2023

Conversation

ElePT
Copy link
Contributor

@ElePT ElePT commented Sep 11, 2023

Summary

Fixes #10802. QPY was failing to deserialize the NUMPY_OBJ from the unitary gate definition because it was looking for the clbits of a circuit that, in that scope, was None.

Details and comments

I am not too happy about having to decompose the circuit so many times for the test. I get that after #10758, the uuid is appended to the name of the gate, which makes the circuits not equal:

>>> qc.data
[CircuitInstruction(operation=Instruction(name='c-unitary', num_qubits=2, num_clbits=0, params=[array([[0.+0.j, 1.+0.j],
       [1.+0.j, 0.+0.j]])]), qubits=(Qubit(QuantumRegister(2, 'q'), 0), Qubit(QuantumRegister(2, 'q'), 1)), clbits=())]
>>> qc2.data
[CircuitInstruction(operation=Instruction(name='c-unitary_781f2d2b-cd9a-4d8e-b38a-59d141b82ebc', num_qubits=2, num_clbits=0, params=[array([[0.+0.j, 1.+0.j],
       [1.+0.j, 0.+0.j]])]), qubits=(Qubit(QuantumRegister(2, 'q'), 0), Qubit(QuantumRegister(2, 'q'), 1)), clbits=())]

But I'm not sure why, for example, decomposing once fails:

>>> qc.decompose(reps=1).data
[CircuitInstruction(operation=Instruction(name='circuit-121_dg', num_qubits=2, num_clbits=0, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0), Qubit(QuantumRegister(2, 'q'), 1)), clbits=())]
>>> qc2.decompose(reps=1).data
[CircuitInstruction(operation=Instruction(name='circuit-121_dg', num_qubits=2, num_clbits=0, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0), Qubit(QuantumRegister(2, 'q'), 1)), clbits=())]

@ElePT ElePT requested a review from a team as a code owner September 11, 2023 09:46
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @mtreinish
  • @nkanazawa1989

@ElePT ElePT added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qpy Related to QPY serialization labels Sep 11, 2023
@coveralls
Copy link

Pull Request Test Coverage Report for Build 6144717289

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • 15 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.01%) to 87.282%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 3 91.41%
crates/qasm2/src/parse.rs 12 96.67%
Totals Coverage Status
Change from base Build 6124202354: -0.01%
Covered Lines: 74469
Relevant Lines: 85320

💛 - Coveralls

@1ucian0 1ucian0 modified the milestones: 0.25.2, 0.25.3 Sep 22, 2023
@1ucian0 1ucian0 modified the milestones: 0.25.2, 0.25.3 Oct 2, 2023
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix LGTM, but there were some merge conflicts that need to be resolved. This also might have a conflict with #10898 but I assume this will merge before that, so I'll fix it in #10898 when this merges.

test/python/circuit/test_circuit_load_from_qpy.py Outdated Show resolved Hide resolved
@mtreinish mtreinish self-assigned this Oct 9, 2023
mtreinish
mtreinish previously approved these changes Oct 11, 2023
Copy link
Member

@mtreinish mtreinish 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 the quick update.

(oh there is still a merge conflict)

qiskit/qpy/binary_io/circuits.py Outdated Show resolved Hide resolved
qiskit/qpy/binary_io/circuits.py Outdated Show resolved Hide resolved
mtreinish
mtreinish previously approved these changes Oct 13, 2023
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, thanks for the update, but I'll hold off on the merge queue because something looks weird with the last rebase, it pulled in a bunch of unrelated commits to your branch.

@mtreinish mtreinish added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Oct 13, 2023
@mtreinish mtreinish enabled auto-merge October 13, 2023 18:31
@mtreinish mtreinish added this pull request to the merge queue Oct 13, 2023
Merged via the queue into Qiskit:main with commit 9843fbf Oct 13, 2023
13 checks passed
mergify bot pushed a commit that referenced this pull request Oct 13, 2023
* Add exception for controlled gate

* Add reno

* Add fix

* Adjust test

* Update test/python/circuit/test_circuit_load_from_qpy.py

Co-authored-by: Matthew Treinish <[email protected]>

* Fix bug with ucr*-dg gates

* Fix typos in comments

* Fix typo again

---------

Co-authored-by: Matthew Treinish <[email protected]>
(cherry picked from commit 9843fbf)

# Conflicts:
#	qiskit/qpy/binary_io/circuits.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qpy Related to QPY serialization stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serialization fails for controlled unitary gate
5 participants