from qiskit import *

%matplotlib inline
from qiskit.tools.visualization import plot_histogram
from qiskit.tools.monitor import job_monitor

# create qubit using quantum registers
qr = QuantumRegister(2)

# create classical register to take measurement of `qr`
cr = ClassicalRegister(2)

# build a circuit
qc = QuantumCircuit(qr, cr)
# visualize the circuit to know how it's looks like or there any modification init ?
qc.draw()

# to add gates into the circuit so that
# to build entanglement in circuit we uses hadamard gate : H
qc.h(0)

qc.draw(output='mpl')

# two qubit controlled operation gate : CNOT gate 
# cx(c_1, t) it controls the c_1 qubit and target the t qubit
qc.cx(0, 1)
#qc.cx(qr[0],qr[1])

qc.draw(output='mpl')


# to measure the qubits and store into classical bits
qc.measure(qr, cr)

qc.draw(output='mpl')

# How to run this quantum circuit on classical computer or quantum simulator
# used qiskit's Aer Simulator 
simulator = Aer.get_backend('qasm_simulator')

result = execute(qc, backend=simulator).result()

plot_histogram(result.get_counts(qc))

# How to run this qunatum circuit on the Quantum computer
# IBM's Quantum Computer
# We access it from cloud using an api call with our account on the ibm experieance
#loading our ibm account 
IBMQ.load_account('API_Key')

# 
provider = IBMQ.get_provider('ibm-q')

qcomp = provider.get_backend('ibmqx2')

job = execute(qc, backend=qcomp)

job_monitor(job)

result = job.result()

plot_histogram(result.get_counts(qc))

""" 
Question : Why there is a difference in output in executing quantum circuit on simulator and on actual quantum device ?




Question : What is the difference b/w the Quantum Simulator and a Quantum Computer ?


"""