Skip to content

Commit

Permalink
Fix unitary synthesis for 3+ q
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryoris committed Dec 20, 2024
1 parent 8e2aaad commit 12391af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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()

0 comments on commit 12391af

Please sign in to comment.