# Importing Qiskit
from qiskit import *

# Init 2 qubits and 2 classical bits

number_of_qubits = 2 # qubits
number_of_classical_bits = 2 # classical bits

Qr = QuantumRegister(number_of_qubits) # quantum register
Cr = ClassicalRegister(number_of_classical_bits) # classical register

# Building the circuit
circuit = QuantumCircuit(Qr, Cr)

# Adding gates to the circuit
circuit.h(Qr[0]) # Hadamard gate on Qubit 0
circuit.cx(Qr[0], Qr[1]) # CNOT gate on control Qubit 0 and target Qubit 1

# Measure the qubits [0, 1] and store the result in classical bits [0, 1]
circuit.measure(Qr, Cr)

# Draw the circuit
circuit.draw(output='mpl')

# the hello world of quantum computing
# 2 qubits, 2 classical bits
# Hadamard gate on Qubit 0
# CNOT gate on control Qubit 0 and target Qubit 1

# Measure the qubits [0, 1] and store the result in classical bits [0, 1]

# Hadamard gate means that the qubit is in superposition, so it has a 50% chance of being 0 or 1
# CNOT gate means that the qubit 1 is entangled with qubit 0, so if qubit 0 is 0, qubit 1 is 0, and if qubit 0 is 1, qubit 1 is 1

# Simulating the circuit in the local simulator
simulator = Aer.get_backend('qasm_simulator') # simulator

result = execute(circuit, backend=simulator).result() # execute the circuit on the simulator

# Plot the result
from qiskit.visualization import plot_histogram 

plot_histogram(result.get_counts(circuit)) # plot the result