{ "cells": [ { "cell_type": "markdown", "id": "227cc453", "metadata": {}, "source": [ "# Tierkreis checkpoints; using pre build graphs\n", "\n", "In this example we will run a predefined graph in a customized environment.\n", "\n", "By default tierkreis will store the checkpoints of workflow runs in the filesystem at `~/.tierkreis/checkpoints`.\n", "This can be configured in the storage by providing the `tierkreis_directory` argument to the storage layer (e.g. `checkpoints2`).\n" ] }, { "cell_type": "code", "execution_count": null, "id": "052a8990", "metadata": {}, "outputs": [], "source": [ "%pip install tierkreis qnexus" ] }, { "cell_type": "code", "execution_count": null, "id": "ff781681", "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "from uuid import UUID\n", "\n", "from tierkreis.storage import FileStorage\n", "\n", "storage = FileStorage(\n", " UUID(int=107),\n", " do_cleanup=True,\n", " tierkreis_directory=Path.home() / \".tierkreis\" / \"checkpoints2\",\n", ")" ] }, { "cell_type": "markdown", "id": "41cc0947", "metadata": {}, "source": [ "This change needs to be forwarded to the executors, which is why they take the logs path as additional argument.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "8992df08", "metadata": {}, "outputs": [], "source": [ "from tierkreis.consts import PACKAGE_PATH\n", "from tierkreis.executor import UvExecutor\n", "\n", "executor = UvExecutor(PACKAGE_PATH.parent / \"tierkreis_workers\", storage.logs_path)" ] }, { "cell_type": "markdown", "id": "4a4167ce", "metadata": {}, "source": [ "Typically now one would define a graph.\n", "Although, tierkreis ships some preconstructed graphs.\n", "For this example we are going a to run a circuit on nexus and poll for its results." ] }, { "cell_type": "code", "execution_count": null, "id": "cfeeea07", "metadata": {}, "outputs": [], "source": [ "from tierkreis.graphs.nexus.submit_poll import nexus_submit_and_poll\n", "\n", "graph = nexus_submit_and_poll()" ] }, { "cell_type": "markdown", "id": "ca071701", "metadata": {}, "source": [ "Before we run the graph we can visualize it to get familiar with it.\n", "This will start a webserver and listen on [localhost](http://localhost:8000)" ] }, { "cell_type": "code", "execution_count": null, "id": "59f2f3e5", "metadata": { "tags": [ "skip-execution" ] }, "outputs": [], "source": [ "from qnexus.client.auth import login\n", "from tierkreis_visualization.visualize_graph import visualize_graph\n", "\n", "login()\n", "visualize_graph(\n", " graph,\n", ") # this spawns a server, you need to manually terminate this cell." ] }, { "cell_type": "markdown", "id": "34bea400", "metadata": {}, "source": [ "and finally we can run it" ] }, { "cell_type": "code", "execution_count": null, "id": "a61d07ad", "metadata": { "tags": [ "skip-execution" ] }, "outputs": [], "source": [ "from pytket.qasm.qasm import circuit_from_qasm\n", "from qnexus import AerConfig\n", "\n", "from tierkreis.controller import run_graph\n", "from tierkreis.storage import read_outputs\n", "\n", "aer_config = AerConfig()\n", "circuit = circuit_from_qasm(Path().parent / \"data\" / \"ghz_state_n23.qasm\")\n", "circuits = [circuit]\n", "inputs = {\n", " \"project_name\": \"2025-tkr-test\",\n", " \"job_name\": \"job-1\",\n", " \"circuits\": circuits,\n", " \"n_shots\": [30] * len(circuits),\n", " \"backend_config\": aer_config,\n", "}\n", "storage.clean_graph_files()\n", "run_graph(\n", " storage,\n", " executor,\n", " graph,\n", " inputs,\n", " polling_interval_seconds=0.1,\n", ")\n", "res = read_outputs(graph, storage)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.11" } }, "nbformat": 4, "nbformat_minor": 5 }