API documentation

The pytket-quantinuum extension allows submission of pytket circuits to Quantinuum systems (and emulators) via the QuantinuumBackend.

See the pytket-quantinuum section of the documentation website for some example usage.

enum pytket.extensions.quantinuum.backends.quantinuum.Language(value)[source]

Language used for submission of circuits.

Valid values are as follows:

QASM = <Language.QASM: 0>
QIR = <Language.QIR: 1>
PQIR = <Language.PQIR: 2>
class pytket.extensions.quantinuum.backends.quantinuum.QuantinuumBackend(device_name, label='job', simulator='state-vector', group=None, provider=None, machine_debug=False, api_handler=<pytket.extensions.quantinuum.backends.api_wrappers.QuantinuumAPI object>, compilation_config=None, data=None, **kwargs)[source]

Bases: Backend

Interface to a Quantinuum device. More information about the QuantinuumBackend can be found on this page https://docs.quantinuum.com/tket/extensions/pytket-quantinuum/index.html

static pass_from_info(backend_info, compilation_config=None, data=None, optimisation_level=2, timeout=300)[source]
Return type:

BasePass

__init__(device_name, label='job', simulator='state-vector', group=None, provider=None, machine_debug=False, api_handler=<pytket.extensions.quantinuum.backends.api_wrappers.QuantinuumAPI object>, compilation_config=None, data=None, **kwargs)[source]

Construct a new Quantinuum backend.

Parameters:
  • device_name (str) – Name of device, e.g. “H2-1”

  • label (str | None) – Job labels used if Circuits have no name, defaults to “job”

  • simulator (str) – Only applies to simulator devices, options are “state-vector” or “stabilizer”, defaults to “state-vector”

  • group (str | None) – string identifier of a collection of jobs, can be used for usage tracking.

  • provider (str | None) – select a provider for federated authentication. We currently only support ‘microsoft’, which enables the microsoft Device Flow.

  • api_handler (QuantinuumAPI) – Instance of API handler, defaults to DEFAULT_API_HANDLER

  • compilation_config (QuantinuumBackendCompilationConfig | None) – Optional compilation configuration

  • data (QuantinuumBackendData | None) – Data characterizing the backend. If this is not provided, the data are retrieved online using the device_name provided. If it is provided, then no online queries are made and no online submission is possible.

Supported kwargs:

classmethod available_devices(**kwargs)[source]

See pytket.backends.backend.Backend.available_devices().

Parameters:

api_handler – Instance of API handler, defaults to DEFAULT_API_HANDLER

Return type:

list[BackendInfo]

Returns:

A list of BackendInfo objects for each available Backend.

circuit_status(handle, **kwargs)[source]

Return a CircuitStatus reporting the status of the circuit execution corresponding to the ResultHandle

Return type:

CircuitStatus

default_compilation_pass(optimisation_level=2, timeout=300)[source]
Parameters:
  • optimisation_level (int) – Allows values of 0, 1, 2 or 3, with higher values prompting more computationally heavy optimising compilation that can lead to reduced gate count in circuits.

  • timeout (int) – Only valid for optimisation level 3, gives a maximimum time for running a single thread of the pass GreedyPauliSimp(). Increase for optimising larger circuits.

Return type:

BasePass

Returns:

Compilation pass for compiling circuits to Quantinuum devices

classmethod device_state(device_name, api_handler=<pytket.extensions.quantinuum.backends.api_wrappers.QuantinuumAPI object>)[source]

Check the status of a device.

>>> QuantinuumBackend.device_state('H2-1') # e.g. "online"
Parameters:
  • device_name (str) – Name of the device.

  • api_handler (QuantinuumAPI) – Instance of API handler, defaults to DEFAULT_API_HANDLER

Return type:

str

Returns:

String of state, e.g. “online”

get_compilation_config()[source]

Get the current compilation configuration.

Return type:

QuantinuumBackendCompilationConfig

get_compiled_circuit(circuit, optimisation_level=2, timeout=300)[source]

Return a single circuit compiled with default_compilation_pass().

Parameters:
  • optimisation_level (int) – Allows values of 0, 1, 2 or 3, with higher values prompting more computationally heavy optimising compilation that can lead to reduced gate count in circuits.

  • timeout (int) – Only valid for optimisation level 3, gives a maximimum time for running a single thread of the pass GreedyPauliSimp(). Increase for optimising larger circuits.

Return type:

Circuit

Returns:

An optimised quantum circuit

get_compiled_circuits(circuits, optimisation_level=2, timeout=300)[source]

Compile a sequence of circuits with default_compilation_pass() and return the list of compiled circuits (does not act in place).

As well as applying a degree of optimisation (controlled by the optimisation_level parameter), this method tries to ensure that the circuits can be run on the backend (i.e. successfully passed to process_circuits()), for example by rebasing to the supported gate set, or routing to match the connectivity of the device. However, this is not always possible, for example if the circuit contains classical operations that are not supported by the backend. You may use valid_circuit() to check whether the circuit meets the backend’s requirements after compilation. This validity check is included in process_circuits() by default, before any circuits are submitted to the backend.

If the validity check fails, you can obtain more information about the failure by iterating through the predicates in the required_predicates property of the backend, and running the verify() method on each in turn with your circuit.

Parameters:
  • circuits (Sequence[Circuit]) – The circuits to compile.

  • optimisation_level (int) – The level of optimisation to perform during compilation. See default_compilation_pass() for a description of the different levels (0, 1, 2 or 3). Defaults to 2.

  • timeout (int) – Only valid for optimisation level 3, gives a maximimum time for running a single thread of the pass GreedyPauliSimp(). Increase for optimising larger circuits.

Return type:

list[Circuit]

Returns:

Compiled circuits.

static get_jobid(handle)[source]

Return the corresponding Quantinuum Job ID from a ResultHandle.

Parameters:

handle (ResultHandle) – result handle.

Return type:

str

Returns:

Quantinuum API Job ID string.

static get_ppcirc_rep(handle)[source]

Return the JSON serialization of the classiocal postprocessing circuit attached to a handle, if any.

Parameters:

handle (ResultHandle) – result handle

Return type:

Any

Returns:

serialized post-processing circuit, if any

get_result(handle, **kwargs)[source]

See pytket.backends.backend.Backend.get_result(). Supported kwargs: timeout, wait, use_websocket.

Return type:

BackendResult

static get_results_selection(handle)[source]

Return a list of pairs (register name, register index) representing the order of the expected results in the response. If None, then all results in the response are used, in lexicographic order.

Return type:

Any

static get_results_width(handle)[source]

Return the truncation width of the results, if any.

Parameters:

handle (ResultHandle) – result handle

Return type:

int | None

Returns:

truncation width of results, if any

process_circuits(circuits, n_shots=None, valid_check=True, **kwargs)[source]

See pytket.backends.backend.Backend.process_circuits().

Supported kwargs: :rtype: list[ResultHandle]

  • postprocess: apply end-of-circuit simplifications and classical postprocessing to improve fidelity of results (bool, default False)

  • simplify_initial: apply the pytket SimplifyInitial() pass to improve fidelity of results assuming all qubits initialized to zero (bool, default False)

  • noisy_simulation: boolean flag to specify whether the simulator should perform noisy simulation with an error model (default value is True).

  • group: string identifier of a collection of jobs, can be used for usage tracking. Overrides the instance variable group.

  • wasm_file_handler: a WasmFileHandler object for linked WASM module.

  • pytketpass: a pytket.passes.BasePass intended to be applied

    by the backend (beta feature, may be ignored).

  • options: items to add to the “options” dictionary of the request body, as a json-style dictionary (in addition to any that were set in the backend constructor)

  • request_options: extra options to add to the request body as a json-style dictionary

  • language: languange for submission, of type Language, default QIR.

  • leakage_detection: if true, adds additional Qubit and Bit to Circuit to detect leakage errors. Run prune_shots_detected_as_leaky() on returned BackendResult to get counts with leakage errors removed.

  • n_leakage_detection_qubits: if set, sets an upper bound on the number of additional qubits to be used when adding leakage detection

  • seed: for local emulators only, PRNG seed for reproduciblity (int)

  • multithreading: for local emulators only, boolean to indicate whether to use multithreading for emulation (defaults to False)

  • max_cost: if set, the maximum amount in HQC to be spent on running the job. Ignored for local emulator.

rebase_pass()[source]

A single compilation pass that when run converts all gates in a Circuit to an OpType supported by the Backend (ignoring architecture constraints).

Return type:

BasePass

Returns:

Compilation pass that converts gates to primitives supported by Backend.

set_compilation_config_allow_implicit_swaps(allow_implicit_swaps)[source]

Set the option to allow or disallow implicit swaps during compilation.

Return type:

None

set_compilation_config_target_2qb_gate(target_2qb_gate)[source]

Set the target two-qubit gate for compilation.

Return type:

None

