from qiskit_cold_atom.providers import ColdAtomProvider

provider = ColdAtomProvider()
backend = provider.get_backend("fermionic_tweezer_simulator")

# give initial occupations separated by spin species
qc = backend.initialize_circuit([[1, 0, 0, 1], [0, 0, 1, 1]])

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

qc.measure_all()

print("measured counts: ", backend.run(qc, shots=10).result().get_counts())
print("measured counts: ", backend.run(qc, shots=10).result().get_memory())

from qiskit_cold_atom.fermions.fermion_gate_library import FermiHubbard

qc = backend.initialize_circuit([[1, 0, 0, 1], [0, 0, 1, 1]])

all_modes=range(8)

qc.append(FermiHubbard(num_modes=8, j=[0.5, 1., -1.], u=5., mu=[0., -1., 1., 0.]), qargs=all_modes)

# alternatively append the FH gate directly:
# qc.fhubbard(j=[0.5, 1., -1.], u=5., mu=[0., -1., 1., 0.], modes=all_modes)

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

from qiskit_cold_atom.fermions.fermion_gate_library import Hop, Interaction, Phase

qc = backend.initialize_circuit([[0, 1, 1, 0], [0, 1, 0, 1]])

hop_gate = Hop(num_modes=4, j=[0.5])
interaction_gate = Interaction(num_modes=8, u=2.)
phase_gate = Phase(num_modes=2, mu=[1.])

qc.append(hop_gate, qargs=[0, 1, 4, 5])
qc.append(interaction_gate, qargs=all_modes)
qc.append(phase_gate, qargs=[2, 6])

# equivalently, we can build the same circuit with a shortcut notation:
# qc.fhop([0.5], [0, 1, 4, 5])
# qc.fint(2., all_modes)
# qc.fphase([1.], [2, 6])

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

print("hopping generator: \n", hop_gate.generator)
print("\n interaction generator: \n",interaction_gate.generator)
print("\n phase generator: \n", phase_gate.generator)

qc.measure_all()

job = backend.run(qc, shots=100)

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

print("time taken: ", job.result().time_taken)

print(backend.get_basis(qc))

job_efficient = backend.run(qc, shots=100, num_species=2)

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

print("time taken: ",job_efficient.result().time_taken)

print("basis: ", backend.get_basis(qc, num_species=2))

from qiskit_cold_atom.fermions.fermion_gate_library import FRXGate, FRYGate, FRZGate
import numpy as np

qc = backend.initialize_circuit([[0, 1, 1, 0], [0, 1, 0, 1]])


# flip the spin of the atom at site 3
qc.append(FRXGate(np.pi), [2, 6])

# equivalently use shortcut
# qc.frx(np.pi, [2, 6])

qc.measure_all()

print("counts: ", backend.run(qc, num_species=2).result().get_counts())

print("basis dimension :", backend.get_basis(qc).dimension)

from pprint import pprint

tweezer_configuration = backend.configuration().to_dict()

pprint(tweezer_configuration)

import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright

