API documentation

Module for conversion between Google Cirq and tket primitives.

pytket.extensions.cirq.cirq_to_tk(circuit)[source]

Converts a Cirq Circuit to a tket Circuit object.

Parameters:

circuit (Circuit) – The input Cirq Circuit

Raises:

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

Return type:

Circuit

Returns:

The tket Circuit corresponding to the input circuit

pytket.extensions.cirq.process_characterisation(device)[source]

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

Parameters:

device (GridDevice) – The device to convert

Return type:

dict

Returns:

A dictionary containing device characteristics

pytket.extensions.cirq.tk_to_cirq(tkcirc, copy_all_qubits=False)[source]

Converts a tket Circuit object to a Cirq Circuit.

Parameters:

tkcirc (Circuit) – The input tket Circuit

Return type:

Circuit

Returns:

The Cirq Circuit corresponding to the input circuit

class pytket.extensions.cirq.CirqStateSampleBackend(seed=None)[source]

Backend for Cirq statevector simulator sampling.

classmethod available_devices(**kwargs)

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)

Cancel a job.

Parameters:

handle (ResultHandle) – handle to job

Raises:

NotImplementedError – If backend does not support job cancellation

Return type:

None

circuit_status(handle)

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

Return type:

CircuitStatus

default_compilation_pass(optimisation_level=1)

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()

Manually empty the result cache on the backend.

Return type:

None

get_compiled_circuit(circuit, optimisation_level=2)

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

Return type:

Circuit

get_compiled_circuits(circuits, optimisation_level=2)

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

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

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

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

  • optimisation_level (int, 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, **kwargs)

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, **kwargs)

Return results corresponding to handles.

Parameters:

handles (Iterable[ResultHandle]) – Iterable of handles

Return type:

list[BackendResult]

Returns:

List of results

Keyword arguments are as for get_result, and apply to all jobs.

pop_result(handle)

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, n_shots=None, valid_check=True, **kwargs)

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

Return type:

ResultHandle

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

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()

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, n_shots=None, valid_check=True, **kwargs)

Submits a circuit to the backend and returns results

Parameters:
  • circuit (Circuit) – Circuit to be executed

  • n_shots (Optional[int]) – Passed on to Backend.process_circuit()

  • valid_check (bool) – Passed on to Backend.process_circuit()

Return type:

BackendResult

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, n_shots=None, valid_check=True, **kwargs)

Submits circuits to the backend and returns results

Parameters:
  • circuits (Sequence[Circuit]) – Sequence of Circuits to be executed

  • n_shots (Union[int, Sequence[int], None]) – Passed on to Backend.process_circuits()

  • valid_check (bool) – Passed on to Backend.process_circuits()

Return type:

list[BackendResult]

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)

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: BackendInfo | None

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

Returns:

The BackendInfo describing this backend if it exists.

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().

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=None, noise_model=None)[source]

Backend for Cirq density matrix simulator sampling.

classmethod available_devices(**kwargs)

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)

Cancel a job.

Parameters:

handle (ResultHandle) – handle to job

Raises:

NotImplementedError – If backend does not support job cancellation

Return type:

None

circuit_status(handle)

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

Return type:

CircuitStatus

default_compilation_pass(optimisation_level=1)

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()

Manually empty the result cache on the backend.

Return type:

None

get_compiled_circuit(circuit, optimisation_level=2)

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

Return type:

Circuit

get_compiled_circuits(circuits, optimisation_level=2)

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

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

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

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

  • optimisation_level (int, 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, **kwargs)

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, **kwargs)

Return results corresponding to handles.

Parameters:

handles (Iterable[ResultHandle]) – Iterable of handles

Return type:

list[BackendResult]

Returns:

List of results

Keyword arguments are as for get_result, and apply to all jobs.

pop_result(handle)

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, n_shots=None, valid_check=True, **kwargs)

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

Return type:

ResultHandle

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

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()

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, n_shots=None, valid_check=True, **kwargs)

Submits a circuit to the backend and returns results

Parameters:
  • circuit (Circuit) – Circuit to be executed

  • n_shots (Optional[int]) – Passed on to Backend.process_circuit()

  • valid_check (bool) – Passed on to Backend.process_circuit()

Return type:

BackendResult

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, n_shots=None, valid_check=True, **kwargs)

Submits circuits to the backend and returns results

Parameters:
  • circuits (Sequence[Circuit]) – Sequence of Circuits to be executed

  • n_shots (Union[int, Sequence[int], None]) – Passed on to Backend.process_circuits()

  • valid_check (bool) – Passed on to Backend.process_circuits()

