API documentation#
- class pytket.extensions.qiskit.IBMQBackend(backend_name: str, instance: str | None = None, monitor: bool = True, provider: IBMProvider | None = None, token: str | None = None)[source]#
- __init__(backend_name: str, instance: str | None = None, monitor: bool = True, provider: IBMProvider | None = None, token: str | None = None)[source]#
A backend for running circuits on remote IBMQ devices. The provider arguments of hub, group and project can be specified here as parameters or set in the config file using
pytket.extensions.qiskit.set_ibmq_config()
. This function can also be used to set the IBMQ API token.- Parameters:
backend_name (str) – Name of the IBMQ device, e.g. ibmq_16_melbourne.
instance (str, optional) – String containing information about the hub/group/project.
monitor (bool, optional) – Use the IBM job monitor. Defaults to True.
provider (Optional[IBMProvider]) – An IBMProvider
token (Optional[str]) – Authentication token to use the QiskitRuntimeService.
- Raises:
ValueError – If no IBMQ account is loaded and none exists on the disk.
- classmethod available_devices(**kwargs: Any) List[BackendInfo] [source]#
Retrieve all available devices as a list of BackendInfo objects, including device name, architecture, supported gate set, gate errors, and other hardware-specific information.
- Returns:
A list of BackendInfo objects describing available devices.
- Return type:
List[BackendInfo]
- cancel(handle: ResultHandle) None [source]#
Cancel a job.
- Parameters:
handle (ResultHandle) – handle to job
- Raises:
NotImplementedError – If backend does not support job cancellation
- circuit_status(handle: ResultHandle) CircuitStatus [source]#
Return a CircuitStatus reporting the status of the circuit execution corresponding to the ResultHandle
- default_compilation_pass(optimisation_level: int = 2, placement_options: Dict | None = None) BasePass [source]#
A suggested compilation pass that will will, if possible, produce an equivalent circuit suitable for running on this backend.
At a minimum it will ensure that compatible gates are used and that all two- qubit interactions are compatible with the backend’s qubit architecture. At higher optimisation levels, further optimisations may be applied.
This is a an abstract method which is implemented in the backend itself, and so is tailored to the backend’s requirements.
The default compilation passes for the
IBMQBackend
,IBMQEmulatorBackend
and the Aer simulators support an optionalplacement_options
dictionary containing arguments to override the default settings inNoiseAwarePlacement
.- Parameters:
optimisation_level (int, optional) –
The level of optimisation to perform during compilation.
Level 0 does the minimum required to solves the device constraints, without any optimisation.
Level 1 additionally performs some light optimisations.
Level 2 (the default) adds more computationally intensive optimisations that should give the best results from execution.
placement_options (Dict, optional) – Optional argument allowing the user to override the default settings in
NoiseAwarePlacement
.
- Returns:
Compilation pass guaranteeing required predicates.
- Return type:
- get_result(handle: ResultHandle, **kwargs: int | float | str | None) BackendResult [source]#
See
pytket.backends.Backend.get_result()
. Supported kwargs: timeout, wait.
- process_circuits(circuits: Sequence[Circuit], n_shots: None | int | Sequence[int | None] = None, valid_check: bool = True, **kwargs: int | float | str | None) List[ResultHandle] [source]#
See
pytket.backends.Backend.process_circuits()
.Supported kwargs: - 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)
- rebase_pass() BasePass [source]#
A single compilation pass that when run converts all gates in a Circuit to an OpType supported by the Backend (ignoring architecture constraints).
- Returns:
Compilation pass that converts gates to primitives supported by Backend.
- Return type:
- property backend_info: BackendInfo#
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.
- Return type:
Optional[BackendInfo]
- class pytket.extensions.qiskit.IBMQEmulatorBackend(backend_name: str, instance: str | None = None, provider: IBMProvider | None = None, token: str | None = None)[source]#
A backend which uses the AerBackend simulator to emulate the behaviour of IBMQBackend. Performs the same compilation and predicate checks as IBMQBackend. Requires a valid IBMQ account.
- __init__(backend_name: str, instance: str | None = None, provider: IBMProvider | None = None, token: str | None = None)[source]#
Construct an IBMQEmulatorBackend. Identical to
IBMQBackend
constructor, except there is no monitor parameter. SeeIBMQBackend
docs for more details.
- cancel(handle: ResultHandle) None [source]#
Cancel a job.
- Parameters:
handle (ResultHandle) – handle to job
- Raises:
NotImplementedError – If backend does not support job cancellation
- circuit_status(handle: ResultHandle) CircuitStatus [source]#
Return a CircuitStatus reporting the status of the circuit execution corresponding to the ResultHandle
- default_compilation_pass(optimisation_level: int = 2, placement_options: Dict | None = None) BasePass [source]#
See documentation for
IBMQBackend.default_compilation_pass()
.
- get_result(handle: ResultHandle, **kwargs: int | float | str | None) BackendResult [source]#
See
pytket.backends.Backend.get_result()
. Supported kwargs: timeout, wait.
- process_circuits(circuits: Sequence[Circuit], n_shots: None | int | Sequence[int | None] = None, valid_check: bool = True, **kwargs: int | float | str | None) List[ResultHandle] [source]#
See
pytket.backends.Backend.process_circuits()
. Supported kwargs: seed, postprocess.
- rebase_pass() BasePass [source]#
A single compilation pass that when run converts all gates in a Circuit to an OpType supported by the Backend (ignoring architecture constraints).
- Returns:
Compilation pass that converts gates to primitives supported by Backend.
- Return type:
- property backend_info: BackendInfo#
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.
- Return type:
Optional[BackendInfo]
- class pytket.extensions.qiskit.AerBackend(noise_model: NoiseModel | None = None, simulation_method: str = 'automatic', crosstalk_params: CrosstalkParams | None = None, n_qubits: int = 40)[source]#
- __init__(noise_model: NoiseModel | None = None, simulation_method: str = 'automatic', crosstalk_params: CrosstalkParams | None = None, n_qubits: int = 40)[source]#
Backend for running simulations on the Qiskit Aer QASM simulator.
- Parameters:
noise_model (Optional[NoiseModel], optional) – Noise model to apply during simulation. Defaults to None.
simulation_method (str) – Simulation method, see https://qiskit.org/documentation/stubs/qiskit.providers.aer.AerSimulator.html for available values. Defaults to “automatic”.
crosstalk_params – Apply crosstalk noise simulation to the circuits before execution. noise_model will be overwritten if this is given. Default to None.
n_qubits – The maximum number of qubits supported by the backend.
- Type:
Optional[CrosstalkParams]
- classmethod available_devices(**kwargs: Any) List[BackendInfo] #
Retrieve all available devices as a list of BackendInfo objects, including device name, architecture, supported gate set, gate errors, and other hardware-specific information.
- Returns:
A list of BackendInfo objects describing available devices.
- Return type:
List[BackendInfo]
- cancel(handle: ResultHandle) None #
Cancel a job.
- Parameters:
handle (ResultHandle) – handle to job
- Raises:
NotImplementedError – If backend does not support job cancellation
- circuit_status(handle: ResultHandle) CircuitStatus #
Return a CircuitStatus reporting the status of the circuit execution corresponding to the ResultHandle
- default_compilation_pass(optimisation_level: int = 2, placement_options: Dict | None = None) BasePass #
See documentation for
IBMQBackend.default_compilation_pass()
.
- get_compiled_circuit(circuit: Circuit, optimisation_level: int = 2) Circuit #
Return a single circuit compiled with
default_compilation_pass()
. SeeBackend.get_compiled_circuits()
.
- get_compiled_circuits(circuits: Sequence[Circuit], optimisation_level: int = 2) List[Circuit] #
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 usevalid_circuit()
to check whether the circuit meets the backend’s requirements after compilation. This validity check is included inprocess_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 – The circuits to compile.
optimisation_level (int, optional) – The level of optimisation to perform during compilation. See
default_compilation_pass()
for a description of the different levels (0, 1 or 2). Defaults to 2.
- Returns:
Compiled circuits.
- Return type:
List[Circuit]
- get_operator_expectation_value(state_circuit: Circuit, operator: QubitPauliOperator, valid_check: bool = True) complex #
Calculates the expectation value of the given circuit with respect to the operator using the built-in Aer snapshot functionality Requires a simple circuit with default register qubits.
- Parameters:
state_circuit (Circuit) – Circuit that generates the desired state \(\left|\psi\right>\).
operator (QubitPauliOperator) – Operator \(H\).
valid_check (bool, optional) – Explicitly check that the circuit satisfies all required predicates to run on the backend. Defaults to True
- Returns:
\(\left<\psi | H | \psi \right>\)
- Return type:
- get_pauli_expectation_value(state_circuit: Circuit, pauli: QubitPauliString, valid_check: bool = True) complex #
Calculates the expectation value of the given circuit using the built-in Aer snapshot functionality Requires a simple circuit with default register qubits.
- Parameters:
state_circuit (Circuit) – Circuit that generates the desired state \(\left|\psi\right>\).
pauli (QubitPauliString) – Pauli operator
valid_check (bool, optional) – Explicitly check that the circuit satisfies all required predicates to run on the backend. Defaults to True
- Returns:
\(\left<\psi | P | \psi \right>\)
- Return type:
- get_result(handle: ResultHandle, **kwargs: int | float | str | None) BackendResult #
Return a BackendResult corresponding to the handle.
Use keyword arguments to specify parameters to be used in retrieving results. See specific Backend derived class for available parameters, from the following list:
timeout: maximum time to wait for remote job to finish
wait: polling interval between remote calls to check job status
- Parameters:
handle (ResultHandle) – handle to results
- Returns:
Results corresponding to handle.
- Return type:
- get_results(handles: Iterable[ResultHandle], **kwargs: int | float | str | None) List[BackendResult] #
Return results corresponding to handles.
- Parameters:
handles – Iterable of handles
- Returns:
List of results
Keyword arguments are as for get_result, and apply to all jobs.
- pop_result(handle: ResultHandle) Dict[str, Any] | None #
Remove cache entry corresponding to handle from the cache and return.
- Parameters:
handle (ResultHandle) – ResultHandle object
- Returns:
Cache entry corresponding to handle, if it was present
- Return type:
Optional[ResultCache]
- process_circuit(circuit: Circuit, n_shots: int | None = None, valid_check: bool = True, **kwargs: int | float | str | None) ResultHandle #
Submit a single circuit to the backend for running. See
Backend.process_circuits()
.
- process_circuits(circuits: Sequence[Circuit], n_shots: None | int | Sequence[int | None] = None, valid_check: bool = True, **kwargs: int | float | str | None) List[ResultHandle] #
See
pytket.backends.Backend.process_circuits()
. Supported kwargs: seed, postprocess.
- rebase_pass() BasePass #
A single compilation pass that when run converts all gates in a Circuit to an OpType supported by the Backend (ignoring architecture constraints).
- Returns:
Compilation pass that converts gates to primitives supported by Backend.
- Return type:
- run_circuit(circuit: Circuit, n_shots: int | None = None, valid_check: bool = True, **kwargs: int | float | str | None) BackendResult #
Submits a circuit to the backend and returns results
- Parameters:
circuit – Circuit to be executed
n_shots – Passed on to
Backend.process_circuit()
valid_check – Passed on to
Backend.process_circuit()
- Returns:
Result
This is a convenience method equivalent to calling
Backend.process_circuit()
followed byBackend.get_result()
. Any additional keyword arguments are passed on toBackend.process_circuit()
andBackend.get_result()
.
- run_circuits(circuits: Sequence[Circuit], n_shots: int | Sequence[int] | None = None, valid_check: bool = True, **kwargs: int | float | str | None) List[BackendResult] #
Submits circuits to the backend and returns results
- Parameters:
circuits – Sequence of Circuits to be executed
n_shots – Passed on to
Backend.process_circuits()
valid_check – Passed on to
Backend.process_circuits()
- Returns:
List of results
This is a convenience method equivalent to calling
Backend.process_circuits()
followed byBackend.get_results()
. Any additional keyword arguments are passed on toBackend.process_circuits()
andBackend.get_results()
.
- valid_circuit(circuit: Circuit) bool #
Checks that the circuit satisfies all of required_predicates.
- property backend_info: BackendInfo#
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.
- Return type:
Optional[BackendInfo]
- property expectation_allows_nonhermitian: bool#
If expectations are supported, is the operator allowed to be non-Hermitan?
- property persistent_handles: bool#
Whether the backend produces ResultHandle objects that can be reused with other instances of the backend class.
- 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.
- Return type:
List[Predicate]
- property supports_contextual_optimisation: bool#
Does this backend support contextual optimisation?
See
process_circuits()
.
- property supports_counts: bool#
Does this backend support counts result retrieval via
backendresult.BackendResult.get_counts()
.
- property supports_density_matrix: bool#
Does this backend support density matrix retrieval via get_density_matrix.
- property supports_expectation: bool#
Does this backend support expectation value calculation for operators.
- property supports_shots: bool#
Does this backend support shot result retrieval via
backendresult.BackendResult.get_shots()
.
- class pytket.extensions.qiskit.AerStateBackend(n_qubits: int = 40)[source]#
- __init__(n_qubits: int = 40) None [source]#
Backend for running simulations on the Qiskit Aer Statevector simulator.
- Parameters:
n_qubits – The maximum number of qubits supported by the backend.
- classmethod available_devices(**kwargs: Any) List[BackendInfo] #
Retrieve all available devices as a list of BackendInfo objects, including device name, architecture, supported gate set, gate errors, and other hardware-specific information.
- Returns:
A list of BackendInfo objects describing available devices.
- Return type:
List[BackendInfo]
- cancel(handle: ResultHandle) None #
Cancel a job.
- Parameters:
handle (ResultHandle) – handle to job
- Raises:
NotImplementedError – If backend does not support job cancellation
- circuit_status(handle: ResultHandle) CircuitStatus #
Return a CircuitStatus reporting the status of the circuit execution corresponding to the ResultHandle
- default_compilation_pass(optimisation_level: int = 2, placement_options: Dict | None = None) BasePass #
See documentation for
IBMQBackend.default_compilation_pass()
.
- get_compiled_circuit(circuit: Circuit, optimisation_level: int = 2) Circuit #
Return a single circuit compiled with
default_compilation_pass()
. SeeBackend.get_compiled_circuits()
.
- get_compiled_circuits(circuits: Sequence[Circuit], optimisation_level: int = 2) List[Circuit] #
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 usevalid_circuit()
to check whether the circuit meets the backend’s requirements after compilation. This validity check is included inprocess_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 – The circuits to compile.
optimisation_level (int, optional) – The level of optimisation to perform during compilation. See
default_compilation_pass()
for a description of the different levels (0, 1 or 2). Defaults to 2.
- Returns:
Compiled circuits.
- Return type:
List[Circuit]
- get_operator_expectation_value(state_circuit: Circuit, operator: QubitPauliOperator, valid_check: bool = True) complex #
Calculates the expectation value of the given circuit with respect to the operator using the built-in Aer snapshot functionality Requires a simple circuit with default register qubits.
- Parameters:
state_circuit (Circuit) – Circuit that generates the desired state \(\left|\psi\right>\).
operator (QubitPauliOperator) – Operator \(H\).
valid_check (bool, optional) – Explicitly check that the circuit satisfies all required predicates to run on the backend. Defaults to True
- Returns:
\(\left<\psi | H | \psi \right>\)
- Return type:
- get_pauli_expectation_value(state_circuit: Circuit, pauli: QubitPauliString, valid_check: bool = True) complex #
Calculates the expectation value of the given circuit using the built-in Aer snapshot functionality Requires a simple circuit with default register qubits.
- Parameters:
state_circuit (Circuit) – Circuit that generates the desired state \(\left|\psi\right>\).
pauli (QubitPauliString) – Pauli operator
valid_check (bool, optional) – Explicitly check that the circuit satisfies all required predicates to run on the backend. Defaults to True
- Returns:
\(\left<\psi | P | \psi \right>\)
- Return type:
- get_result(handle: ResultHandle, **kwargs: int | float | str | None) BackendResult #
Return a BackendResult corresponding to the handle.
Use keyword arguments to specify parameters to be used in retrieving results. See specific Backend derived class for available parameters, from the following list:
timeout: maximum time to wait for remote job to finish
wait: polling interval between remote calls to check job status
- Parameters:
handle (ResultHandle) – handle to results
- Returns:
Results corresponding to handle.
- Return type:
- get_results(handles: Iterable[ResultHandle], **kwargs: int | float | str | None) List[BackendResult] #
Return results corresponding to handles.
- Parameters:
handles – Iterable of handles
- Returns:
List of results
Keyword arguments are as for get_result, and apply to all jobs.
- pop_result(handle: ResultHandle) Dict[str, Any] | None #
Remove cache entry corresponding to handle from the cache and return.
- Parameters:
handle (ResultHandle) – ResultHandle object
- Returns:
Cache entry corresponding to handle, if it was present
- Return type:
Optional[ResultCache]
- process_circuit(circuit: Circuit, n_shots: int | None = None, valid_check: bool = True, **kwargs: int | float | str | None) ResultHandle #
Submit a single circuit to the backend for running. See
Backend.process_circuits()
.
- process_circuits(circuits: Sequence[Circuit], n_shots: None | int | Sequence[int | None] = None, valid_check: bool = True, **kwargs: int | float | str | None) List[ResultHandle] #
See
pytket.backends.Backend.process_circuits()
. Supported kwargs: seed, postprocess.
- rebase_pass() BasePass #
A single compilation pass that when run converts all gates in a Circuit to an OpType supported by the Backend (ignoring architecture constraints).
- Returns:
Compilation pass that converts gates to primitives supported by Backend.
- Return type:
- run_circuit(circuit: Circuit, n_shots: int | None = None, valid_check: bool = True, **kwargs: int | float | str | None) BackendResult #
Submits a circuit to the backend and returns results
- Parameters:
circuit – Circuit to be executed
n_shots – Passed on to
Backend.process_circuit()
valid_check – Passed on to
Backend.process_circuit()
- Returns:
Result
This is a convenience method equivalent to calling
Backend.process_circuit()
followed byBackend.get_result()
. Any additional keyword arguments are passed on toBackend.process_circuit()
andBackend.get_result()
.
- run_circuits(circuits: Sequence[Circuit], n_shots: int | Sequence[int] | None = None, valid_check: bool = True, **kwargs: int | float | str | None) List[BackendResult] #
Submits circuits to the backend and returns results
- Parameters:
circuits – Sequence of Circuits to be executed
n_shots – Passed on to
Backend.process_circuits()
valid_check – Passed on to
Backend.process_circuits()
- Returns:
List of results
This is a convenience method equivalent to calling
Backend.process_circuits()
followed byBackend.get_results()
. Any additional keyword arguments are passed on toBackend.process_circuits()
andBackend.get_results()
.
- valid_circuit(circuit: Circuit) bool #
Checks that the circuit satisfies all of required_predicates.
- property backend_info: BackendInfo#
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.
- Return type:
Optional[BackendInfo]
- property expectation_allows_nonhermitian: bool#
If expectations are supported, is the operator allowed to be non-Hermitan?
- property persistent_handles: bool#
Whether the backend produces ResultHandle objects that can be reused with other instances of the backend class.
- 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.
- Return type:
List[Predicate]
- property supports_contextual_optimisation: bool#
Does this backend support contextual optimisation?
See
process_circuits()
.
- property supports_counts: bool#
Does this backend support counts result retrieval via
backendresult.BackendResult.get_counts()
.
- property supports_density_matrix: bool#
Does this backend support density matrix retrieval via get_density_matrix.
- property supports_expectation: bool#
Does this backend support expectation value calculation for operators.
- property supports_shots: bool#
Does this backend support shot result retrieval via
backendresult.BackendResult.get_shots()
.
- class pytket.extensions.qiskit.AerUnitaryBackend(n_qubits: int = 40)[source]#
- __init__(n_qubits: int = 40) None [source]#
Backend for running simulations on the Qiskit Aer Unitary simulator.
- Parameters:
n_qubits – The maximum number of qubits supported by the backend.
- classmethod available_devices(**kwargs: Any) List[BackendInfo] #
Retrieve all available devices as a list of BackendInfo objects, including device name, architecture, supported gate set, gate errors, and other hardware-specific information.
- Returns:
A list of BackendInfo objects describing available devices.
- Return type:
List[BackendInfo]
- cancel(handle: ResultHandle) None #
Cancel a job.
- Parameters:
handle (ResultHandle) – handle to job
- Raises:
NotImplementedError – If backend does not support job cancellation
- circuit_status(handle: ResultHandle) CircuitStatus #
Return a CircuitStatus reporting the status of the circuit execution corresponding to the ResultHandle
- default_compilation_pass(optimisation_level: int = 2, placement_options: Dict | None = None) BasePass #
See documentation for
IBMQBackend.default_compilation_pass()
.
- get_compiled_circuit(circuit: Circuit, optimisation_level: int = 2) Circuit #
Return a single circuit compiled with
default_compilation_pass()
. SeeBackend.get_compiled_circuits()
.
- get_compiled_circuits(circuits: Sequence[Circuit], optimisation_level: int = 2) List[Circuit] #
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 usevalid_circuit()
to check whether the circuit meets the backend’s requirements after compilation. This validity check is included inprocess_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 – The circuits to compile.
optimisation_level (int, optional) – The level of optimisation to perform during compilation. See
default_compilation_pass()
for a description of the different levels (0, 1 or 2). Defaults to 2.
- Returns:
Compiled circuits.
- Return type:
List[Circuit]
- get_operator_expectation_value(state_circuit: Circuit, operator: QubitPauliOperator, valid_check: bool = True) complex #
Calculates the expectation value of the given circuit with respect to the operator using the built-in Aer snapshot functionality Requires a simple circuit with default register qubits.
- Parameters:
state_circuit (Circuit) – Circuit that generates the desired state \(\left|\psi\right>\).
operator (QubitPauliOperator) – Operator \(H\).
valid_check (bool, optional) – Explicitly check that the circuit satisfies all required predicates to run on the backend. Defaults to True
- Returns:
\(\left<\psi | H | \psi \right>\)
- Return type:
- get_pauli_expectation_value(state_circuit: Circuit, pauli: QubitPauliString, valid_check: bool = True) complex #
Calculates the expectation value of the given circuit using the built-in Aer snapshot functionality Requires a simple circuit with default register qubits.
- Parameters:
state_circuit (Circuit) – Circuit that generates the desired state \(\left|\psi\right>\).
pauli (QubitPauliString) – Pauli operator
valid_check (bool, optional) – Explicitly check that the circuit satisfies all required predicates to run on the backend. Defaults to True
- Returns:
\(\left<\psi | P | \psi \right>\)
- Return type:
- get_result(handle: ResultHandle, **kwargs: int | float | str | None) BackendResult #
Return a BackendResult corresponding to the handle.
Use keyword arguments to specify parameters to be used in retrieving results. See specific Backend derived class for available parameters, from the following list:
timeout: maximum time to wait for remote job to finish
wait: polling interval between remote calls to check job status
- Parameters:
handle (ResultHandle) – handle to results
- Returns:
Results corresponding to handle.
- Return type:
- get_results(handles: Iterable[ResultHandle], **kwargs: int | float | str | None) List[BackendResult] #
Return results corresponding to handles.
- Parameters:
handles – Iterable of handles
- Returns:
List of results
Keyword arguments are as for get_result, and apply to all jobs.
- pop_result(handle: ResultHandle) Dict[str, Any] | None #
Remove cache entry corresponding to handle from the cache and return.
- Parameters:
handle (ResultHandle) – ResultHandle object
- Returns:
Cache entry corresponding to handle, if it was present
- Return type:
Optional[ResultCache]
- process_circuit(circuit: Circuit, n_shots: int | None = None, valid_check: bool = True, **kwargs: int | float | str | None) ResultHandle #
Submit a single circuit to the backend for running. See
Backend.process_circuits()
.
- process_circuits(circuits: Sequence[Circuit], n_shots: None | int | Sequence[int | None] = None, valid_check: bool = True, **kwargs: int | float | str | None) List[ResultHandle] #
See
pytket.backends.Backend.process_circuits()
. Supported kwargs: seed, postprocess.
- rebase_pass() BasePass #
A single compilation pass that when run converts all gates in a Circuit to an OpType supported by the Backend (ignoring architecture constraints).
- Returns:
Compilation pass that converts gates to primitives supported by Backend.
- Return type:
- run_circuit(circuit: Circuit, n_shots: int | None = None, valid_check: bool = True, **kwargs: int | float | str | None) BackendResult #
Submits a circuit to the backend and returns results
- Parameters:
circuit – Circuit to be executed
n_shots – Passed on to
Backend.process_circuit()
valid_check – Passed on to
Backend.process_circuit()
- Returns:
Result
This is a convenience method equivalent to calling
Backend.process_circuit()
followed byBackend.get_result()
. Any additional keyword arguments are passed on toBackend.process_circuit()
andBackend.get_result()
.
- run_circuits(circuits: Sequence[Circuit], n_shots: int | Sequence[int] | None = None, valid_check: bool = True, **kwargs: int | float | str | None) List[BackendResult] #
Submits circuits to the backend and returns results
- Parameters:
circuits – Sequence of Circuits to be executed
n_shots – Passed on to
Backend.process_circuits()
valid_check – Passed on to
Backend.process_circuits()
- Returns:
List of results
This is a convenience method equivalent to calling
Backend.process_circuits()
followed byBackend.get_results()
. Any additional keyword arguments are passed on toBackend.process_circuits()
andBackend.get_results()
.
- valid_circuit(circuit: Circuit) bool #
Checks that the circuit satisfies all of required_predicates.
- property backend_info: BackendInfo#
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.
- Return type:
Optional[BackendInfo]
- property expectation_allows_nonhermitian: bool#
If expectations are supported, is the operator allowed to be non-Hermitan?
- property persistent_handles: bool#
Whether the backend produces ResultHandle objects that can be reused with other instances of the backend class.
- 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.
- Return type:
List[Predicate]
- property supports_contextual_optimisation: bool#
Does this backend support contextual optimisation?
See
process_circuits()
.
- property supports_counts: bool#
Does this backend support counts result retrieval via
backendresult.BackendResult.get_counts()
.
- property supports_density_matrix: bool#
Does this backend support density matrix retrieval via get_density_matrix.
- property supports_expectation: bool#
Does this backend support expectation value calculation for operators.
- property supports_shots: bool#
Does this backend support shot result retrieval via
backendresult.BackendResult.get_shots()
.
Module for conversion between IBM Qiskit and tket primitives.
- pytket.extensions.qiskit.process_characterisation(backend: QiskitBackend) Dict[str, Any] [source]#
- Convert a
qiskit.providers.backend.Backendv1
to a dictionary containing device Characteristics
- Parameters:
backend (Backendv1) – A backend to be converted
- Returns:
A dictionary containing device characteristics
- Return type:
- Convert a
- pytket.extensions.qiskit.qiskit_to_tk(qcirc: QuantumCircuit, preserve_param_uuid: bool = False) Circuit [source]#
Converts a qiskit
qiskit.QuantumCircuit
to a pytketCircuit
.- Parameters:
qcirc (QuantumCircuit) – A circuit to be converted
preserve_param_uuid (bool) – Whether to preserve symbolic Parameter uuids by appending them to the tket Circuit symbol names as “_UUID:<uuid>”. This can be useful if you want to reassign Parameters after conversion to tket and back, as it is necessary for Parameter object equality to be preserved.
- Returns:
The converted circuit
- Return type:
- pytket.extensions.qiskit.tk_to_qiskit(tkcirc: Circuit, replace_implicit_swaps: bool = False) QuantumCircuit [source]#
Converts a pytket
Circuit
to a qiskitqiskit.QuantumCircuit
.In many cases there will be a qiskit gate to exactly replace each tket gate. If no exact replacement can be found for a part of the circuit then an equivalent circuit will be returned using the tket gates which are supported in qiskit.
- class pytket.extensions.qiskit.tket_backend.TketBackend(backend: Backend, comp_pass: BasePass | None = None)[source]#
Wraps a
Backend
as aqiskit.providers.BaseBackend
for use within the Qiskit software stack.Each
qiskit.circuit.quantumcircuit.QuantumCircuit
passed in will be converted to aCircuit
object. If aBasePass
is provided forcomp_pass
, this is applied to theCircuit
. Then it is processed by theBackend
, wrapping theResultHandle
s in aTketJob
, retrieving the results when called on the job object. The required predicates of theBackend
are presented to the Qiskit transpiler to enable it to perform the compilation in many cases. This may not always be possible due to unsupported gatesets or additional constraints that cannot be captured in Qiskit’s transpiler, in which case a customqiskit.transpiler.TranspilationPass
should be used to map into a tket- compatible gateset and setcomp_pass
to compile for the backend. To compile with tket only, setcomp_pass
and just use Qiskit to map into a tket-compatible gateset. In Qiskit Aqua, you should wrap theTketBackend
in aqiskit.aqua.QuantumInstance
, providing a customqiskit.transpiler.PassManager
with aqiskit.transpiler.passes.Unroller
. For examples, see the user manual or the Qiskit integration example.- __init__(backend: Backend, comp_pass: BasePass | None = None)[source]#
Create a new
TketBackend
from aBackend
.- Parameters:
backend (Backend) – The device or simulator to wrap up
comp_pass (Optional[BasePass], optional) – The (optional) tket compilation pass to apply to each circuit before submitting to the
Backend
, defaults to None
- run(run_input: QuantumCircuit | List[QuantumCircuit], **options: Any) TketJob [source]#
Run on the backend.
This method returns a
Job
object that runs circuits. Depending on the backend this may be either an async or sync call. It is at the discretion of the provider to decide whether running should block until the execution is finished or not: the Job class can handle either situation.- Args:
- run_input (QuantumCircuit or Schedule or list): An individual or a
list of
QuantumCircuit
orSchedule
objects to run on the backend. For legacy providers migrating to the new versioned providers, provider interface aQasmQobj
orPulseQobj
objects should probably be supported too (but deprecated) for backwards compatibility. Be sure to update the docstrings of subclasses implementing this method to document that. New provider implementations should not do this though asqiskit.qobj
will be deprecated and removed along with the legacy providers interface.- options: Any kwarg options to pass to the backend for running the
config. If a key is also present in the options attribute/object then the expectation is that the value specified will be used instead of what’s set in the options object.
- Returns:
Job: The job object for the run
- class pytket.extensions.qiskit.tket_pass.TketAutoPass(*args, **kwargs)[source]#
The tket compiler to be plugged in to the Qiskit compilation sequence
- __init__(backend: BackendV1, optimisation_level: int = 2, token: str | None = None)[source]#
Identifies a Qiskit backend and provides the corresponding default compilation pass from pytket as a
qiskit.transpiler.TransformationPass
.- Parameters:
backend – The Qiskit backend to target. Accepts Aer or IBMQ backends.
optimisation_level (int, optional) – The level of optimisation to perform during compilation. Level 0 just solves the device constraints without optimising. Level 1 additionally performs some light optimisations. Level 2 adds more computationally intensive optimisations. Defaults to 2.
token (Optional[str]) – Authentication token to use the QiskitRuntimeService.
- class pytket.extensions.qiskit.tket_pass.TketPass(*args, **kwargs)[source]#
The tket compiler to be plugged in to the Qiskit compilation sequence
- __init__(tket_pass: BasePass)[source]#
Wraps a pytket compiler pass as a
qiskit.transpiler.TransformationPass
. Aqiskit.dagcircuit.DAGCircuit
is converted to a pytketCircuit
. tket_pass will be run and the result is converted back.- Parameters:
tket_pass (BasePass) – The pytket compiler pass to run
- run(dag: DAGCircuit) DAGCircuit [source]#
Run a preconfigured optimisation pass on the circuit and route for the given backend.
- Parameters:
dag – The circuit to optimise and route
- Returns:
The modified circuit
- class pytket.extensions.qiskit.tket_job.JobInfo(circuit_name: str, qbits: List[pytket.unit_id.Qubit], cbits: List[pytket.unit_id.Bit], n_shots: int | None)[source]#
- class pytket.extensions.qiskit.tket_job.TketJob(backend: TketBackend, handles: List[ResultHandle], jobinfos: List[JobInfo], final_maps: List[None] | List[Dict[UnitID, UnitID]])[source]#
TketJob wraps a
ResultHandle
list as aqiskit.providers.JobV1