Skip to content

Instantly share code, notes, and snippets.

@ntakouris
Created September 12, 2019 11:00
Show Gist options
  • Select an option

  • Save ntakouris/76b3dd7d569cc2531fed2e14a0e89742 to your computer and use it in GitHub Desktop.

Select an option

Save ntakouris/76b3dd7d569cc2531fed2e14a0e89742 to your computer and use it in GitHub Desktop.
import cirq
from cirq.ops import CNOT, H, T, S, ZPowGate
# the actual matrix you could get: T_DAG = np.matrix.getH(cirq.unitary(cirq.ops.T))
# but cirq works with ops
# from the definition
# actual T is defined as exponent=0.25
T_DAG = ZPowGate(exponent=-0.25)
q0, q1, q2 = [cirq.GridQubit(0, x) for x in range(0, 3)]
circuit = cirq.Circuit()
circuit.append(H(q2))
circuit.append(CNOT(q1, q2))
circuit.append(T_DAG(q2))
circuit.append(CNOT(q0, q2))
circuit.append(T(q2))
circuit.append(CNOT(q1, q2))
circuit.append(T_DAG(q2))
circuit.append(CNOT(q0, q2))
circuit.append([T_DAG(q1), T(q2)])
circuit.append([CNOT(q0, q1), H(q2)])
circuit.append(T_DAG(q1))
circuit.append(CNOT(q0, q1))
circuit.append([T(q0), S(q1)])
print("Circuit:")
print(circuit)
#Circuit:
#(0, 0): ──────────────────@──────────────────@───@──────────@───T───
# │ │ │ │
#(0, 1): ───────@──────────┼───────@───T^-1───┼───X───T^-1───X───S───
# │ │ │ │
#(0, 2): ───H───X───T^-1───X───T───X───T^-1───X───T───H──────────────
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment