from qiskit import QuantumCircuit

from circuit_grid import CircuitGridModel, CircuitGridNode
import circuit_node_types as node_types
from sympy import pi
import logging

id_gate = CircuitGridNode(node_types.ID)
x_gate = CircuitGridNode(node_types.X, 1)
y_gate = CircuitGridNode(node_types.Y, 1)
z_gate = CircuitGridNode(node_types.Z, 1)
h_gate = CircuitGridNode(node_types.H, 1)
s_gate = CircuitGridNode(node_types.S, 1)
sdg_gate = CircuitGridNode(node_types.SDG, 1)
t_gate = CircuitGridNode(node_types.T, 1)
tdg_gate = CircuitGridNode(node_types.TDG, 1)

u1_gate = CircuitGridNode(node_types.U1, 1, theta=pi)
u2_gate = CircuitGridNode(node_types.U2, 1, theta=pi, phi=pi)
u3_gate = CircuitGridNode(node_types.U3, 1, theta=pi, phi=pi, lam=pi)

rx_gate = CircuitGridNode(node_types.RX, 1, theta=pi)
ry_gate = CircuitGridNode(node_types.RY, 1, theta=pi)
rz_gate = CircuitGridNode(node_types.RZ, 1, theta=pi)

cx_gate = CircuitGridNode(node_types.CX, 1, ctrl_a=0)
cy_gate = CircuitGridNode(node_types.CY, 2, ctrl_a=1)
cz_gate = CircuitGridNode(node_types.CZ, 3, ctrl_a=2)
ch_gate = CircuitGridNode(node_types.CH, 4, ctrl_a=3)
crz_gate = CircuitGridNode(node_types.CRZ, 1, theta=pi, ctrl_a=0)

cu1_gate = CircuitGridNode(node_types.CU1, 1, theta=pi, ctrl_a=0)
cu3_gate = CircuitGridNode(node_types.CU3, 1, theta=pi, phi=pi, lam=pi, ctrl_a=0)

ccx_gate = CircuitGridNode(node_types.CCX, 2, ctrl_a=0, ctrl_b=1)

swap_gate = CircuitGridNode(node_types.SWAP, 1, swap=2)
cswap_gate = CircuitGridNode(node_types.CSWAP, 1, ctrl_a=0, swap=2)

barrier = CircuitGridNode(node_types.BARRIER, 1)
measure_z = CircuitGridNode(node_types.MEASURE_Z, 1)
reset = CircuitGridNode(node_types.RESET, 1)
_if = CircuitGridNode(node_types.IF, 1)

gates = [
    id_gate,
    x_gate,
    y_gate,
    z_gate,
    h_gate,
    s_gate,
    sdg_gate,
    t_gate,
    tdg_gate,
    
    u1_gate,
    u2_gate,
    u3_gate,
    
    rx_gate,
    ry_gate,
    rz_gate,
    
    cx_gate,
    cy_gate,
    cz_gate,
    ch_gate,
    crz_gate,
    
    cu1_gate,
    cu3_gate,
    
    ccx_gate,
    
    swap_gate,
    cswap_gate,
    
    barrier,
    measure_z,
    reset,
    _if
]

for gate in gates:
    print(gate)

for gate in gates:
    print(gate.qasm())

circuit_grid = CircuitGridModel(4,7)
print(circuit_grid)

print(gates[0])

for j in range(circuit_grid.circuit_depth):
    for i in range(circuit_grid.qubit_count):
        circuit_grid.set_node(i,j,gates[j*circuit_grid.qubit_count + i])

print(circuit_grid)

qasm_str = circuit_grid.create_qasm_for_circuit()
print(qasm_str)

qc = QuantumCircuit.from_qasm_str(qasm_str)

qc.draw()

