Quantinuum Emulator SubmissionΒΆ
Quantinuum provides the emulation targets to execute Guppy programs. These emulators are distributions of the Selene framework. The Helios emulators a are pre-configured to use the Helios runtime and error model. A threshold user-defined keyword argument, max_cost, prevents program execution from exceeding the specified Hardware Quantum Credits (HQC). If this threshold number is exceeded, the program fails and returns measurement results for successfully completed shots.
The main method synthesizes an 8-qubit log-depth GHZ circuit, and compiles the guppy source into a Heirarchical Unified Graph Representation (HUGR) binary. HUGR is a compact intermediate representation for Guppy programs.
from guppylang import guppy
from guppylang.std.quantum import cx, h, measure_array, qubit
from guppylang.std.builtins import array, result, comptime, barrier
n_qubits = 8
@guppy
def main() -> None:
"""
Create a GHZ circuit with log depth.
"""
qubit_array: array[qubit, comptime(n_qubits)] = array(qubit() for _ in range(comptime(n_qubits)))
h(qubit_array[0])
barrier(qubit_array)
qubits_used: int = 1
i: int = 0
while qubits_used < comptime(n_qubits):
i += 1
for k in range(qubits_used):
cx(qubit_array[k], qubit_array[qubits_used])
qubits_used += 1
barrier(qubit_array)
mresults = measure_array(qubit_array)
result("measurementResults", mresults[0])
hugr = main.compile()
The HUGR binary is uploaded to Nexus with a unique name (datetime) using the qnx.hugr module. The HUGR upload requires a user friendly name, which does not need to be unique across the Nexus project. A HUGR reference is returned after uploading to the Nexus database. This reference is required for execute jobs.
import qnexus as qnx
from importlib.metadata import version
import datetime
dt = datetime.datetime.now()
pkg_version = version('hugr') # replace 'numpy' with your package name
project = qnx.projects.get_or_create("release/helios", f"HUGR to support Quantinuum Helios Release.")
qnx.context.set_active_project(project)
hugr_ref = qnx.hugr.upload(
hugr_package=hugr,
name=f"1-layer brickwork circuit-{dt.strftime('%Y-%m-%d_%H-%M-%S')}",
description=f"Log-depth GHZ circuit using {n_qubits} qubits. HUGR version {pkg_version}.",
)
The max_cost keyword argument in the QuantinuumConfig constructor is used to stop HQC consumption if a threshold is exceeded during program execution. The device_name corresponds to the emulation target Various Helios backends can be specified via device_name. The simulation keyword argument can be set as state-vector or stabilizer.
config = qnx.models.QuantinuumConfig(device_name="Helios-1E", max_cost=500, simulator="stabilizer")
An execution job can be submitted using the start_execute_job function. This requires the reference to the uploaded HUGR, the QuantinuumConfig instance and a user-friendly job name which needs to be unique in the project space. A job reference is returned, which is needed to query the status of an execute job, in addition to retrieving results.
job_ref = qnx.start_execute_job(
programs=[hugr_ref],
n_shots=[100],
backend_config=config,
name=f"GHZ Circuit Execution: {dt.strftime('%Y-%m-%d_%H-%M-%S')}",
description="Log-depth GHZ circuit execution on Helios-1E."
)
The result retrieval can be blocked using qnexus.job.wait_for whilst the job is running. The block has a timeout of 900 seconds before returning an error. Once the job completes, a result reference is returned.
qnx.jobs.wait_for(job_ref)
result_ref = qnx.jobs.results(job_ref)[0]
A QsysResult instance can be downloaded using the result reference.
result = result_ref.download_result()
print(result)