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 a bug in isometry.rs (backport #12469) #12471

Merged
merged 1 commit into from
May 28, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented May 28, 2024

Summary

After PR #12197 was merged, there is a bug with the following code:

num_qubits = 3
num_controls = 4
u = random_unitary(2 ** num_qubits)
ug = UnitaryGate(u)
cug = ug.control(num_controls)
cug 

The code is working for num_qubits = 1 or 2 but not for 3 or 4 or 5, and raises the following error:

/qiskit/circuit/library/generalized_gates/isometry.py:221, in Isometry._disentangle(self, circuit, q, diag, remaining_isometry, column_index, s)
    217 diagonal_mcg = self._append_mcg_up_to_diagonal(
    218     circuit, q, gate, control_labels, target_label
    219 )
    220 # apply the MCG to the remaining isometry
--> 221 v = isometry_rs.apply_multi_controlled_gate(v, control_labels, target_label, gate)
    222 # correct for the implementation "up to diagonal"
    223 diag_mcg_inverse = np.conj(diagonal_mcg).astype(complex, copy=False)

PanicException: assertion failed: j <= 1

Details and comments

The solution is to remove the assertion assert!(j <= 1) in crates/accelerate/src/isometry.rs:215:13


This is an automatic backport of pull request #12469 done by [Mergify](https://mergify.com).

* remove assertion

* extend the test

* add release notes

* fix release notes

* Update releasenotes/notes/fix-isometry-rust-adf0eed09c6611f1.yaml

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

---------

Co-authored-by: Matthew Treinish <[email protected]>
(cherry picked from commit 0f0a634)
@mergify mergify bot requested a review from a team as a code owner May 28, 2024 18:46
@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:

@github-actions github-actions bot added Changelog: Bugfix Include in the "Fixed" section of the changelog Rust This PR or issue is related to Rust code in the repository labels May 28, 2024
@github-actions github-actions bot added this to the 1.1.1 milestone May 28, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 9274742625

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 19 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.01%) to 89.619%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 7 92.37%
crates/qasm2/src/parse.rs 12 97.15%
Totals Coverage Status
Change from base Build 9164868799: -0.01%
Covered Lines: 62247
Relevant Lines: 69457

💛 - Coveralls

@mtreinish mtreinish added this pull request to the merge queue May 28, 2024
Merged via the queue into stable/1.1 with commit bac400d May 28, 2024
16 of 18 checks passed
@mergify mergify bot deleted the mergify/bp/stable/1.1/pr-12469 branch May 28, 2024 20:43
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 Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants