pytket_worker

Module Contents

Functions

add_measure_all

Appends final measurements to all qubits.

append_pauli_measurement_impl

Appends pauli measurements according to the pauli string to the circuit.

optimise_phase_gadgets

Applies an optimization pass to the circuit.

apply_pass

Applies an arbitrary optimization pass to the circuit

compile

Generic compilation function.

compile_circuit_quantinuum

Applies a predefined optimization pass for Quantinuum devices.

compile_circuits_quantinuum

Applies a predefined optimization pass for Quantinuum devices.

compile_tket_circuit_ibm

Applies pytkets default compilation pass for IBMQ devices.

compile_tket_circuits_ibm

Applies pytkets default compilation pass for IBMQ devices.

compile_tket_circuit_quantinuum

Applies pytkets default compilation pass for Quantinuum devices.

compile_tket_circuits_quantinuum

Applies pytkets default compilation pass for Quantinuum devices.

to_qasm_str

Transforms a pytket circuit into a QASM2 string.

from_gasm_str

Generates a pytket circuit from a QASM2 string.

to_qir_bytes

Generate qir bytecode from the pytket circuit.

from_qir_bytes

Converts qir bytecode into a pytket circuit.

expectation

Estimates the expectation value from a circuits shot counts.

n_qubits

Wrapper for pytket.Circuit.n_qubits.

main

Data

API

pytket_worker.worker = 'Worker(...)'
pytket_worker.add_measure_all(circuit: pytket._tket.circuit.Circuit) pytket._tket.circuit.Circuit

Appends final measurements to all qubits.

Parameters:

circuit (Circuit) – The original circuit.

Returns:

Circuit with measurement on all qubits.

Return type:

Circuit

pytket_worker.append_pauli_measurement_impl(circuit: pytket._tket.circuit.Circuit, pauli_string: pytket.pauli.QubitPauliString) pytket._tket.circuit.Circuit

Appends pauli measurements according to the pauli string to the circuit.

Parameters:
  • circuit (Circuit) – The original circuit.

  • pauli_string (QubitPauliString) – The Pauli String describing an observable.

Returns:

The updated circuits withe measurements attached.

Return type:

Circuit

pytket_worker.optimise_phase_gadgets(circuit: pytket._tket.circuit.Circuit) pytket._tket.circuit.Circuit

Applies an optimization pass to the circuit.

The optimization pass is based on identifying phase gadget structures in subcircuits of the circuit.

Parameters:

circuit (Circuit) – The original circuit.

Returns:

The optimized circuit.

Return type:

Circuit

pytket_worker.apply_pass(circuit: pytket._tket.circuit.Circuit, compiler_pass: pytket.passes.BasePass) pytket._tket.circuit.Circuit

Applies an arbitrary optimization pass to the circuit

Parameters:
  • circuit (Circuit) – The original circuit.

  • compiler_pass (BasePass) – The pass to apply to the circuit.

Returns:

The optimized circuit.

Return type:

Circuit

pytket_worker.compile(circuit: pytket._tket.circuit.Circuit | str | bytes, input_format: str = 'TKET', optimization_level: int = 2, gate_set: list[str] | None = None, coupling_map: list[tuple[int, int]] | None = None, output_format: str = 'TKET', optimization_pass: pytket.passes.BasePass | None = None) pytket._tket.circuit.Circuit | str | bytes

Generic compilation function.

When no optimization pass is provided a generic one will be applied. The passes are indicated for which optimizatino level they apply: - DecomposeBoxes, [0,1,2,3] - First round

  • AutoRebase, [0]

  • SynthesiseTket, AutoSquash, [1]

  • FullPeepholeOptimise, [2]

  • RemoveBarries, AutoRebase, GreedyPauliSimp, [3]

  • Mapping, [0,1,2,3] if not all-to-all
    • AutoRebase, FullMappingPass(Graph, LexiLabel, LexiRouting)

  • Second round
    • SynthesiseTket, [1,3]

    • KAKDecomposition, CliffordSimpm, SynthesiseTket, [2]

  • AutoRebase, AutoSquash, RemoveRedundancies, [0,1,2,3]

The input format is checked against the circuit; if they don’t match an error will be raised. The matching is as follows: - Circuit: TKET - str: QASM2 - bytes: QIR When no coupling map is provided an all-to-all connectivity is assumed, no mapping will take place. The qubit number is inferred from the number of qubits in the circuit. The coupling map is expected as a tuple of integers, from which the maximum number of qubits will be inferred. When no gate_set is provide a minimal gate set of {Rx, Rz, CX} is used. Gates in the gate set are matched to the pytket OpTypes.

Parameters:
  • circuit (Circuit | str | bytes) – The circuit to optimize.

  • input_format (str in ["TKET", "QASM2", "QIR"], optional) – The desired input format, defaults to “TKET”

  • optimization_level (int, optional) – Level of optimization to perform, defaults to 2

  • gate_set (list[str] | None, optional) – A set of OpTypes as strings for hardware restrictions, defaults to None

  • coupling_map (list[tuple[int, int]] | None, optional) – Connectivity constraint, fidelities are not regarded , defaults to None

  • output_format (str in ["TKET", "QASM2", "QIR"], optional) – The desired output formt, defaults to “TKET”

  • optimization_pass (BasePass | None, optional) – A custom optimization pass to be applied, defaults to None

