Skip to content
Merged
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
6 changes: 5 additions & 1 deletion crates/accelerate/src/unitary_synthesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ fn get_2q_decomposers_from_target(
let mut available_2q_props: IndexMap<&str, (Option<f64>, Option<f64>)> = IndexMap::new();

let mut qubit_gate_map = IndexMap::new();

match target.operation_names_for_qargs(Some(&qubits)) {
Ok(direct_keys) => {
qubit_gate_map.insert(&qubits, direct_keys);
Expand Down Expand Up @@ -597,7 +598,10 @@ fn get_2q_decomposers_from_target(
OperationRef::Standard(_) => (),
_ => continue,
}

// Filter out non-2q-gate candidates
if op.operation.num_qubits() != 2 {
continue;
}
available_2q_basis.insert(key, replace_parametrized_gate(op.clone()));

if target.contains_key(key) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
Fixed a bug in the :class:`.UnitarySynthesis` transpiler pass where
non-2-qubit gates would be included in the available 2 qubit basis,
causing the ``TwoQubitWeylDecomposition`` to panic because of
the dimension mismatch.
15 changes: 15 additions & 0 deletions test/python/transpiler/test_unitary_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,21 @@ def test_3q_measure_all(self):
self.assertIn("cx", ops)
self.assertIn("measure", ops)

def test_target_with_global_gates(self):
"""Test that 2q decomposition can handle a target with global gates."""

basis_gates = ["h", "p", "cp", "rz", "cx", "ccx", "swap"]
target = Target.from_configuration(basis_gates=basis_gates)

bell = QuantumCircuit(2)
bell.h(0)
bell.cx(0, 1)
bell_op = Operator(bell)
qc = QuantumCircuit(2)
qc.unitary(bell_op, [0, 1])
tqc = transpile(qc, target=target)
self.assertTrue(set(tqc.count_ops()).issubset(basis_gates))


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