API documentation#

Module for conversion between Google Cirq and tket primitives.

pytket.extensions.cirq.cirq_to_tk(circuit: cirq.circuits.circuit.Circuit) pytket.circuit.Circuit#

Converts a Cirq Circuit to a tket Circuit object.

Parameters

circuit – The input Cirq Circuit

Raises

NotImplementedError – If the input contains a Cirq Circuit operation which is not yet supported by pytket

Returns

The tket Circuit corresponding to the input circuit

pytket.extensions.cirq.process_characterisation(device: cirq_google.devices.grid_device.GridDevice) dict#

Generates a tket dictionary containing device characteristics for a Cirq GridDevice.

Parameters

device – The device to convert

Returns

A dictionary containing device characteristics

pytket.extensions.cirq.tk_to_cirq(tkcirc: pytket.circuit.Circuit, copy_all_qubits: bool = False) cirq.circuits.circuit.Circuit#

Converts a tket Circuit object to a Cirq Circuit.

Parameters

tkcirc – The input tket Circuit

Returns

The Cirq Circuit corresponding to the input circuit

class pytket.extensions.cirq.CirqStateSampleBackend(seed: Optional[Any] = None)#

Backend for Cirq statevector simulator sampling.

classmethod available_devices(**kwargs: Any) List[pytket.backends.backendinfo.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: pytket.backends.resulthandle.ResultHandle) None#

Cancel a job.

Parameters

handle (ResultHandle) – handle to job

Raises

NotImplementedError – If backend does not support job cancellation

circuit_status(handle: pytket.backends.resulthandle.ResultHandle) pytket.backends.status.CircuitStatus#

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

default_compilation_pass(optimisation_level: int = 1) pytket.passes.BasePass#

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.

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.

Returns

Compilation pass guaranteeing required predicates.

Return type

BasePass

empty_cache() None#

Manually empty the result cache on the backend.

get_compiled_circuit(circuit: pytket.circuit.Circuit, optimisation_level: int = 2) pytket.circuit.Circuit#

Return a single circuit compiled with default_compilation_pass(). See Backend.get_compiled_circuits().

