Skip to content

Commit

Permalink
Fix missing handling of no-synthesis case in UnitarySynthesis (Qisk…
Browse files Browse the repository at this point in the history
…it#9843)

Since moving `Optimize1qDecomposition` down to the Rust level, some of
its use in the default `UnitarySynthesis` plugin was allowing `None` to
be passed to an internal function unchecked.  This correctly returns the
"could not synthesise" value when appropriate.
  • Loading branch information
jakelishman committed Mar 23, 2023
1 parent 84a0fdd commit 5a19f8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions qiskit/transpiler/passes/synthesis/unitary_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,10 @@ def run(self, unitary, **options):

if unitary.shape == (2, 2):
_decomposer1q = Optimize1qGatesDecomposition(basis_gates, target)
return _decomposer1q._gate_sequence_to_dag(
_decomposer1q._resynthesize_run(unitary, qubits[0])
)
sequence = _decomposer1q._resynthesize_run(unitary, qubits[0])
if sequence is None:
return None
return _decomposer1q._gate_sequence_to_dag(sequence)
elif unitary.shape == (4, 4):
# select synthesizers that can lower to the target
if target is not None:
Expand Down
6 changes: 6 additions & 0 deletions test/python/transpiler/test_unitary_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,12 @@ def __init__(self):
result_qc = dag_to_circuit(result_dag)
self.assertEqual(result_qc, QuantumCircuit(2))

def test_default_does_not_fail_on_no_syntheses(self):
qc = QuantumCircuit(1)
qc.unitary(np.eye(2), [0])
pass_ = UnitarySynthesis(["unknown", "gates"])
self.assertEqual(qc, pass_(qc))


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

0 comments on commit 5a19f8a

Please sign in to comment.