{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Saving and Loading Refs\n", "\n", "Refs to data can always be obtained with the right query, but for convenience Refs can be saved or loaded from the local filesystem.\n", "\n", "\n", "For instance, maybe we have a job that we expect will take time to run and we want to save a Ref to it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import qnexus as qnx\n", "\n", "from datetime import datetime\n", "from pathlib import Path\n", "\n", "from pytket import Circuit" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "job_name = f\"Job from {datetime.now()}\"\n", "\n", "my_project_ref = qnx.projects.get_or_create(name=\"My Project\")\n", "\n", "my_circuit_ref = qnx.circuits.upload(\n", " name=f\"My Circuit from {datetime.now()}\",\n", " circuit = Circuit(2).ZZPhase(0.5, 0, 1).measure_all(),\n", " project = my_project_ref,\n", ")\n", "\n", "my_execute_job_ref = qnx.start_execute_job(\n", " circuits=[my_circuit_ref],\n", " backend_config=qnx.QuantinuumConfig(device_name=\"H1-1LE\"),\n", " n_shots=[100],\n", " name=job_name,\n", " project=my_project_ref,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qnx.filesystem.save(\n", " ref=my_execute_job_ref,\n", " path=Path.cwd() / \"my_job_folder\" / job_name,\n", " mkdir=True,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can then load this Ref later to check on its status." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "my_job_ref = qnx.filesystem.load(\n", " path=Path.cwd() / \"my_job_folder\" / job_name\n", ")\n", "\n", "qnx.jobs.status(my_job_ref)" ] } ], "metadata": { "kernelspec": { "display_name": "qnexus-Rou6F43i-py3.11", "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.11.8" } }, "nbformat": 4, "nbformat_minor": 2 }