get_compiled_circuits(circuits: Sequence[pytket.circuit.Circuit], optimisation_level: int = 2) List[pytket.circuit.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 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 – 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_result(handle: pytket.backends.resulthandle.ResultHandle, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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

BackendResult

get_results(handles: Iterable[pytket.backends.resulthandle.ResultHandle], **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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: pytket.backends.resulthandle.ResultHandle) Optional[Dict[str, Any]]#

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: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.resulthandle.ResultHandle#

Submit a single circuit to the backend for running. See Backend.process_circuits().

process_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Union[None, int, Sequence[Optional[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.resulthandle.ResultHandle]#

Submit circuits to the backend for running. The results will be stored in the backend’s result cache to be retrieved by the corresponding get_<data> method.

If the postprocess keyword argument is set to True, and the backend supports the feature (see supports_contextual_optimisation()), then contextual optimisatioons are applied before running the circuit and retrieved results will have any necessary classical postprocessing applied. This is not enabled by default.

Use keyword arguments to specify parameters to be used in submitting circuits See specific Backend derived class for available parameters, from the following list:

  • seed: RNG seed for simulators

  • postprocess: if True, apply contextual optimisations

Note: If a backend is reused many times, the in-memory results cache grows indefinitely. Therefore, when processing many circuits on a statevector or unitary backend (whose results may occupy significant amounts of memory), it is advisable to run Backend.empty_cache() after each result is retrieved.

Parameters
  • circuits (Sequence[Circuit]) – Circuits to process on the backend.

  • n_shots (Optional[Union[int, Iterable[int]], optional) – Number of shots to run per circuit. Optionally, this can be a list of shots specifying the number of shots for each circuit separately. None is to be used for state/unitary simulators. Defaults to None.

  • valid_check (bool, optional) – Explicitly check that all circuits satisfy all required predicates to run on the backend. Defaults to True

Returns

Handles to results for each input circuit, as an interable in the same order as the circuits.

Return type

List[ResultHandle]

rebase_pass() pytket.passes.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

BasePass

run_circuit(circuit: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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 by Backend.get_result(). Any additional keyword arguments are passed on to Backend.process_circuit() and Backend.get_result().

run_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Optional[Union[int, Sequence[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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 by Backend.get_results(). Any additional keyword arguments are passed on to Backend.process_circuits() and Backend.get_results().

valid_circuit(circuit: pytket.circuit.Circuit) bool#

Checks that the circuit satisfies all of required_predicates.

Parameters

circuit (Circuit) – The circuit to check.

Returns

Whether or not all of required_predicates are satisfied.

Return type

bool

property backend_info: Optional[pytket.backends.backendinfo.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[pytket.predicates.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().

property supports_state: bool#

Does this backend support statevector retrieval via backendresult.BackendResult.get_state().

property supports_unitary: bool#

Does this backend support unitary retrieval via backendresult.BackendResult.get_unitary().

class pytket.extensions.cirq.CirqDensityMatrixSampleBackend(seed: Any = None, noise_model: Union[None, cirq.NoiseModel, cirq.Gate] = None)#

Backend for Cirq density matrix simulator sampling.

classmethod available_devices(**kwargs: Any) List[pytket.backends.backendinfo.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: pytket.backends.resulthandle.ResultHandle) None#

Cancel a job.

Parameters

handle (ResultHandle) – handle to job

Raises

NotImplementedError – If backend does not support job cancellation

circuit_status(handle: pytket.backends.resulthandle.ResultHandle) pytket.backends.status.CircuitStatus#

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

default_compilation_pass(optimisation_level: int = 1) pytket.passes.BasePass#

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.

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.

Returns

Compilation pass guaranteeing required predicates.

Return type

BasePass

empty_cache() None#

Manually empty the result cache on the backend.

get_compiled_circuit(circuit: pytket.circuit.Circuit, optimisation_level: int = 2) pytket.circuit.Circuit#

Return a single circuit compiled with default_compilation_pass(). See Backend.get_compiled_circuits().

get_compiled_circuits(circuits: Sequence[pytket.circuit.Circuit], optimisation_level: int = 2) List[pytket.circuit.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 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 – 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_result(handle: pytket.backends.resulthandle.ResultHandle, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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

BackendResult

get_results(handles: Iterable[pytket.backends.resulthandle.ResultHandle], **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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: pytket.backends.resulthandle.ResultHandle) Optional[Dict[str, Any]]#

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: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.resulthandle.ResultHandle#

Submit a single circuit to the backend for running. See Backend.process_circuits().

process_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Union[None, int, Sequence[Optional[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.resulthandle.ResultHandle]#

Submit circuits to the backend for running. The results will be stored in the backend’s result cache to be retrieved by the corresponding get_<data> method.

If the postprocess keyword argument is set to True, and the backend supports the feature (see supports_contextual_optimisation()), then contextual optimisatioons are applied before running the circuit and retrieved results will have any necessary classical postprocessing applied. This is not enabled by default.

Use keyword arguments to specify parameters to be used in submitting circuits See specific Backend derived class for available parameters, from the following list:

  • seed: RNG seed for simulators

  • postprocess: if True, apply contextual optimisations

Note: If a backend is reused many times, the in-memory results cache grows indefinitely. Therefore, when processing many circuits on a statevector or unitary backend (whose results may occupy significant amounts of memory), it is advisable to run Backend.empty_cache() after each result is retrieved.

Parameters
  • circuits (Sequence[Circuit]) – Circuits to process on the backend.

  • n_shots (Optional[Union[int, Iterable[int]], optional) – Number of shots to run per circuit. Optionally, this can be a list of shots specifying the number of shots for each circuit separately. None is to be used for state/unitary simulators. Defaults to None.

  • valid_check (bool, optional) – Explicitly check that all circuits satisfy all required predicates to run on the backend. Defaults to True

Returns

Handles to results for each input circuit, as an interable in the same order as the circuits.

Return type

List[ResultHandle]

rebase_pass() pytket.passes.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

BasePass

run_circuit(circuit: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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 by Backend.get_result(). Any additional keyword arguments are passed on to Backend.process_circuit() and Backend.get_result().

run_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Optional[Union[int, Sequence[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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 by Backend.get_results(). Any additional keyword arguments are passed on to Backend.process_circuits() and Backend.get_results().

valid_circuit(circuit: pytket.circuit.Circuit) bool#

Checks that the circuit satisfies all of required_predicates.

Parameters

circuit (Circuit) – The circuit to check.

Returns

Whether or not all of required_predicates are satisfied.

Return type

bool

property backend_info: Optional[pytket.backends.backendinfo.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[pytket.predicates.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().

property supports_state: bool#

Does this backend support statevector retrieval via backendresult.BackendResult.get_state().

property supports_unitary: bool#

Does this backend support unitary retrieval via backendresult.BackendResult.get_unitary().

class pytket.extensions.cirq.CirqCliffordSampleBackend(seed: Optional[Any] = None)#

Backend for Cirq Clifford simulator sampling.

classmethod available_devices(**kwargs: Any) List[pytket.backends.backendinfo.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: pytket.backends.resulthandle.ResultHandle) None#

Cancel a job.

Parameters

handle (ResultHandle) – handle to job

Raises

NotImplementedError – If backend does not support job cancellation

circuit_status(handle: pytket.backends.resulthandle.ResultHandle) pytket.backends.status.CircuitStatus#

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

default_compilation_pass(optimisation_level: int = 1) pytket.passes.BasePass#

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.

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.

Returns

Compilation pass guaranteeing required predicates.

Return type

BasePass

empty_cache() None#

Manually empty the result cache on the backend.

get_compiled_circuit(circuit: pytket.circuit.Circuit, optimisation_level: int = 2) pytket.circuit.Circuit#

Return a single circuit compiled with default_compilation_pass(). See Backend.get_compiled_circuits().

get_compiled_circuits(circuits: Sequence[pytket.circuit.Circuit], optimisation_level: int = 2) List[pytket.circuit.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 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 – 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_result(handle: pytket.backends.resulthandle.ResultHandle, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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

BackendResult

get_results(handles: Iterable[pytket.backends.resulthandle.ResultHandle], **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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: pytket.backends.resulthandle.ResultHandle) Optional[Dict[str, Any]]#

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: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.resulthandle.ResultHandle#

Submit a single circuit to the backend for running. See Backend.process_circuits().

process_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Union[None, int, Sequence[Optional[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.resulthandle.ResultHandle]#

Submit circuits to the backend for running. The results will be stored in the backend’s result cache to be retrieved by the corresponding get_<data> method.

If the postprocess keyword argument is set to True, and the backend supports the feature (see supports_contextual_optimisation()), then contextual optimisatioons are applied before running the circuit and retrieved results will have any necessary classical postprocessing applied. This is not enabled by default.

Use keyword arguments to specify parameters to be used in submitting circuits See specific Backend derived class for available parameters, from the following list:

  • seed: RNG seed for simulators

  • postprocess: if True, apply contextual optimisations

Note: If a backend is reused many times, the in-memory results cache grows indefinitely. Therefore, when processing many circuits on a statevector or unitary backend (whose results may occupy significant amounts of memory), it is advisable to run Backend.empty_cache() after each result is retrieved.

Parameters
  • circuits (Sequence[Circuit]) – Circuits to process on the backend.

  • n_shots (Optional[Union[int, Iterable[int]], optional) – Number of shots to run per circuit. Optionally, this can be a list of shots specifying the number of shots for each circuit separately. None is to be used for state/unitary simulators. Defaults to None.

  • valid_check (bool, optional) – Explicitly check that all circuits satisfy all required predicates to run on the backend. Defaults to True

Returns

Handles to results for each input circuit, as an interable in the same order as the circuits.

Return type

List[ResultHandle]

rebase_pass() pytket.passes.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

BasePass

run_circuit(circuit: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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 by Backend.get_result(). Any additional keyword arguments are passed on to Backend.process_circuit() and Backend.get_result().

run_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Optional[Union[int, Sequence[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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 by Backend.get_results(). Any additional keyword arguments are passed on to Backend.process_circuits() and Backend.get_results().

valid_circuit(circuit: pytket.circuit.Circuit) bool#

Checks that the circuit satisfies all of required_predicates.

Parameters

circuit (Circuit) – The circuit to check.

Returns

Whether or not all of required_predicates are satisfied.

Return type

bool

property backend_info: Optional[pytket.backends.backendinfo.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[pytket.predicates.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().

property supports_state: bool#

Does this backend support statevector retrieval via backendresult.BackendResult.get_state().

property supports_unitary: bool#

Does this backend support unitary retrieval via backendresult.BackendResult.get_unitary().

class pytket.extensions.cirq.CirqStateSimBackend(seed: Optional[Any] = None)#

Backend for Cirq statevector simulator state return.

classmethod available_devices(**kwargs: Any) List[pytket.backends.backendinfo.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: pytket.backends.resulthandle.ResultHandle) None#

Cancel a job.

Parameters

handle (ResultHandle) – handle to job

Raises

NotImplementedError – If backend does not support job cancellation

circuit_status(handle: pytket.backends.resulthandle.ResultHandle) pytket.backends.status.CircuitStatus#

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

default_compilation_pass(optimisation_level: int = 1) pytket.passes.BasePass#

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.

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.

Returns

Compilation pass guaranteeing required predicates.

Return type

BasePass

empty_cache() None#

Manually empty the result cache on the backend.

get_compiled_circuit(circuit: pytket.circuit.Circuit, optimisation_level: int = 2) pytket.circuit.Circuit#

Return a single circuit compiled with default_compilation_pass(). See Backend.get_compiled_circuits().

get_compiled_circuits(circuits: Sequence[pytket.circuit.Circuit], optimisation_level: int = 2) List[pytket.circuit.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 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 – 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_result(handle: pytket.backends.resulthandle.ResultHandle, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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

BackendResult

get_results(handles: Iterable[pytket.backends.resulthandle.ResultHandle], **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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.

package_result(circuit: cirq.circuits.circuit.Circuit, q_bits: Sequence[pytket.unit_id.Qubit]) pytket.backends.backendresult.BackendResult#
Parameters
  • circuit (CirqCircuit) – The circuit to simulate.

  • q_bits (Sequence[Qubit]) – ordered pytket Qubit

Returns

result of simulation

Return type

BackendResult

package_results(circuit: cirq.circuits.circuit.Circuit, q_bits: Sequence[pytket.unit_id.Qubit]) List[pytket.backends.backendresult.BackendResult]#
Parameters
  • circuit (CirqCircuit) – The circuit to simulate.

  • q_bits (Sequence[Qubit]) – ordered pytket Qubit

Returns

sequence of moments from simulator

Return type

List[BackendResult]

pop_result(handle: pytket.backends.resulthandle.ResultHandle) Optional[Dict[str, Any]]#

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: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.resulthandle.ResultHandle#

Submit a single circuit to the backend for running. See Backend.process_circuits().

process_circuit_moments(circuit: pytket.circuit.Circuit, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.resulthandle.ResultHandle#

Submit a single circuit to the backend for running. See _CirqSimBackend.process_circuits_moments().

process_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Optional[Union[int, Sequence[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.resulthandle.ResultHandle]#

Submit circuits to the backend for running. The results will be stored in the backend’s result cache to be retrieved by the corresponding get_<data> method.

If the postprocess keyword argument is set to True, and the backend supports the feature (see supports_contextual_optimisation()), then contextual optimisatioons are applied before running the circuit and retrieved results will have any necessary classical postprocessing applied. This is not enabled by default.

Use keyword arguments to specify parameters to be used in submitting circuits See specific Backend derived class for available parameters, from the following list:

  • seed: RNG seed for simulators

  • postprocess: if True, apply contextual optimisations

Note: If a backend is reused many times, the in-memory results cache grows indefinitely. Therefore, when processing many circuits on a statevector or unitary backend (whose results may occupy significant amounts of memory), it is advisable to run Backend.empty_cache() after each result is retrieved.

Parameters
  • circuits (Sequence[Circuit]) – Circuits to process on the backend.

  • n_shots (Optional[Union[int, Iterable[int]], optional) – Number of shots to run per circuit. Optionally, this can be a list of shots specifying the number of shots for each circuit separately. None is to be used for state/unitary simulators. Defaults to None.

  • valid_check (bool, optional) – Explicitly check that all circuits satisfy all required predicates to run on the backend. Defaults to True

Returns

Handles to results for each input circuit, as an interable in the same order as the circuits.

Return type

List[ResultHandle]

process_circuits_moments(circuits: Sequence[pytket.circuit.Circuit], valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.resulthandle.ResultHandle]#

Submit circuits to the backend for running. The results will be stored in the backend’s result cache to be retrieved by the corresponding get_<data> method. The get_<data> method will return List[BackendResult] corresponding to each moment.

Parameters
  • circuits (Iterable[Circuit]) – Circuits to process on the backend.

  • valid_check (bool, optional) – Explicitly check that all circuits satisfy all required predicates to run on the backend. Defaults to True

Returns

Handles to results for each input circuit, as an interable in the same order as the circuits.

Return type

List[ResultHandle]

rebase_pass() pytket.passes.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

BasePass

run_circuit(circuit: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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 by Backend.get_result(). Any additional keyword arguments are passed on to Backend.process_circuit() and Backend.get_result().

run_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Optional[Union[int, Sequence[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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 by Backend.get_results(). Any additional keyword arguments are passed on to Backend.process_circuits() and Backend.get_results().

valid_circuit(circuit: pytket.circuit.Circuit) bool#

Checks that the circuit satisfies all of required_predicates.

Parameters

circuit (Circuit) – The circuit to check.

Returns

Whether or not all of required_predicates are satisfied.

Return type

bool

property backend_info: Optional[pytket.backends.backendinfo.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[pytket.predicates.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().

property supports_state: bool#

Does this backend support statevector retrieval via backendresult.BackendResult.get_state().

property supports_unitary: bool#

Does this backend support unitary retrieval via backendresult.BackendResult.get_unitary().

class pytket.extensions.cirq.CirqDensityMatrixSimBackend(seed: Any = None, noise_model: Union[None, cirq.NoiseModel, cirq.Gate] = None)#

Backend for Cirq density matrix simulator density_matrix return.

classmethod available_devices(**kwargs: Any) List[pytket.backends.backendinfo.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: pytket.backends.resulthandle.ResultHandle) None#

Cancel a job.

Parameters

handle (ResultHandle) – handle to job

Raises

NotImplementedError – If backend does not support job cancellation

circuit_status(handle: pytket.backends.resulthandle.ResultHandle) pytket.backends.status.CircuitStatus#

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

default_compilation_pass(optimisation_level: int = 1) pytket.passes.BasePass#

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.

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.

Returns

Compilation pass guaranteeing required predicates.

Return type

BasePass

empty_cache() None#

Manually empty the result cache on the backend.

get_compiled_circuit(circuit: pytket.circuit.Circuit, optimisation_level: int = 2) pytket.circuit.Circuit#

Return a single circuit compiled with default_compilation_pass(). See Backend.get_compiled_circuits().

get_compiled_circuits(circuits: Sequence[pytket.circuit.Circuit], optimisation_level: int = 2) List[pytket.circuit.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 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 – 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_result(handle: pytket.backends.resulthandle.ResultHandle, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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

BackendResult

get_results(handles: Iterable[pytket.backends.resulthandle.ResultHandle], **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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.

package_result(circuit: cirq.circuits.circuit.Circuit, q_bits: Sequence[pytket.unit_id.Qubit]) pytket.backends.backendresult.BackendResult#
Parameters
  • circuit (CirqCircuit) – The circuit to simulate.

  • q_bits (Sequence[Qubit]) – ordered pytket Qubit

Returns

result of simulation

Return type

BackendResult

package_results(circuit: cirq.circuits.circuit.Circuit, q_bits: Sequence[pytket.unit_id.Qubit]) List[pytket.backends.backendresult.BackendResult]#
Parameters
  • circuit (CirqCircuit) – The circuit to simulate.

  • q_bits (Sequence[Qubit]) – ordered pytket Qubit

Returns

sequence of moments from simulator

Return type

List[BackendResult]

pop_result(handle: pytket.backends.resulthandle.ResultHandle) Optional[Dict[str, Any]]#

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: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.resulthandle.ResultHandle#

Submit a single circuit to the backend for running. See Backend.process_circuits().

process_circuit_moments(circuit: pytket.circuit.Circuit, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.resulthandle.ResultHandle#

Submit a single circuit to the backend for running. See _CirqSimBackend.process_circuits_moments().

process_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Optional[Union[int, Sequence[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.resulthandle.ResultHandle]#

Submit circuits to the backend for running. The results will be stored in the backend’s result cache to be retrieved by the corresponding get_<data> method.

If the postprocess keyword argument is set to True, and the backend supports the feature (see supports_contextual_optimisation()), then contextual optimisatioons are applied before running the circuit and retrieved results will have any necessary classical postprocessing applied. This is not enabled by default.

Use keyword arguments to specify parameters to be used in submitting circuits See specific Backend derived class for available parameters, from the following list:

  • seed: RNG seed for simulators

  • postprocess: if True, apply contextual optimisations

Note: If a backend is reused many times, the in-memory results cache grows indefinitely. Therefore, when processing many circuits on a statevector or unitary backend (whose results may occupy significant amounts of memory), it is advisable to run Backend.empty_cache() after each result is retrieved.

Parameters
  • circuits (Sequence[Circuit]) – Circuits to process on the backend.

  • n_shots (Optional[Union[int, Iterable[int]], optional) – Number of shots to run per circuit. Optionally, this can be a list of shots specifying the number of shots for each circuit separately. None is to be used for state/unitary simulators. Defaults to None.

  • valid_check (bool, optional) – Explicitly check that all circuits satisfy all required predicates to run on the backend. Defaults to True

Returns

Handles to results for each input circuit, as an interable in the same order as the circuits.

Return type

List[ResultHandle]

process_circuits_moments(circuits: Sequence[pytket.circuit.Circuit], valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.resulthandle.ResultHandle]#

Submit circuits to the backend for running. The results will be stored in the backend’s result cache to be retrieved by the corresponding get_<data> method. The get_<data> method will return List[BackendResult] corresponding to each moment.

Parameters
  • circuits (Iterable[Circuit]) – Circuits to process on the backend.

  • valid_check (bool, optional) – Explicitly check that all circuits satisfy all required predicates to run on the backend. Defaults to True

Returns

Handles to results for each input circuit, as an interable in the same order as the circuits.

Return type

List[ResultHandle]

rebase_pass() pytket.passes.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

BasePass

run_circuit(circuit: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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 by Backend.get_result(). Any additional keyword arguments are passed on to Backend.process_circuit() and Backend.get_result().

run_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Optional[Union[int, Sequence[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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 by Backend.get_results(). Any additional keyword arguments are passed on to Backend.process_circuits() and Backend.get_results().

valid_circuit(circuit: pytket.circuit.Circuit) bool#

Checks that the circuit satisfies all of required_predicates.

Parameters

circuit (Circuit) – The circuit to check.

Returns

Whether or not all of required_predicates are satisfied.

Return type

bool

property backend_info: Optional[pytket.backends.backendinfo.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[pytket.predicates.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().

property supports_state: bool#

Does this backend support statevector retrieval via backendresult.BackendResult.get_state().

property supports_unitary: bool#

Does this backend support unitary retrieval via backendresult.BackendResult.get_unitary().

class pytket.extensions.cirq.CirqCliffordSimBackend(seed: Optional[Any] = None)#

Backend for Cirq Clifford simulator state return.

classmethod available_devices(**kwargs: Any) List[pytket.backends.backendinfo.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: pytket.backends.resulthandle.ResultHandle) None#

Cancel a job.

Parameters

handle (ResultHandle) – handle to job

Raises

NotImplementedError – If backend does not support job cancellation

circuit_status(handle: pytket.backends.resulthandle.ResultHandle) pytket.backends.status.CircuitStatus#

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

default_compilation_pass(optimisation_level: int = 1) pytket.passes.BasePass#

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.

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.

Returns

Compilation pass guaranteeing required predicates.

Return type

BasePass

empty_cache() None#

Manually empty the result cache on the backend.

get_compiled_circuit(circuit: pytket.circuit.Circuit, optimisation_level: int = 2) pytket.circuit.Circuit#

Return a single circuit compiled with default_compilation_pass(). See Backend.get_compiled_circuits().

get_compiled_circuits(circuits: Sequence[pytket.circuit.Circuit], optimisation_level: int = 2) List[pytket.circuit.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 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 – 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_result(handle: pytket.backends.resulthandle.ResultHandle, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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

BackendResult

get_results(handles: Iterable[pytket.backends.resulthandle.ResultHandle], **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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.

package_result(circuit: cirq.circuits.circuit.Circuit, q_bits: Sequence[pytket.unit_id.Qubit]) pytket.backends.backendresult.BackendResult#
Parameters
  • circuit (CirqCircuit) – The circuit to simulate.

  • q_bits (Sequence[Qubit]) – ordered pytket Qubit

Returns

result of simulation

Return type

BackendResult

package_results(circuit: cirq.circuits.circuit.Circuit, q_bits: Sequence[pytket.unit_id.Qubit]) List[pytket.backends.backendresult.BackendResult]#
Parameters
  • circuit (CirqCircuit) – The circuit to simulate.

  • q_bits (Sequence[Qubit]) – ordered pytket Qubit

Returns

sequence of moments from simulator

Return type

List[BackendResult]

pop_result(handle: pytket.backends.resulthandle.ResultHandle) Optional[Dict[str, Any]]#

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: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.resulthandle.ResultHandle#

Submit a single circuit to the backend for running. See Backend.process_circuits().

process_circuit_moments(circuit: pytket.circuit.Circuit, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.resulthandle.ResultHandle#

Submit a single circuit to the backend for running. See _CirqSimBackend.process_circuits_moments().

process_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Optional[Union[int, Sequence[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.resulthandle.ResultHandle]#

Submit circuits to the backend for running. The results will be stored in the backend’s result cache to be retrieved by the corresponding get_<data> method.

If the postprocess keyword argument is set to True, and the backend supports the feature (see supports_contextual_optimisation()), then contextual optimisatioons are applied before running the circuit and retrieved results will have any necessary classical postprocessing applied. This is not enabled by default.

Use keyword arguments to specify parameters to be used in submitting circuits See specific Backend derived class for available parameters, from the following list:

  • seed: RNG seed for simulators

  • postprocess: if True, apply contextual optimisations

Note: If a backend is reused many times, the in-memory results cache grows indefinitely. Therefore, when processing many circuits on a statevector or unitary backend (whose results may occupy significant amounts of memory), it is advisable to run Backend.empty_cache() after each result is retrieved.

Parameters
  • circuits (Sequence[Circuit]) – Circuits to process on the backend.

  • n_shots (Optional[Union[int, Iterable[int]], optional) – Number of shots to run per circuit. Optionally, this can be a list of shots specifying the number of shots for each circuit separately. None is to be used for state/unitary simulators. Defaults to None.

  • valid_check (bool, optional) – Explicitly check that all circuits satisfy all required predicates to run on the backend. Defaults to True

Returns

Handles to results for each input circuit, as an interable in the same order as the circuits.

Return type

List[ResultHandle]

process_circuits_moments(circuits: Sequence[pytket.circuit.Circuit], valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.resulthandle.ResultHandle]#

Submit circuits to the backend for running. The results will be stored in the backend’s result cache to be retrieved by the corresponding get_<data> method. The get_<data> method will return List[BackendResult] corresponding to each moment.

Parameters
  • circuits (Iterable[Circuit]) – Circuits to process on the backend.

  • valid_check (bool, optional) – Explicitly check that all circuits satisfy all required predicates to run on the backend. Defaults to True

Returns

Handles to results for each input circuit, as an interable in the same order as the circuits.

Return type

List[ResultHandle]

rebase_pass() pytket.passes.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

BasePass

run_circuit(circuit: pytket.circuit.Circuit, n_shots: Optional[int] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.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 by Backend.get_result(). Any additional keyword arguments are passed on to Backend.process_circuit() and Backend.get_result().

run_circuits(circuits: Sequence[pytket.circuit.Circuit], n_shots: Optional[Union[int, Sequence[int]]] = None, valid_check: bool = True, **kwargs: Optional[Union[int, float, str]]) List[pytket.backends.backendresult.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 by Backend.get_results(). Any additional keyword arguments are passed on to Backend.process_circuits() and Backend.get_results().

valid_circuit(circuit: pytket.circuit.Circuit) bool#

Checks that the circuit satisfies all of required_predicates.

Parameters

circuit (Circuit) – The circuit to check.

Returns

Whether or not all of required_predicates are satisfied.

Return type

bool

property backend_info: Optional[pytket.backends.backendinfo.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[pytket.predicates.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().

property supports_state: bool#

Does this backend support statevector retrieval via backendresult.BackendResult.get_state().

property supports_unitary: bool#

Does this backend support unitary retrieval via backendresult.BackendResult.get_unitary().