API documentation#

Module for conversion between Rigetti pyQuil and tket primitives.

class pytket.extensions.pyquil.ForestBackend(qc: pyquil.api._quantum_computer.QuantumComputer)#

Interface to a Rigetti device.

classmethod available_devices(**kwargs: Any) List[pytket.backends.backendinfo.BackendInfo]#

See pytket.backends.Backend.available_devices(). Supported kwargs: qpus (default true), qvms (default false).

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.

This will throw an PyQuilJobStatusUnavailable exception if the results have not been retrieved yet, as pyQuil does not currently support asynchronous job status queries.

Parameters

handle (ResultHandle) – The handle to the submitted job.

Returns

The status of the submitted job.

Raises
  • PyQuilJobStatusUnavailable – Cannot retrieve job status.

  • CircuitNotRunError – The handle does not correspond to a valid job.

default_compilation_pass(optimisation_level: int = 2) 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

get_result(handle: pytket.backends.resulthandle.ResultHandle, **kwargs: Optional[Union[int, float, str]]) pytket.backends.backendresult.BackendResult#

See pytket.backends.Backend.get_result(). Supported kwargs: none.

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]#

See pytket.backends.Backend.process_circuits(). Supported kwargs: seed.

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

property backend_info: 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 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]

class pytket.extensions.pyquil.ForestStateBackend#

State based interface to a Rigetti device.

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 = 2) 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

get_operator_expectation_value(state_circuit: pytket.circuit.Circuit, operator: pytket.utils.QubitPauliOperator) complex#

Calculates the expectation value of the given circuit with respect to the operator using the built-in QVM functionality

Parameters
  • state_circuit (Circuit) – Circuit that generates the desired state \(\left|\psi\right>\).

  • operator (QubitPauliOperator) – Operator \(H\).

Returns

\(\left<\psi | H | \psi \right>\)

Return type

complex

get_pauli_expectation_value(state_circuit: pytket.circuit.Circuit, pauli: pytket.pauli.QubitPauliString) complex#

Calculates the expectation value of the given circuit using the built-in QVM functionality

Parameters
  • state_circuit (Circuit) – Circuit that generates the desired state \(\left|\psi\right>\).

  • pauli (QubitPauliString) – Pauli operator

Returns

\(\left<\psi | P | \psi \right>\)

Return type

complex

process_circuits(circuits: Iterable[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]

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

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]

pytket.extensions.pyquil.pyquil_to_tk(prog: pyquil.quil.Program) pytket.circuit.Circuit#

Convert a pyquil.Program to a tket Circuit . Note that not all pyQuil operations are currently supported by pytket.

Parameters

prog – A circuit to be converted

Returns

The converted circuit

pytket.extensions.pyquil.tk_to_pyquil(tkcirc: pytket.circuit.Circuit, active_reset: bool = False, return_used_bits: bool = False) Union[pyquil.quil.Program, Tuple[pyquil.quil.Program, List[pytket.unit_id.Bit]]]#

Convert a tket Circuit to a pyquil.Program .

Parameters

tkcirc – A circuit to be converted

Returns

The converted circuit