import qiskit

qiskit.__version__

qiskit.__qiskit_version__

import qiskit.tools.jupyter
%qiskit_version_table

from qiskit import QuantumCircuit
qc = QuantumCircuit(2,2) # (qbit, classicalbit)
qc.measure_all()
qc.draw()

qc.draw('mpl')

qc.draw('latex')

qc = QuantumCircuit(3,2) # (qbit, classicalbit)
qc.measure([0,1], [0,1])
qc.draw('mpl')

from qiskit import QuantumRegister, ClassicalRegister
from qiskit import Aer, execute
q = QuantumRegister(2)
c = ClassicalRegister(2)
qc = QuantumCircuit(q, c)
qc.measure([0, 1], [0, 1])
qc.draw('mpl')

from qiskit.visualization import plot_histogram
sim = Aer.get_backend('statevector_simulator')
job = execute(qc, sim, shots=1024)
result = job.result()
counts = result.get_counts()
plot_histogram(counts)

from qiskit.visualization import plot_state_qsphere
from qiskit.quantum_info import Statevector
qc=QuantumCircuit(1)
qc.x(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

from qiskit.visualization import array_to_latex

sim = Aer.get_backend('unitary_simulator')
job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))
#array_to_latex(result.get_statevector(qc)) # for statevector_simulator

qc=QuantumCircuit(1)
qc.y(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.y(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.z(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.z(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

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

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.s(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.s(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.sdg(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.s(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.t(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.t(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.tdg(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.tdg(0)
qc.draw(output="mpl")

state = Statevector.from_instruction(qc)
state.draw('latex')

plot_state_qsphere(state)

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

from math import pi
qc=QuantumCircuit(1)
qc.p(pi,0)

qc.draw(output="mpl")

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.p(pi/2,0)

qc.draw(output="mpl")

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.p(pi/4,0)

qc.draw(output="mpl")

job = execute(qc, sim)
result = job.result()

array_to_latex(result.get_unitary(qc, decimals=3))