Tierkreis checkpoints; using pre build graphs¶
In this example we will run a predefined graph in a customized environment.
By default tierkreis will store the checkpoints of workflow runs in the filesystem at ~/.tierkreis/checkpoints.
This can be configured in the storage by providing the tierkreis_directory argument to the storage layer (e.g. checkpoints2).
from pathlib import Path
from tierkreis.runtime import new_default
runtime = await new_default()
This change needs to be forwarded to the executors, which is why they take the logs path as additional argument.
# The default subprocess executor discovers the installed Nexus worker.
Typically now one would define a graph. Although, tierkreis ships some preconstructed graphs. For this example we are going a to run a circuit on nexus and poll for its results.
from tierkreis.graphs.nexus.submit_poll import nexus_submit_and_poll
graph = nexus_submit_and_poll()
Before we run the graph we can visualize it to get familiar with it. This will start a webserver and listen on localhost
from qnexus.client.auth import login
from tierkreis_visualization.visualize_graph import visualize_graph
login()
visualize_graph(
graph,
) # this spawns a server, you need to manually terminate this cell.
and finally we can run it
from pytket.qasm.qasm import circuit_from_qasm
from qnexus import AerConfig
aer_config = AerConfig()
circuit = circuit_from_qasm(Path().parent / "data" / "ghz_state_n23.qasm")
circuits = [circuit]
inputs = {
"project_name": "2025-tkr-test",
"job_name": "job-1",
"circuits": [circuit.to_dict() for circuit in circuits],
"n_shots": [30] * len(circuits),
"backend_config": aer_config.model_dump(mode="json"),
}
with runtime:
workflow_id = await runtime.save_workflow("Nexus polling", graph)
run_id = await runtime.start_new_run(workflow_id, inputs)
await runtime.wait_for(run_id)
res = await runtime.get_outputs(run_id)