How can I transpile using universal $Clifford + T$ gates set? I have only seen examples using rotations + $CNOT$.
This is what I have tried
from qiskit import *
from qiskit.quantum_info import Operator
from qiskit.compiler import transpile
%matplotlib inline
u = Operator([[0, 0, 1, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 1, 0, 0, 0]])
qc = QuantumCircuit(3)
qc.unitary(u, [0,1,2], label='u')
result = transpile(qc, basis_gates=['u1', 'u2', 'u3', 'cx'], optimization_level=3)
result.draw(output='mpl')
And this example works fine. But when I was trying to set:
basis_gates=['h', 's', 't', 'cx']
It doesn't work. Could you help me, please?)
UPDATE: After comments I've tried this:
pip install git+https://github.com/LNoorl/qiskit-terra.git@feature/sk-pass
and then:
from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import TGate, HGate, TdgGate, SGate
from qiskit.transpiler.passes import SolovayKitaevDecomposition
from qiskit import *
from qiskit.quantum_info import Operator
from qiskit.compiler import transpile
%matplotlib inline
u = Operator([[1, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, -1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 1]])
qc = QuantumCircuit(3)
qc.unitary(u, [0,1,2], label='u')
print('Orginal circuit:')
print(qc)
basis_gates = [TGate(), SGate(), HGate()]
skd = SolovayKitaevDecomposition(recursion_degree=2, basis_gates=basis_gates, depth=5)
discretized = skd(qc)
print('Discretized circuit:')
print(discretized)
But it outputs only this:
Orginal circuit:
┌────┐
q_0: ┤0 ├
│ │
q_1: ┤1 u ├
│ │
q_2: ┤2 ├
└────┘
Discretized circuit:
┌────┐
q_0: ┤0 ├
│ │
q_1: ┤1 u ├
│ │
q_2: ┤2 ├
└────┘
Where is a problem?
transpile(circuit, basis_gates=['u', 'cx'])
and then you just need to find a Clifford+T approximation, which is discussed in the question @luciano referred to. Since Clifford includes S and H that gives you the H, S, T and CNOT basis. – Cryoris Apr 23 '21 at 12:43qc.decompose().draw()
would show you the inside of your black box – Lena Apr 23 '21 at 13:00┌───────────┐ q_0: ┤0 ├ │ │ q_1: ┤1 ISOMETRY ├ │ │ q_2: ┤2 ├ └───────────┘
– Игорь Токарев Apr 23 '21 at 13:04