API documentation#

Module for conversion between ProjectQ and tket primitives.

class pytket.extensions.projectq.ProjectQBackend#

Backend for running statevector simulations on the ProjectQ simulator.

circuit_status(handle: ResultHandle) CircuitStatus#

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

default_compilation_pass(optimisation_level: int = 1) 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: Circuit, operator: QubitPauliOperator, valid_check: bool = True) complex#

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

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

  • operator (QubitPauliOperator) – Operator \(H\). Must be Hermitian.

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

Returns:

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

Return type:

complex

get_pauli_expectation_value(state_circuit: Circuit, pauli: QubitPauliString, valid_check: bool = True) complex#

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

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

  • pauli (QubitPauliString) – Pauli operator

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

Returns:

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

Return type:

complex

process_circuits(circuits: Sequence[Circuit], n_shots: None | int | Sequence[int | None] = None, valid_check: bool = True, **kwargs: int | float | str | None) List[ResultHandle]#

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

rebase_pass() BasePass#

A single compilation pass that when run converts all gates in a Circuit to an OpType supported by the Backend (ignoring architecture constraints).

Returns:

Compilation pass that converts gates to primitives supported by Backend.

Return type:

BasePass

property backend_info: BackendInfo#

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

Returns:

The BackendInfo describing this backend if it exists.

Return type:

Optional[BackendInfo]

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

class pytket.extensions.projectq.tketBackendEngine#

A projectq backend designed to translate from projectq commands to tket Circuits

is_available(cmd: Command) bool#

Ask the next engine whether a command is available, i.e., whether it can be executed by the next engine(s).

Raises:

LastEngineException – If is_last_engine is True but is_available is not implemented.

Parameters:

cmd – Command for which to check availability.

Returns:

True if the command can be executed.

receive(command_list: Iterable) None#

Process commands from a list and append to local Circuit.

property circuit: Circuit#
Raises:

NotImplementedError – If the Circuit has no gates, assumes user forgot to flush engines.

Returns:

The tket Circuit from the engine.

class pytket.extensions.projectq.tketOptimiser#

A ProjectQ BasicEngine designed to translate from ProjectQ commands to tket Circuits, optimise them, and then return other ProjectQ commands.

receive(command_list: list) None#

Receives a list of commands and appends to local Circuit. If a flush gate is received, optimises the Circuit using a default Transform pass and then sends the commands from this optimised Circuit into the next engine.

pytket.extensions.projectq.tk_to_projectq(engine: MainEngine, qureg: Qureg, circuit: Circuit, ignore_measures: bool = False) None#

Given a ProjectQ Qureg in an Engine, converts a Circuit to a series of ProjectQ Commands on this Qureg.

Parameters:
  • engine (MainEngine) – A ProjectQ MainEngine

  • qureg (Qureg) – A ProjectQ Qureg in this MainEngine

  • circuit (Circuit) – A tket Circuit