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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/accelerate/src/unitary_synthesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ fn py_run_main_loop(
None,
None,
)?;
out_dag = synth_dag;
let out_qargs = dag.get_qargs(packed_instr.qubits);
apply_synth_dag(py, &mut out_dag, out_qargs, &synth_dag)?;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fixes:
- |
Fixed a bug in the :class:`.UnitarySynthesis` transpiler pass, where blocks of
:class:`.UnitaryGate`\s of 3 qubits or more were not correctly synthesized.
This lead e.g. to the circuit being overwritten with the last processed block or
to internal panics when encountering measurements after a such a block.
Fixed `#13586 <https://github.com/Qiskit/qiskit/issues/13586>`__.
12 changes: 12 additions & 0 deletions test/python/transpiler/test_unitary_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,18 @@ def test_qsd(self, opt):
qc_transpiled = transpile(qc, target=target, optimization_level=opt)
self.assertTrue(np.allclose(mat, Operator(qc_transpiled).data))

def test_3q_with_measure(self):
"""Test 3-qubit synthesis with measurements."""
backend = FakeBackend5QV2()

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

qc_transpiled = transpile(qc, backend)
self.assertTrue(qc_transpiled.size, 1)
self.assertTrue(qc_transpiled.count_ops().get("measure", 0), 1)


if __name__ == "__main__":
unittest.main()
Loading