import numpy as np

from qiskit import QuantumCircuit, execute
from qiskit_quantinuum import Quantinuum
from qiskit.visualization import plot_histogram

# Quantinuum.save_account(user_name="first.last@company.com")
Quantinuum.save_account(user_name="megan.l.kohagen@quantinuum.com")
Quantinuum.load_account()

Quantinuum.backends()

device = 'H1-2E'
backend = Quantinuum.get_backend(device)
status = backend.status()

print(device, "status :", status.status_msg)

n_qubits = 2
circuit = QuantumCircuit(n_qubits, n_qubits, name='Bell Test')
circuit.h(0)
circuit.cx(0, 1)
circuit.measure_all()

circuit.draw()

shots = 100
job = execute(circuit, backend, shots=shots)

job.status()

result = job.result()

print("Job ID:", result.job_id)
print("Job success:", result.success)

counts = result.get_counts()
print("Total count for 00 and 11 are:",counts)

# Result should not be '0', it should be '00'!

plot_histogram(counts)

import json

with open(f'results_{result.job_id}.json', 'w') as f:
    json.dump(result.get_counts(), f)

device = 'H1-2E'
job_id = 'insert job id'
backend = Quantinuum.get_backend(device)
job = backend.retrieve_job(job_id)
result = job.result()
counts = result.get_counts()
print(counts)

device = 'H1'
shots = 100

backend = Quantinuum.get_backend(device)
job = execute(circuit, backend, shots=shots)

result = job.result()
counts = result.get_counts()
print(counts)