Return type:

list[BackendResult]

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)

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: BackendInfo | None

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

Returns:

The BackendInfo describing this backend if it exists.

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().

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=None)[source]

Backend for Cirq Clifford simulator sampling.

classmethod available_devices(**kwargs)

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)

Cancel a job.

Parameters:

handle (ResultHandle) – handle to job

Raises:

NotImplementedError – If backend does not support job cancellation

Return type:

None

circuit_status(handle)

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

Return type:

CircuitStatus

default_compilation_pass(optimisation_level=1)

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()

Manually empty the result cache on the backend.

Return type:

None

get_compiled_circuit(circuit, optimisation_level=2)

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

Return type:

Circuit

get_compiled_circuits(circuits, optimisation_level=2)

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

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

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

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

  • optimisation_level (int, 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, **kwargs)

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, **kwargs)

Return results corresponding to handles.

Parameters:

handles (Iterable[ResultHandle]) – Iterable of handles

Return type:

list[BackendResult]

Returns:

List of results

Keyword arguments are as for get_result, and apply to all jobs.

pop_result(handle)

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, n_shots=None, valid_check=True, **kwargs)

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

Return type:

ResultHandle

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

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()[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:

BasePass

run_circuit(circuit, n_shots=None, valid_check=True, **kwargs)

Submits a circuit to the backend and returns results

Parameters:
  • circuit (Circuit) – Circuit to be executed

  • n_shots (Optional[int]) – Passed on to Backend.process_circuit()

  • valid_check (bool) – Passed on to Backend.process_circuit()

Return type:

BackendResult

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, n_shots=None, valid_check=True, **kwargs)

Submits circuits to the backend and returns results

Parameters:
  • circuits (Sequence[Circuit]) – Sequence of Circuits to be executed

  • n_shots (Union[int, Sequence[int], None]) – Passed on to Backend.process_circuits()

  • valid_check (bool) – Passed on to Backend.process_circuits()

Return type:

list[BackendResult]

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)

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: BackendInfo | None

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

Returns:

The BackendInfo describing this backend if it exists.

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().

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=None)[source]

Backend for Cirq statevector simulator state return.

classmethod available_devices(**kwargs)

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)

Cancel a job.

Parameters:

handle (ResultHandle) – handle to job

Raises:

NotImplementedError – If backend does not support job cancellation

Return type:

None

circuit_status(handle)

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

Return type:

CircuitStatus

default_compilation_pass(optimisation_level=1)

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()

Manually empty the result cache on the backend.

Return type:

None

get_compiled_circuit(circuit, optimisation_level=2)

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

Return type:

Circuit

get_compiled_circuits(circuits, optimisation_level=2)

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

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

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

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

  • optimisation_level (int, 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, **kwargs)

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, **kwargs)

Return results corresponding to handles.

Parameters:

handles (Iterable[ResultHandle]) – Iterable of handles

Return type:

list[BackendResult]

Returns:

List of results

Keyword arguments are as for get_result, and apply to all jobs.

package_result(circuit, q_bits)[source]
Parameters:
  • circuit (CirqCircuit) – The circuit to simulate.

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

Returns:

result of simulation

Return type:

BackendResult

package_results(circuit, q_bits)[source]
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)

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, n_shots=None, valid_check=True, **kwargs)

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

Return type:

ResultHandle

process_circuit_moments(circuit, valid_check=True, **kwargs)

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

Return type:

ResultHandle

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

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, valid_check=True, **kwargs)

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()

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, n_shots=None, valid_check=True, **kwargs)

Submits a circuit to the backend and returns results

Parameters:
  • circuit (Circuit) – Circuit to be executed

  • n_shots (Optional[int]) – Passed on to Backend.process_circuit()

  • valid_check (bool) – Passed on to Backend.process_circuit()

Return type:

BackendResult

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, n_shots=None, valid_check=True, **kwargs)

Submits circuits to the backend and returns results

Parameters:
  • circuits (Sequence[Circuit]) – Sequence of Circuits to be executed

  • n_shots (Union[int, Sequence[int], None]) – Passed on to Backend.process_circuits()

  • valid_check (bool) – Passed on to Backend.process_circuits()

Return type:

list[BackendResult]

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)

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: BackendInfo | None

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

Returns:

The BackendInfo describing this backend if it exists.

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().

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=None, noise_model=None)[source]

Backend for Cirq density matrix simulator density_matrix return.

