Saving and Loading Refs¶

Refs to data can always be obtained with the right query, but for convenience Refs can be saved or loaded from the local filesystem.

For instance, maybe we have a job that we expect will take time to run and we want to save a Ref to it.

import qnexus as qnx

from datetime import datetime
from pathlib import Path

from pytket import Circuit
job_name = f"Job from {datetime.now()}"

my_project_ref = qnx.projects.get_or_create(name="My Project")

my_circuit_ref = qnx.circuits.upload(
    name=f"My Circuit from {datetime.now()}",
    circuit = Circuit(2).ZZPhase(0.5, 0, 1).measure_all(),
    project = my_project_ref,
)

my_execute_job_ref = qnx.start_execute_job(
    circuits=[my_circuit_ref],
    backend_config=qnx.QuantinuumConfig(device_name="H1-1LE"),
    n_shots=[100],
    name=job_name,
    project=my_project_ref,
)
qnx.filesystem.save(
    ref=my_execute_job_ref,
    path=Path.cwd() / "my_job_folder" / job_name,
    mkdir=True,
)

We can then load this Ref later to check on its status.

my_job_ref = qnx.filesystem.load(
    path=Path.cwd() / "my_job_folder" / job_name
)

qnx.jobs.status(my_job_ref)