4

Let's suppose I define a basis gate set and the following circuit.

import qiskit as qk
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit,Aer
backend = Aer.get_backend('unitary_simulator')

basis_gates=['h',"cx",'t'] qreg_q = QuantumRegister(1, 'q') circuit = QuantumCircuit(qreg_q) circuit.s(0) qk.transpile(QT.circuit, backend, basis_gates)

I get the TranspilerError TranspilerError: "Unable to map source basis {('s', 1)} to target basis {'measure', 'h', 'delay', 'snapshot', 'cx', 'barrier', 't', 'reset'} over library <qiskit.circuit.equivalence.EquivalenceLibrary object at 0x14aefb3a1160>."

Why doesn't transpile work, being S gate = TT? It should be able to decompose it, right?

John Brown
  • 61
  • 3

1 Answers1

2

The transpile doesn't work because the identity $S = TT$ is not there in the SessionEquivalenceLibrary. You can add an entry manually like this, and your circuit will be transpiled:

from qiskit.circuit.equivalence_library import SessionEquivalenceLibrary as sel
from qiskit.circuit.library import SGate
qc_eq = QuantumCircuit(1)
qc_eq.t(0)
qc_eq.t(0)
s = SGate()
sel.add_equivalence(s, qc_eq)

I assume the identity is not available by default, because it is not essential. Similarly, you won't be able to transpile an $X$ gate in terms of $H$ and $Z$, unless you add an identity $X = HZH$ explicitly to SessionEquivalenceLibrary.