from qiskit import *
from qiskit.visualization import plot_bloch_multivector, visualize_transition, plot_histogram

# Create a quantum circuit with 2 qubits
# The default initial state of qubits will be |0> or [1,0]
BS1 = QuantumCircuit(2)

#Applying the CNOT gate
BS1.h(0)
BS1.cx(0,1)

#Draw the circuit
# qc.draw()
BS1.draw('mpl')

#Get the backend for the circuit to display unitary matrix
backend = Aer.get_backend('unitary_simulator')

#execute the circuit using the backend
out = execute(BS1,backend).result().get_unitary()

#import qiskit_textbook and display the combined unitary matrix
from qiskit_textbook.tools import array_to_latex
array_to_latex(out, pretext = "\\text{UnitaryMatrix} = ")

#Get the backend for the circuit (simulator or realtime system)
backend = Aer.get_backend('statevector_simulator')

#execute the circuit using the backend
out = execute(BS1,backend).result().get_statevector()

#import qiskit_textbook and display the statevector
#from qiskit_textbook.tools import array_to_latex
array_to_latex(out, pretext = "\\text{Statevector} = ")

#execute the circuit and get the plain result
out = execute(BS1,backend).result()
#getting the count of the result
counts = out.get_counts()
#plotting the histogram
plot_histogram(counts)

# Create a quantum circuit with 2 qubits
# The default initial state of qubits will be |0> or [1,0]
BS2 = QuantumCircuit(2)

BS2.x(0)
BS2.h(0)
BS2.cx(0,1)

#Draw the circuit
# qc.draw()
BS2.draw('mpl')

#Get the backend for the circuit to display unitary matrix
backend = Aer.get_backend('unitary_simulator')

#execute the circuit using the backend
out = execute(BS2,backend).result().get_unitary()

#import qiskit_textbook and display the combined unitary matrix
from qiskit_textbook.tools import array_to_latex
array_to_latex(out, pretext = "\\text{UnitaryMatrix} = ")

#Get the backend for the circuit (simulator or realtime system)
backend = Aer.get_backend('statevector_simulator')

#execute the circuit using the backend
out = execute(BS2,backend).result().get_statevector()

#import qiskit_textbook and display the statevector
#from qiskit_textbook.tools import array_to_latex
array_to_latex(out, pretext = "\\text{Statevector} = ")

#execute the circuit and get the plain result
out = execute(BS2,backend).result()
#getting the count of the result
counts = out.get_counts()
#plotting the histogram
plot_histogram(counts)

BS3=QuantumCircuit(2)

BS3.h(0)

BS3.x(1)

BS3.cx(0,1)

BS3.draw('mpl')


#Get the backend for the circuit to display unitary matrix
backend = Aer.get_backend('unitary_simulator')

#execute the circuit using the backend
out = execute(BS3,backend).result().get_unitary()

#import qiskit_textbook and display the combined unitary matrix
from qiskit_textbook.tools import array_to_latex
array_to_latex(out, pretext = "\\text{UnitaryMatrix} = ")

#Get the backend for the circuit (simulator or realtime system)
backend = Aer.get_backend('statevector_simulator')

out = execute(BS3,backend).result().get_statevector()

array_to_latex(out, pretext = "\\text{Statevector} = ")

#execute the circuit and get the plain result
out = execute(BS3,backend).result()
#getting the count of the result
counts = out.get_counts()
#plotting the histogram
plot_histogram(counts)

BS4=QuantumCircuit(2)

BS4.h(0)
BS4.z(0)
BS4.x(1)
BS4.z(1)
BS4.cx(0,1)

BS4.draw('mpl')

#Get the backend for the circuit to display unitary matrix
backend = Aer.get_backend('unitary_simulator')

#execute the circuit using the backend
out = execute(BS4,backend).result().get_unitary()

#import qiskit_textbook and display the combined unitary matrix
from qiskit_textbook.tools import array_to_latex
array_to_latex(out, pretext = "\\text{UnitaryMatrix} = ")

#Get the backend for the circuit (simulator or realtime system)
backend = Aer.get_backend('statevector_simulator')

#execute the circuit using the backend
out = execute(BS4,backend).result().get_statevector()

#import qiskit_textbook and display the statevector
#from qiskit_textbook.tools import array_to_latex
array_to_latex(out, pretext = "\\text{Statevector} = ")

#execute the circuit and get the plain result
out = execute(BS4,backend).result()
#getting the count of the result
counts = out.get_counts()
#plotting the histogram
plot_histogram(counts)

from qiskit import QuantumCircuit, Aer, transpile, assemble, execute
from qiskit.visualization import plot_histogram

# Create a quantum circuit with two qubits
bell_circuit = QuantumCircuit(2, 2)

# Apply a Hadamard gate to the first qubit
bell_circuit.h(0)

# Apply a CNOT gate with the first qubit as the control and the second qubit as the target
bell_circuit.cx(0, 1)

# The resulting state is a Bell state
bell_circuit.measure([0, 1], [0, 1])

# Simulate the circuit using the Aer simulator
simulator = Aer.get_backend('qasm_simulator')

# Transpile the circuit for the simulator
transpiled_bell_circuit = transpile(bell_circuit, simulator)

# Run the simulation
result = execute(transpiled_bell_circuit, simulator).result()

# Display the measurement results
counts = result.get_counts(bell_circuit)
plot_histogram(counts)


