import os
from qiskit import *
import qiskit.tools.visualization as qt
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi
import matplotlib.pyplot as plt
%matplotlib inline

qreg_q = QuantumRegister(2, 'q')
creg_c = ClassicalRegister(2, 'c')

circuits = []
for i in range(0, 4):
    circuits.append(QuantumCircuit(qreg_q, creg_c))

circuits[0].reset(qreg_q[0])
circuits[0].reset(qreg_q[1])
circuits[0].cx(qreg_q[0], qreg_q[1])
circuits[0].measure(qreg_q[0], creg_c[0])
circuits[0].measure(qreg_q[1], creg_c[1])

circuits[0].draw(output='mpl')

simulator = Aer.get_backend('qasm_simulator')
result00 = execute(circuits[0], backend = simulator, shots = 1).result()
counts00 = result00.get_counts()
print(counts00)

qt.plot_histogram(counts00, title="Histogram with the evaluating of |00> state under CNOT transformation")

circuits[1].reset(qreg_q[0])
circuits[1].x(qreg_q[1])
circuits[1].cx(qreg_q[0], qreg_q[1])
circuits[1].measure(qreg_q[0], creg_c[0])
circuits[1].measure(qreg_q[1], creg_c[1])

circuits[1].draw(output="mpl")

simulator = Aer.get_backend('qasm_simulator')
result01 = execute(circuits[1], backend = simulator, shots = 1).result()
counts01 = result01.get_counts()
print(counts01)

qt.plot_histogram(counts01, title="Histogram with the evaluating of |01> state under CNOT transformation")

circuits[2].x(qreg_q[0])
circuits[2].reset(qreg_q[1])
circuits[2].cx(qreg_q[0], qreg_q[1])
circuits[2].measure(qreg_q[0], creg_c[0])
circuits[2].measure(qreg_q[1], creg_c[1])

circuits[2].draw(output="mpl")

simulator = Aer.get_backend('qasm_simulator')
result10 = execute(circuits[2], backend = simulator, shots = 1).result()
counts10 = result10.get_counts()
print(counts10)

qt.plot_histogram(counts10, title="Histogram with the evaluating of |10> state under CNOT transformation")

circuits[3].x(qreg_q[0])
circuits[3].x(qreg_q[1])
circuits[3].cx(qreg_q[0], qreg_q[1])
circuits[3].measure(qreg_q[0], creg_c[0])
circuits[3].measure(qreg_q[1], creg_c[1])

circuits[3].draw(output="mpl")

simulator = Aer.get_backend('qasm_simulator')
result11 = execute(circuits[3], backend = simulator, shots = 1).result()
counts11 = result11.get_counts()
print(counts11)

qt.plot_histogram(counts11, title="Histogram with the evaluating of |11> state under CNOT transformation")