from qiskit_cold_atom.spins import SpinSimulator
from qiskit import QuantumCircuit, QuantumRegister

backend = SpinSimulator()
qc = QuantumCircuit(4)
qc.measure_all()
# confirm that an empty circuit will return '0 0 0 0'
job = backend.run(qc, spin=3)

print(job.result().get_counts())

from qiskit_nature.second_q.operators import SpinOp
from qiskit_cold_atom.spins import SpinGate
import numpy as np

Hx = np.pi*SpinOp({"X_0": 1})  # generator of a rotation of angle pi around the x-axis

rx_spin = SpinGate(name="rx_spin", num_modes=1, generator=Hx)

qc = QuantumCircuit(QuantumRegister(1, "spin"))

qc.append(rx_spin, [0])
qc.measure_all()
qc.draw(output='mpl', style='clifford')

job = backend.run(qc, spin=10)
print(job.result().get_counts())

job = backend.run(qc, spin=6)
print(job.result().get_counts())

from qiskit_cold_atom.spins import RLXGate

qc = QuantumCircuit(QuantumRegister(1, "spin"))
qc.append(RLXGate(np.pi/2), [0])
qc.measure_all()
qc.draw(output='mpl', style="clifford")

# The same circuit can also be built by the following shorthand notation
# which is added to QuantumCircuit upon importing from qiskit_cold_atom.spins
qc = QuantumCircuit(QuantumRegister(1, "spin"))
qc.rlx(np.pi/2, 0)
qc.measure_all()
qc.draw(output='mpl', style="clifford")

from qiskit.visualization import plot_histogram

job = backend.run(qc, spin=10, shots=1000, seed=123)

counts = job.result().get_counts()
# convert counts to integers for better formatting
plot_histogram({int(k):v for k,v in counts.items()})

Hzz = SpinOp({"Z_0 Z_1": np.pi}, num_spins=2)  # generating Hamiltonian acting on two spins

zz_gate = SpinGate(name="zz_spin", num_modes=2, generator=Hzz)

qc = QuantumCircuit(QuantumRegister(2, "spin"))

qc.rlx(np.pi/2, [0, 1])
qc.append(zz_gate, [0, 1])
qc.rlx(np.pi/2, [0, 1])
qc.measure_all()

qc.draw(output='mpl', style="clifford")

job = backend.run(qc, spin=1, shots=1000, seed=1234)

print("counts: ", job.result().get_counts())

plot_histogram(job.result().get_counts())

# access the statevector 
print("\nstatevector :", job.result().get_statevector())

# accedd the unitary
print("\ncircuit unitary : \n", job.result().get_unitary())

import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright