Skip to content

Commit

Permalink
Transpiler add passes that might be out of the default basis (Qiskit#…
Browse files Browse the repository at this point in the history
…2357)

Fixes Qiskit#2349

When a basis is not defined for a circuit, the default basis set is the
set of gates used in the circuit. This makes total sense to me.

However, passes might add gates and the might be out of that bases. For
this reason, I'm suggesting to add the base basis (UBase and CXBase) as
part of the default basis set. If I understand correctly, the base
basis (is that their name?) is supported by every backend by
definition, so the gates that are added by the transpiler can run in
the backend.

(cherry picked from commit 4bfcc5d)
  • Loading branch information
1ucian0 authored and mtreinish committed May 9, 2019
1 parent e9957ec commit ad4b661
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions qiskit/compiler/transpile.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,14 @@ def _parse_basis_gates(basis_gates, backend, circuits):
if basis_gates is None or (isinstance(basis_gates, list) and
all(isinstance(i, str) for i in basis_gates)):
basis_gates = [basis_gates] * len(circuits)
# no basis means don't unroll (all circuit gates are valid basis)
basis_gates = [[inst.name for inst, _, _ in circuit.data] if basis is None
else basis for basis, circuit in zip(basis_gates, circuits)]

# no basis means don't unroll (all circuit gates are valid basis)
for index, circuit in enumerate(circuits):
basis = basis_gates[index]
if basis is None:
gates_in_circuit = set(inst.name for inst, _, _ in circuit.data)
# Other passes might add new gates that need to be supported
basis_gates[index] = list(gates_in_circuit.union(['u3', 'cx']))
return basis_gates


Expand Down

0 comments on commit ad4b661

Please sign in to comment.