import numpy as np
from qiskit import QuantumCircuit

# Building the circuit

# Create a Quantum Circuit acting on a quantum register of three qubits
circ = QuantumCircuit(3)

# Add a H gate on qubit 0, putting this qubit in superposition.
circ.h(0)
# Add a CX (CNOT) gate on control qubit 0 and target qubit 1, putting
# the qubits in a Bell state.
circ.cx(0, 1)
# Add a CX (CNOT) gate on control qubit 0 and target qubit 2, putting
# the qubits in a GHZ state.
circ.cx(0, 2)

# We can visualise the circuit using QuantumCircuit.draw()
circ.draw('mpl')


from qiskit.quantum_info import Statevector

# Set the initial state of the simulator to the ground state using from_int
state = Statevector.from_int(0, 2**3)

# Evolve the state by the quantum circuit
state = state.evolve(circ)

#draw using latex
state.draw('latex')

from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *

# Build
#------
 
# Create a Quantum Circuit acting on the q register
circuit = QuantumCircuit(2, 2)
 
# Add a H gate on qubit 0
circuit.h(0)
 
# Add a CX (CNOT) gate on control qubit 0 and target qubit 1
circuit.cx(0, 1)
 
# Map the quantum measurement to the classical bits
circuit.measure([0,1], [0,1])
 
# END

# Execute
#--------
 
# Use Aer's qasm_simulator
simulator = Aer.get_backend('qasm_simulator')
 
# Execute the circuit on the qasm simulator
job = execute(circuit, simulator, shots=1000)
 
# Grab results from the job
result = job.result()
 
# Return counts
counts = result.get_counts(circuit)
print("\nTotal count for 00 and 11 are:",counts)
 
# END

# Visualize
#----------
 
# Using QuantumCircuit.draw(), as in previous example
circuit.draw('mpl')
 

# Analyze
#--------
 
# Plot a histogram
plot_histogram(counts)

# END


<h3 style="color: rgb(0, 125, 65)"><i>References</i></h3>

https://qiskit.org/documentation/tutorials.html

https://www.youtube.com/watch?v=P5cGeDKOIP0

https://qiskit.org/documentation/tutorials/circuits/01_circuit_basics.html

https://docs.quantum-computing.ibm.com/lab/first-circuit
    