API documentation

Module for conversion between ProjectQ and tket primitives.

class pytket.extensions.projectq.ProjectQBackend[source]

Backend for running statevector simulations on the ProjectQ simulator.

circuit_status(handle)[source]

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

Return type:

CircuitStatus

default_compilation_pass(optimisation_level=1)[source]

A suggested compilation pass that will will, if possible, produce an equivalent circuit suitable for running on this backend.

At a minimum it will ensure that compatible gates are used and that all two- qubit interactions are compatible with the backend’s qubit architecture. At higher optimisation levels, further optimisations may be applied.

This is a an abstract method which is implemented in the backend itself, and so is tailored to the backend’s requirements.

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, operator, valid_check=True)[source]

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, pauli, valid_check=True)[source]

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

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

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

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[source]

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

is_available(cmd)[source]

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) – Command for which to check availability.

Return type:

bool

Returns:

True if the command can be executed.

receive(command_list)[source]

Process commands from a list and append to local Circuit.

Return type:

None

property circuit: Circuit
If the Circuit has no gates, assumes user forgot to

flush engines.

Returns:

The tket Circuit from the engine.

Type:

raises NotImplementedError

class pytket.extensions.projectq.tketOptimiser[source]

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

receive(command_list)[source]

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.

Return type:

None

pytket.extensions.projectq.tk_to_projectq(engine, qureg, circuit, ignore_measures=False)[source]

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

Return type:

None