{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Scheduler operations\n", "\n", "This example demonstrates how Lightworks can be used for interacting with the scheduling system." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import lightworks as lw\n", "from lightworks import remote\n", "\n", "try:\n", " remote.token.load(\"main_token\")\n", "except remote.TokenError:\n", " print(\n", " \"Token could not be automatically loaded, this will need to be \"\n", " \"manually configured.\"\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For testing, we'll create and submit a very small job to the system and save the id of this job." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "sampler = lw.Sampler(\n", " lw.Unitary(lw.random_unitary(4)), lw.State([1, 0, 0, 0]), n_samples=100\n", ")\n", "\n", "qpu = remote.QPU(\"Artemis\")\n", "test_job = qpu.run(sampler, job_name=\"Test job\")\n", "test_job_id = test_job.job_id" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Job management\n", "\n", "There is a set of functions provided for managing jobs once they are submitted for the system. The majority of these can be completed directly using the created Job object when submitted (as demonstrated later), but if for some reason this no longer exists then the job ID may also be used. This can be seen when creating a job or may be retrieved from the dashboard. \n", "\n", "First, we'll use ``list_scheduled_jobs`` and ``show_scheduled`` to view all job IDs waiting for execution and the status of these jobs respectively. If you submitted the test job above recently then this should appear here. It may not have a queue position, depending on whether or not it has been allocated one yet." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[17770]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "remote.list_scheduled_jobs()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Job ID | \n", "Status | \n", "Queue Position | \n", "
|---|---|---|---|
| 0 | \n", "17770 | \n", "Scheduled | \n", "2 | \n", "