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 UnitarySynthesis for 3+ qubits when compiled for a backend #13591

Merged
merged 5 commits into from
Jan 7, 2025

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Dec 20, 2024

Summary

When encountering a 3+ qubit UnitaryGate, UnitarySynthesis currently replaces the whole dag with the definition of the block instead of appending it, see

Details and comments

This also leads to #13586 because the qubit/clbit interners are overwritten, but maybe more importantly this can lead to issues when multiple 3-qubit blocks are present in the circuit. E.g. running

import numpy as np
from qiskit.quantum_info import Operator
from qiskit.circuit.library import UnitaryGate
from qiskit import QuantumCircuit, transpile
from qiskit_ibm_runtime.fake_provider import FakeSherbrooke

backend = FakeSherbrooke()

x = QuantumCircuit(3)
x.x(2)
x_mat = Operator(x)

qc = QuantumCircuit(3, 1)
qc.unitary(x_mat, range(3))
qc.unitary(np.eye(2 ** 3), range(3))

tqc = transpile(qc, backend, optimization_level=0)
print(tqc.count_ops())

produces an empty circuit, since the last block implements the identity.

Some additional tests, such as the precise case of #13586 and a series of 3q UnitaryGates, should be added.

@Cryoris Cryoris added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog Rust This PR or issue is related to Rust code in the repository labels Dec 20, 2024
@Cryoris Cryoris added this to the 1.3.2 milestone Dec 20, 2024
@Cryoris Cryoris requested a review from a team as a code owner December 20, 2024 16:12
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Dec 20, 2024

Pull Request Test Coverage Report for Build 12650420997

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

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

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 91.73%
qiskit/primitives/containers/observables_array.py 5 95.0%
crates/qasm2/src/parse.rs 18 96.23%
qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py 20 94.58%
Totals Coverage Status
Change from base Build 12420636821: -0.01%
Covered Lines: 79419
Relevant Lines: 89295

💛 - Coveralls

@alexanderivrii
Copy link
Contributor

Thanks for the fix, @Cryoris!

Looks good! (modulo some minor spell-checking nitpicks about the release notes)

Some additional tests, such as the precise case of #13586 and a series of 3q UnitaryGates, should be added.

Are you planning to add a test for that (like the one you have in the code snippet in the description)?

@Cryoris
Copy link
Contributor Author

Cryoris commented Jan 6, 2025

@alexanderivrii more tests added in 583ec3d 🙂

@Cryoris Cryoris enabled auto-merge January 7, 2025 12:24
@Cryoris Cryoris added this pull request to the merge queue Jan 7, 2025
Merged via the queue into Qiskit:main with commit 86a5325 Jan 7, 2025
17 checks passed
mergify bot pushed a commit that referenced this pull request Jan 7, 2025
)

* Fix unitary synthesis for 3+ q

* Update releasenotes/notes/fix-unitary-synthesis-3q-2b2de5305bfd11ff.yaml

Co-authored-by: Alexander Ivrii <[email protected]>

* add more tests

* use == over equiv

---------

Co-authored-by: Alexander Ivrii <[email protected]>
(cherry picked from commit 86a5325)
github-merge-queue bot pushed a commit that referenced this pull request Jan 7, 2025
) (#13619)

* Fix unitary synthesis for 3+ q

* Update releasenotes/notes/fix-unitary-synthesis-3q-2b2de5305bfd11ff.yaml

Co-authored-by: Alexander Ivrii <[email protected]>

* add more tests

* use == over equiv

---------

Co-authored-by: Alexander Ivrii <[email protected]>
(cherry picked from commit 86a5325)

Co-authored-by: Julien Gacon <[email protected]>
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 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.

Rust exeception raised when transpiling PaulEvolutionGate with measurements against backend
4 participants