pytket_worker¶
Module Contents¶
Functions¶
Retrieves a BackendInfo object for a given configuration. |
|
Returns the device name in the BackendInfo if it exists. |
|
Generic task compile a circuit for a backend info according to the backend config. |
|
Appends final measurements to all qubits. |
|
Appends pauli measurements according to the pauli string to the circuit. |
|
Applies an optimization pass to the circuit. |
|
Applies an arbitrary optimization pass to the circuit |
|
Generic compilation function. |
|
Transforms a pytket circuit into a QASM2 string. |
|
Generates a pytket circuit from a QASM2 string. |
|
Generate qir bytecode from the pytket circuit. |
|
Converts qir bytecode into a pytket circuit. |
|
Estimates the expectation value from a circuits shot counts. |
|
Wrapper for pytket.Circuit.n_qubits. |
|
Converst a pytket BackendResults to a mapping register_name -> list of bitstrings. |
|
Turns a dict representation of shots on a backend into a pytket.BackendResult. |
|
Data¶
API¶
- pytket_worker.worker = 'Worker(...)'¶
- pytket_worker.get_backend_info(config: qnexus.BackendConfig) pytket.backends.backendinfo.BackendInfo¶
Retrieves a BackendInfo object for a given configuration.
Depending on the backend, this requires authorization. The BackendInfo can be reused for different compilation tasks without refetching.
- Parameters:
config (BackendConfig) – The user provide configuration of the backend to use.
- Raises:
TierkreisError – If the pytket-quantinuum and pytket-qiskit extensions are not available.
TierkreisError – If no available backend matches the provided configuration.
NotImplementedError – If a backend is requested that’s neither IBMQ nor Quantinuum.
- Returns:
The BackendInfo if the device was available
- Return type:
BackendInfo
- pytket_worker.device_name_from_info(backend_info: pytket.backends.backendinfo.BackendInfo) str | None¶
Returns the device name in the BackendInfo if it exists.
- Parameters:
backend_info (BackendInfo) – The BackendInfo object.
- Returns:
The device name if it exists, otherwise None.
- Return type:
str | None
- pytket_worker.compile_using_info(circuit: pytket._tket.circuit.Circuit, backend_info: pytket.backends.backendinfo.BackendInfo, config: qnexus.BackendConfig, optimisation_level: int = 2, timeout: int = 300) pytket._tket.circuit.Circuit¶
Generic task compile a circuit for a backend info according to the backend config.
Compiles for a previously acquired backend information using the same config.
- Parameters:
circuit (Circuit) – The original circuit.
backend_info (BackendInfo) – The backend info to get the optimization pass from.
config (BackendConfig) – The backend configuration provided by the user.
optimisation_level (int) – The optimization level for the compilation, defaults to 2
timeout (int) – Timeout to wait for the pass to arrive, defaults to 300
- Raises:
TierkreisError – If the pytket-quantinuum and pytket-qiskit extensions are not available.
NotImplementedError – If a backend is requested that’s neither IBMQ nor Quantinuum.
- Returns:
The compiled circuit.
- Return type:
Circuit
- 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_generic_with_fixed_pass(circuit: pytket._tket.circuit.Circuit | str | bytes, input_format: str = 'TKET', optimisation_level: int = 2, gate_set: list[str] | None = None, coupling_map: list[tuple[int, int]] | None = None, output_format: str = 'TKET', optimisation_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 optimization 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”
optimisation_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”
optimisation_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.to_qasm2_str(circuit: pytket._tket.circuit.Circuit, header: str = 'qelib1') str¶
Transforms a pytket circuit into a QASM2 string.
- Parameters:
circuit (Circuit) – The original circuit.
header (str) – The QASM2 header lib to use.
- Returns:
The circuit in QASM2 representation.
- Return type:
str
- pytket_worker.from_qasm2_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.backend_result_to_dict(backend_result: pytket.backends.backendresult.BackendResult) dict[str, list[str]]¶
Converst a pytket BackendResults to a mapping register_name -> list of bitstrings.
- Parameters:
backend_result (BackendResult) – The backend results.
- Returns:
A dict of register names and shot bitstrings.
- Return type:
dict[str, list[str]]
- pytket_worker.backend_result_from_dict(data: dict[str, list[str]]) pytket.backends.backendresult.BackendResult¶
Turns a dict representation of shots on a backend into a pytket.BackendResult.
The expected format is a dict mapping register names to lists of bitstrings. For example:
- {
“c”: [“00”, “01”, “10”, “11”], “d”: [“0”, “1”, “0”, “1”]
}
- Parameters:
data (dict[str, list[str]]) – The dict representation of the shots.
- Returns:
The corresponding pytket.BackendResult.
- Return type:
BackendResult
- pytket_worker.main()¶