from qiskit import IBMQ, QuantumRegister, ClassicalRegister, QuantumCircuit, Aer, execute

from qiskit.quantum_info import Statevector

from qiskit.visualization import plot_bloch_multivector, plot_histogram

import numpy as np
from numpy import pi
import math
from math import sqrt

import matplotlib as mpl
%matplotlib inline

qc = QuantumCircuit(1)

qc.draw(output="mpl")

# Bloch Sphere

simulator_statevector = Aer.get_backend('statevector_simulator')
job_statevector = execute(qc, simulator_statevector)
result_statevector = job_statevector.result()
outputstate = result_statevector.get_statevector(qc)
plot_bloch_multivector(outputstate)

qc.ry(3 * math.pi/4, 0)

qc.draw(output="mpl")

qc = QuantumCircuit(2)

qc.ry(3 * math.pi/4, 1)

qc.draw(output="mpl")

# Bloch Sphere

simulator_statevector = Aer.get_backend('statevector_simulator')
job_statevector = execute(qc, simulator_statevector)
result_statevector = job_statevector.result()
outputstate = result_statevector.get_statevector(qc)
plot_bloch_multivector(outputstate)

qc_rotate = QuantumCircuit(1, 1)
qc_rotate.ry(3 * math.pi/4, 0)

qc_rotate.measure([0], [0])

qc_rotate.draw(output="mpl")

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

# Plot a histogram
plot_histogram(counts)

qc_rotate = QuantumCircuit(1, 1)
qc_rotate.ry(math.pi/4, 0)

qc_rotate.measure([0], [0])

qc_rotate.draw(output="mpl")

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

# Plot a histogram
plot_histogram(counts)

qc_rotate = QuantumCircuit(1, 1)
qc_rotate.ry(math.pi/2, 0)

qc_rotate.measure([0], [0])

qc_rotate.draw(output="mpl")

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

# Plot a histogram
plot_histogram(counts)

qc_rotate = QuantumCircuit(1, 1)
qc_rotate.ry(3 * math.pi/4, 0)

qc_rotate.measure([0], [0])

qc_rotate.draw(output="mpl")

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

# Plot a histogram
plot_histogram(counts)

qc_rotate = QuantumCircuit(1, 1)
qc_rotate.ry(math.pi, 0)

qc_rotate.measure([0], [0])

qc_rotate.draw(output="mpl")

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

# Plot a histogram
plot_histogram(counts)