property backend_info: BackendInfo | None

Retrieve all Backend properties in a BackendInfo object, including device architecture, supported gate set, gate errors and other hardware-specific information.

Returns:

The BackendInfo describing this backend if it exists.

property compilation_config: QuantinuumBackendCompilationConfig

The current compilation configuration for the Backend.

Accessing this property will set the target_2qb_gate if it has not already been set.

property default_two_qubit_gate: OpType

Returns the default two-qubit gate for the device.

property is_local_emulator: bool

True if the backend is a local emulator, otherwise False

property required_predicates: list[Predicate]

The minimum set of predicates that a circuit must satisfy before it can be successfully run on this backend.

Returns:

Required predicates.

property two_qubit_gate_set: set[OpType]

Returns the set of supported two-qubit gates.

Submitted circuits must contain only one of these.

class pytket.extensions.quantinuum.backends.quantinuum.QuantinuumBackendCompilationConfig(allow_implicit_swaps=True, target_2qb_gate=None)[source]

Options to configure default compilation and rebase passes.

  • allow_implicit_swaps: Whether to allow use of implicit swaps when rebasing. The default is to allow implicit swaps.

  • target_2qb_gate: Choice of two-qubit gate. The default is to use the device’s default.

exception pytket.extensions.quantinuum.backends.quantinuum.BackendOfflineError[source]

Raised when backend constructed with the data parameter is asked to make an online API call.

exception pytket.extensions.quantinuum.backends.quantinuum.BatchingUnsupported[source]

Batching not supported for this backend.

exception pytket.extensions.quantinuum.backends.quantinuum.DeviceNotAvailable(device_name)[source]
exception pytket.extensions.quantinuum.backends.quantinuum.GetResultFailed[source]
exception pytket.extensions.quantinuum.backends.quantinuum.LanguageUnsupported[source]

Submission language not supported for this backend.

exception pytket.extensions.quantinuum.backends.quantinuum.MaxShotsExceeded[source]
exception pytket.extensions.quantinuum.backends.quantinuum.NoSyntaxChecker[source]
class pytket.extensions.quantinuum.backends.data.QuantinuumBackendData(n_qubits, n_cl_reg, gate_set=frozenset({OpType.Rz, OpType.Measure, OpType.Reset, OpType.PhasedX, OpType.ZZPhase}), local_emulator=False)[source]

Data characterizing a QuantinuumBackend.

  • n_qubits: maximum number of qubits available

  • n_cl_reg: maximum number of classical registers available

  • gate_set: set of available native gates

  • local_emulator: whether the backend is a local emulator

pytket.extensions.quantinuum.backends.data.H2 = QuantinuumBackendData(n_qubits=56, n_cl_reg=4000, gate_set=frozenset({OpType.Rz, OpType.PhasedX, OpType.ZZMax, OpType.ZZPhase, OpType.TK2}), local_emulator=False)

Data characterizing a QuantinuumBackend.

  • n_qubits: maximum number of qubits available

  • n_cl_reg: maximum number of classical registers available

  • gate_set: set of available native gates

  • local_emulator: whether the backend is a local emulator

class pytket.extensions.quantinuum.backends.api_wrappers.QuantinuumAPI(machine_list=None)[source]

Alias for QuantinuumAPIOffline.

get_machine_list()

Returns a given list of the available machines :rtype: list[dict[str, Any]] :return: list of machines

class pytket.extensions.quantinuum.backends.api_wrappers.QuantinuumAPIOffline(machine_list=None)[source]

Offline Quantinuum API emulator.

get_jobs()[source]

The function will return all the jobs that have been submitted

Return type:

list | None

Returns:

List of all the submitted jobs

get_machine_list()[source]

Returns a given list of the available machines :rtype: list[dict[str, Any]] :return: list of machines

class pytket.extensions.quantinuum.backends.config.QuantinuumConfig(username, refresh_token, id_token, refresh_token_timeout, id_token_timeout)[source]

Holds config parameters for pytket-quantinuum.

classmethod from_extension_dict(ext_dict)[source]

Abstract method to build PytketExtConfig from dictionary serialized form.

Return type:

QuantinuumConfig

pytket.extensions.quantinuum.backends.config.set_quantinuum_config(username)[source]

Set default value for Quantinuum username. Can be overriden in backend construction.

Return type:

None

exception pytket.extensions.quantinuum.backends.quantinuum.WasmUnsupported[source]
exception pytket.extensions.quantinuum.backends.api_wrappers.QuantinuumAPIError[source]