Returns:

The circuit in the desired output format.

Return type:

Circuit | str | bytes

pytket_worker.compile_circuit_quantinuum(circuit: pytket._tket.circuit.Circuit) pytket._tket.circuit.Circuit

Applies a predefined optimization pass for Quantinuum devices.

The optimization pass corresponds to a level=3 optimization.

Parameters:

circuit (Circuit) – The original circuit.

Returns:

The optimized circuit.

Return type:

Circuit

pytket_worker.compile_circuits_quantinuum(circuits: list[pytket._tket.circuit.Circuit]) list[pytket._tket.circuit.Circuit]

Applies a predefined optimization pass for Quantinuum devices.

Parameters:

circuits (list[Circuit]) – A list of circuits to be optimized.

Returns:

The optimized circuits.

Return type:

list[Circuit]

pytket_worker.compile_tket_circuit_ibm(circuit: pytket._tket.circuit.Circuit, backend_name: str, optimization_level: int = 2) pytket._tket.circuit.Circuit

Applies pytkets default compilation pass for IBMQ devices.

The device is constructed by name, this function needs credentials.

Parameters:
  • circuit (Circuit) – The original circuit.

  • backend_name (str) – The name of the IBMQ backend.

  • optimization_level (int, optional) – Level of optimization in [0,1,2,3], defaults to 2

Returns:

The optimized circuit.

Return type:

Circuit

pytket_worker.compile_tket_circuits_ibm(circuits: list[pytket._tket.circuit.Circuit], backend_name: str, optimization_level: int = 2) list[pytket._tket.circuit.Circuit]

Applies pytkets default compilation pass for IBMQ devices.

The device is constructed by name, this function needs credentials.

Parameters:
  • circuits (list[Circuit]) – A list of circuits to be optimized.

  • backend_name (str) – The name of the IBMQ backend.

  • optimization_level (int, optional) – Level of optimization in [0,1,2,3], defaults to 2

Returns:

The optimized circuits.

Return type:

list[Circuit]

pytket_worker.compile_tket_circuit_quantinuum(circuit: pytket._tket.circuit.Circuit, backend_name: str, optimization_level: int = 2) pytket._tket.circuit.Circuit

Applies pytkets default compilation pass for Quantinuum devices.

The device is constructed by name, this function needs credentials.

Parameters:
  • circuit (Circuit) – The original circuit.

  • backend_name (str) – The name of the Quantinuum backend.

  • optimization_level (int, optional) – Level of optimization in [0,1,2,3], defaults to 2

Returns:

The optimized circuit.

Return type:

Circuit

pytket_worker.compile_tket_circuits_quantinuum(circuits: list[pytket._tket.circuit.Circuit], backend_name: str, optimization_level: int = 2) list[pytket._tket.circuit.Circuit]

Applies pytkets default compilation pass for Quantinuum devices.

The device is constructed by name, this function needs credentials.

Parameters:
  • circuits (list[Circuit]) – A list of circuits to be optimized.

  • backend_name (str) – The name of the Quantinuum backend.

  • optimization_level (int, optional) – Level of optimization in [0,1,2,3], defaults to 2

Returns:

The optimized circuits.

Return type:

list[Circuit]

pytket_worker.to_qasm_str(circuit: pytket._tket.circuit.Circuit) str

Transforms a pytket circuit into a QASM2 string.

Parameters:

circuit (Circuit) – The original circuit.

Returns:

The circuit in QASM2 representation.

Return type:

str

pytket_worker.from_gasm_str(qasm: str) pytket._tket.circuit.Circuit

Generates a pytket circuit from a QASM2 string.

Parameters:

qasm (str) – The circuit in QASM2 representation.

Returns:

The corresponding pytket circuit.

Return type:

Circuit

pytket_worker.to_qir_bytes(circuit: pytket._tket.circuit.Circuit) bytes

Generate qir bytecode from the pytket circuit.

Parameters:

circuit (Circuit) – The original circuit.

Returns:

The circuit as QIR bytecode.

Return type:

bytes

pytket_worker.from_qir_bytes(qir: bytes) pytket._tket.circuit.Circuit

Converts qir bytecode into a pytket circuit.

Parameters:

qir (bytes) – The QIR bytecode.

Returns:

The corresponding pytket circuit.

Return type:

Circuit

pytket_worker.expectation(backend_result: pytket.backends.backendresult.BackendResult) float

Estimates the expectation value from a circuits shot counts.

Parameters:

backend_result (BackendResult) – Results from a pytket backend.

Returns:

The estimated expectation value.

Return type:

float

pytket_worker.n_qubits(circuit: pytket._tket.circuit.Circuit) int

Wrapper for pytket.Circuit.n_qubits.

Parameters:

circuit (Circuit) – The pytket circuit.

Returns:

The number of qubits in that circuit.

Return type:

int

pytket_worker.main()