# Decomposing S gate in two T gate with qiskit

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?

• I tried different universal sets and I was never able to decompose $S=T^2$, but maybe there is one that allows it. May 19 at 8:20
• If one looks at the unitary, they are the same, so it should not depend on the other gates in the set, as long as T is in the set, right? May 19 at 14:48

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

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.