#Import the required packages
from qiskit import QuantumCircuit, Aer,execute
from qiskit.visualization import *

#Create a Quantum Circuit with 2 qubits and 2 classical bits
qc_bell=QuantumCircuit(2,2)
qc_bell.h(0)
qc_bell.cx(0,1)

#Measurement
qc_bell.measure([0,1],[0,1])
qc_bell.draw('mpl')

#Get the qasm simulator from Aer
backend=Aer.get_backend('qasm_simulator')

#Execute the circuit
#shots= number of times the experiment/circuit is run

job=execute(qc_bell,backend,shots=1024)

#Get the job result: result()

result=job.result()

#Get the histogram data of the experiement

counts=result.get_counts()

print(counts)

plot_histogram(counts,title="Bell State without noise")

qc1_bell=QuantumCircuit(2)
qc1_bell.h(0)
qc1_bell.cx(0,1)
qc1_bell.draw(output="mpl")


backend=Aer.get_backend('statevector_simulator')
job=execute(qc1_bell,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

qc2_bell=QuantumCircuit(2)
qc2_bell.x(0)
qc2_bell.h(0)
qc2_bell.cx(0,1)

qc2_bell.draw(output="mpl")


backend=Aer.get_backend('statevector_simulator')
job=execute(qc2_bell,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

plot_state_qsphere(sv,show_state_phases=True)

qc3_bell=QuantumCircuit(2)
qc3_bell.x(1)
qc3_bell.h(0)
qc3_bell.cx(0,1)
qc3_bell.draw(output="mpl")


backend=Aer.get_backend('statevector_simulator')
job=execute(qc3_bell,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

qc4_bell=QuantumCircuit(2)
qc4_bell.x(0)
qc4_bell.x(1)
qc4_bell.h(0)
qc4_bell.cx(0,1)

qc4_bell.draw(output="mpl")


backend=Aer.get_backend('statevector_simulator')
job=execute(qc4_bell,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

plot_state_qsphere(sv,show_state_phases=True)

bell_1=QuantumCircuit(2)
bell_1.h(0)
bell_1.x(1)
bell_1.cx(0,1)
bell_1.draw(output="mpl")

backend=Aer.get_backend('statevector_simulator')
job=execute(bell_1,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

bell_2=QuantumCircuit(2)
bell_2.cx(0,1)
bell_2.h(0)
bell_2.x(1)

bell_2.draw(output="mpl")

backend=Aer.get_backend('statevector_simulator')
job=execute(bell_2,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

bell_3=QuantumCircuit(2)
bell_3.h(0)
bell_3.x(1)
bell_3.cz(0,1)


bell_3.draw(output="mpl")

backend=Aer.get_backend('statevector_simulator')
job=execute(bell_2,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

bell_4=QuantumCircuit(2)
bell_4.h(0)
bell_4.h(1)
bell_4.draw(output="mpl")

backend=Aer.get_backend('statevector_simulator')
job=execute(bell_4,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

qc3=QuantumCircuit(3)
qc3.h(0)
qc3.cx(0,1)
qc3.cx(0,2)
qc3.draw(output="mpl")

backend=Aer.get_backend('statevector_simulator')
job=execute(qc3,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")