import sys
sys.path.append('/Users/kirais/Documents/GitHub/Qiskit-for-GameDev/pygame/')

from qgame import CircuitGridModel, CircuitGridNode, MeasurementsHistogram
from qgame import circuit_node_types as node_types

from qiskit import QuantumCircuit

circuit_grid_model = CircuitGridModel(4, 18)
circuit_grid_model.set_node(0, 0, CircuitGridNode(node_types.ID))
circuit = circuit_grid_model.compute_circuit()

print(circuit_grid_model)

cx_gate = CircuitGridNode(node_types.CX, 1, ctrl_a=0)

circuit_grid_model.set_node(1,1,cx_gate)

print(circuit_grid_model)

qasm_str = circuit_grid_model.create_qasm_for_circuit()

qasm_str = 'OPENQASM 2.0;include "qelib1.inc";qreg q[4];creg c[4];id q;id q[0];rx(pi) q[1];'

circuit = QuantumCircuit.from_qasm_str(qasm_str)

circuit.draw()

from qiskit import BasicAer, QuantumRegister, ClassicalRegister, QuantumCircuit, execute

backend_sim = BasicAer.get_backend('qasm_simulator')
qr = QuantumRegister(circuit.width(), 'q')
cr = ClassicalRegister(circuit.width(), 'c')
meas_circ = QuantumCircuit(qr, cr)
meas_circ.barrier(qr)
meas_circ.measure(qr, cr)

circuit.draw()

circuit.n_qubits

meas_circ.draw()

complete_circuit = circuit + meas_circ