classmethod available_devices(**kwargs)

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)

Cancel a job.

Parameters:

handle (ResultHandle) – handle to job

Raises:

NotImplementedError – If backend does not support job cancellation

Return type:

None

circuit_status(handle)

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

Return type:

CircuitStatus

default_compilation_pass(optimisation_level=1)

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()

Manually empty the result cache on the backend.

Return type:

None

get_compiled_circuit(circuit, optimisation_level=2)

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

Return type:

Circuit

get_compiled_circuits(circuits, optimisation_level=2)

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

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

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

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

  • optimisation_level (int, 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, **kwargs)

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, **kwargs)

Return results corresponding to handles.

Parameters:

handles (Iterable[ResultHandle]) – Iterable of handles

Return type:

list[BackendResult]

Returns:

List of results

Keyword arguments are as for get_result, and apply to all jobs.

package_result(circuit, q_bits)[source]
Parameters:
  • circuit (CirqCircuit) – The circuit to simulate.

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

Returns:

result of simulation

Return type:

BackendResult

package_results(circuit, q_bits)[source]
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)

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, n_shots=None, valid_check=True, **kwargs)

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

Return type:

ResultHandle

process_circuit_moments(circuit, valid_check=True, **kwargs)

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

Return type:

ResultHandle

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

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, valid_check=True, **kwargs)

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()

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, n_shots=None, valid_check=True, **kwargs)

Submits a circuit to the backend and returns results

Parameters:
  • circuit (Circuit) – Circuit to be executed

  • n_shots (Optional[int]) – Passed on to Backend.process_circuit()

  • valid_check (bool) – Passed on to Backend.process_circuit()

Return type:

BackendResult

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, n_shots=None, valid_check=True, **kwargs)

Submits circuits to the backend and returns results

Parameters:
  • circuits (Sequence[Circuit]) – Sequence of Circuits to be executed

  • n_shots (Union[int, Sequence[int], None]) – Passed on to Backend.process_circuits()

  • valid_check (bool) – Passed on to Backend.process_circuits()

Return type:

list[BackendResult]

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)

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: BackendInfo | None

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

Returns:

The BackendInfo describing this backend if it exists.

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().

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=None)[source]

Backend for Cirq Clifford simulator state return.

classmethod available_devices(**kwargs)

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)

Cancel a job.

Parameters:

handle (ResultHandle) – handle to job

Raises:

NotImplementedError – If backend does not support job cancellation

Return type:

None

circuit_status(handle)

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

Return type:

CircuitStatus

default_compilation_pass(optimisation_level=1)

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()

Manually empty the result cache on the backend.

Return type:

None

get_compiled_circuit(circuit, optimisation_level=2)

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

Return type:

Circuit

get_compiled_circuits(circuits, optimisation_level=2)

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

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

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

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

  • optimisation_level (int, 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, **kwargs)

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, **kwargs)

Return results corresponding to handles.

Parameters:

handles (Iterable[ResultHandle]) – Iterable of handles

Return type:

list[BackendResult]

Returns:

List of results

Keyword arguments are as for get_result, and apply to all jobs.

package_result(circuit, q_bits)[source]
Parameters:
  • circuit (CirqCircuit) – The circuit to simulate.

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

Returns:

result of simulation

Return type:

BackendResult

package_results(circuit, q_bits)[source]
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)

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, n_shots=None, valid_check=True, **kwargs)

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

Return type:

ResultHandle

process_circuit_moments(circuit, valid_check=True, **kwargs)

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

Return type:

ResultHandle

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

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, valid_check=True, **kwargs)

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()[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:

BasePass

run_circuit(circuit, n_shots=None, valid_check=True, **kwargs)

Submits a circuit to the backend and returns results

Parameters:
  • circuit (Circuit) – Circuit to be executed

  • n_shots (Optional[int]) – Passed on to Backend.process_circuit()

  • valid_check (bool) – Passed on to Backend.process_circuit()

Return type:

BackendResult

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, n_shots=None, valid_check=True, **kwargs)

Submits circuits to the backend and returns results

Parameters:
  • circuits (Sequence[Circuit]) – Sequence of Circuits to be executed

  • n_shots (Union[int, Sequence[int], None]) – Passed on to Backend.process_circuits()

  • valid_check (bool) – Passed on to Backend.process_circuits()

Return type:

list[BackendResult]

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)

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: BackendInfo | None

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

Returns:

The BackendInfo describing this backend if it exists.

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().

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().