from sympy import Matrix
X = Matrix([[0,1],[1,0]]); X

Y = Matrix([[0,-1j],[1j,0]]); Y

Z = Matrix([[1,0],[0,-1]]); Z

X.eigenvals()

X.eigenvects()

Y.eigenvects()

Z.eigenvects()

from sympy import Matrix
X = Matrix([[0,1],[1,0]])
ket0 = Matrix([[1],[0]]); ket1 = Matrix([[0],[1]]); ket0, ket1

X*ket0, X*ket1

Y*ket0, Y*ket1, Z*ket0, Z*ket1

from sympy.physics.quantum import TensorProduct as tp
ket00 = tp(ket0,ket0); ket01 = tp(ket0,ket1); ket10 = tp(ket1,ket0); ket11 = tp(ket1,ket1); ket00, ket01, ket10, ket11

tp(eye(2),X), tp(eye(2),eye(2))*ket00, tp(eye(2),X)*ket00, tp(X,eye(2))*ket00, tp(X,X)*ket00

from qiskit import QuantumCircuit
import qiskit
from qiskit.quantum_info import Statevector
qc = QuantumCircuit(2) # prepara o estado |00>
qc.draw('mpl')
state = Statevector(qc)
state

qc = QuantumCircuit(2)
qc.x(1) # estado |01>
qc.draw('mpl')
state = Statevector(qc); state

from sympy.physics.quantum.dagger import Dagger
P0 = ket0*Dagger(ket0); P1 = ket1*Dagger(ket1); P0,P1

CNOTab = tp(P0,eye(2)) + tp(P1,X); CNOTba = tp(eye(2),P0) + tp(X,P1); CNOTab,CNOTba

H = Matrix([[1,1],[1,-1]])/sqrt(2); H

Phip = CNOTab*tp(H,eye(2))*ket00; Phim = CNOTab*tp(H,eye(2))*ket10; Phip,Phim

from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1)
qc.draw('mpl')

from qiskit.quantum_info import Statevector
state = Statevector(qc); state # |Phi+>

from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.x([0,1])
qc.h(0)
qc.cx(0,1)
qc.draw('mpl')

from qiskit.quantum_info import Statevector
state = Statevector(qc); state # |Psi->

from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h(0); qc.cx(0,1) # prepara |Phi+>
qc.barrier()
qc.cx(0,1)
qc.h(0)
qc.draw('mpl')

from qiskit.quantum_info import Statevector
state = Statevector(qc); state # estado |00>

from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.x([0,1]); qc.h(0); qc.cx(0,1) # prepara |Psi->
qc.barrier()
qc.cx(0,1)
qc.h(0)
qc.draw('mpl')

from qiskit.quantum_info import Statevector
state = Statevector(qc); state # estado |11>

from sympy import Matrix
X = Matrix([[0,1],[1,0]]); X

init_printing(use_unicode=True) # pra visualização ficar melhor
X.eigenvects()

from qiskit import QuantumCircuit
qc = QuantumCircuit(1,1)
qc.h(0)
from qiskit.quantum_info import Statevector
state = Statevector(qc)
state

qc.measure(0,0)
qc.draw('mpl')

from qiskit import Aer, execute
simulator = Aer.get_backend('qasm_simulator')
nshots = 2**13 # 8192 
job = execute(qc, backend=simulator, shots=nshots)
from qiskit.tools.visualization import plot_histogram
plot_histogram(job.result().get_counts())

from qiskit import QuantumCircuit
qc = QuantumCircuit(1,1)
qc.h(0)
qc.barrier()
qc.h(0)
qc.measure(0,0)
qc.draw('mpl')

from qiskit import Aer, execute
simulator = Aer.get_backend('qasm_simulator')
nshots = 2**13 # 8192 
job = execute(qc, backend=simulator, shots=nshots)
from qiskit.tools.visualization import plot_histogram
plot_histogram(job.result().get_counts())

from qiskit import QuantumCircuit
qc = QuantumCircuit(1,1)
qc.sdg(0)
qc.h(0)
qc.measure(0,0)
qc.draw('mpl')

from qiskit import execute, Aer
simulator = Aer.get_backend('qasm_simulator')
nshots = 2**13
job = execute(qc, backend=simulator, shots=nshots)
from qiskit.tools.visualization import plot_histogram
plot_histogram(job.result().get_counts())

from sympy import symbols
th, ph, lb = symbols('theta phi lambda'); th, ph, lb

sn = Matrix([[cos(th),exp(-1j*ph)*sin(th)],[exp(1j*ph)*sin(th),-cos(th)]]); sn

sn.eigenvects()

import math
math.cos(math.pi/8)**2

from qiskit import QuantumCircuit
qc = QuantumCircuit(1,1)
import math
th = -math.pi/4
ph = 0
lb = math.pi - ph
qc.u(th,ph,lb, 0) # porta parametrizada
qc.measure(0,0)
qc.draw('mpl')

from qiskit import Aer, execute
simulator = Aer.get_backend('qasm_simulator')
nshots = 2**13
job = execute(qc, backend = simulator, shots=nshots)
from qiskit.tools.visualization import plot_histogram
plot_histogram(job.result().get_counts())

# Cria o circuito quântico, sem usar medidas
from qiskit import QuantumCircuit
qc = QuantumCircuit(1)
qc.h(0)
qc.s(0)
qc.draw(output='mpl') # estado |o+>=(|0>+i|1>)/sqrt(2)

2**13

from qiskit import Aer, execute; simulator = Aer.get_backend('qasm_simulator'); nshots = 2**13
import qiskit; from qiskit.ignis.verification.tomography import state_tomography_circuits, StateTomographyFitter
qstc = state_tomography_circuits(qc, [0]); job = execute(qstc, backend=simulator, shots=nshots)
qstf = StateTomographyFitter(job.result(), qstc); rho = qstf.fit(method='lstsq')
qiskit.visualization.plot_state_city(rho)

rho

from sympy import Matrix, symbols, init_printing, eye
init_printing(use_unicode=True)
X = Matrix([[0,1],[1,0]]); Y = Matrix([[0,-1j],[1j,0]]); Z = Matrix([[1,0],[0,-1]])
x,y,z = symbols('x y z')
rho = (1/2)*(eye(2) + x*X + y*Y + z*Z); rho
rho.eigenvals()

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_bloch_multivector
qc = QuantumCircuit(4) # não faz nada no 1º qubit
qc.x(1)
qc.h(2)
qc.h(3); qc.s(3) 
state = Statevector(qc)
plot_bloch_multivector(state)

