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 missing handling of no-synthesis case in UnitarySynthesis #9843

Merged
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
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()