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 pass bug when target contains global gates #13651

Merged
merged 5 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 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,11 @@ fn get_2q_decomposers_from_target(
OperationRef::Standard(_) => (),
_ => continue,
}

// Filter out non-2q-gate candidates
match op.operation.num_qubits() {
2 => (),
_ => continue,
}
ElePT marked this conversation as resolved.
Show resolved Hide resolved
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 incuded in the available 2 qubit basis,
ShellyGarion marked this conversation as resolved.
Show resolved Hide resolved
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