H2 Stack

Pytket is circuit builder API and optimizing compiler that serves System Model H2. Pytket supports limited conditional elements in the user circuit. More information is available at the Pytket documentation. Nexus is a cloud-native Platform-as-a-Service (PaaS) that provides access to System Model H2, in addition to H2 emulator instances in the cloud. A workflow schematic is provided below.

H2 Stack

Access pathway for System Model H2 Hardware instances and emulators distributions.

Job Workflow

Initialize a H2 project. A UUID can be used to suffix resources names for uniqueness.

import qnexus as qnx
import uuid

unique_suffix = uuid.uuid1()

project = qnx.projects.get_or_create("H2-Samples")
qnx.context.set_active_project(project)

Write Guppy source and build a compact representation (HUGR).

from pytket import Circuit
from pytket.circuit import Qubit, Bit


def build_repeat_until_success_circuit(max_attempts: int = 5) -> Circuit:
    """
    Pytket version of the Guppy repeat-until-success example.

    The dynamic loop is unrolled to `max_attempts`; each attempt uses fresh ancillas
    and records their measurement outcomes for classical post-processing.
    """
    circ = Circuit()

    # Target qubit that receives the effective Rz(acos(3/5)) gadget attempts.
    q = Qubit("q", 0)
    circ.add_qubit(q)

    # One output bit for the final q measurement.
    q_out = Bit("q", 0)
    circ.add_bit(q_out)

    for i in range(max_attempts):
        a = Qubit("a", i)
        b = Qubit("b", i)
        a_m = Bit("a_m", i)
        b_m = Bit("b_m", i)

        circ.add_qubit(a)
        circ.add_qubit(b)
        circ.add_bit(a_m)
        circ.add_bit(b_m)

        # h(a), h(b), toffoli(a, b, q), s(q), toffoli(a, b, q), h(a), h(b), measure
        circ.H(a)
        circ.H(b)
        circ.CCX(a, b, q)
        circ.S(q)
        circ.CCX(a, b, q)
        circ.H(a)
        circ.H(b)
        circ.Measure(a, a_m)
        circ.Measure(b, b_m)

    circ.Measure(q, q_out)
    return circ


circ = build_repeat_until_success_circuit(max_attempts=5)
circ

Upload HUGR to the Nexus Database. The user can access reference to the HUGR to request actions (costing, execution) on the underlying HUGR program.

ref_hugr = qnx.circuits.upload(
    circ, 
    name=f"repeat-until-success-{unique_suffix}"
)

The H2 syntax checkers can be queried for an estimate on the maximum cost specification.

prediction = qnx.circuits.cost(
    programs=[circ], 
    n_shots=[10]
)

A QuantinuumConfig instance with the device_name needs to be specified.

config = qnx.models.QuantinuumConfig(system_name="H2-Emulator")

A QuantinuumConfig instance is supplied to the start execution job function, alongside the HUGR reference, the number of shots and a job name.

import numpy as np

result_ref = qnx.start_execute_job(
    programs=[ref_hugr],
    n_shots=[10],
    backend_config=config,
    name=f"H2-Emulator-{unique_suffix}",
)

The job result can be queried once ready. The query can be blocked if the result is not ready with the {py:func}‘qnexus.jobs.wait_for’ function.

qnx.jobs.wait_for(result_ref)
job_result = qnx.jobs.results(result_ref)[0].download_result()