setups

The setups package contains a collection of setups which can be loaded by the MainEngine. Each setup contains a get_engine_list function which returns a list of compiler engines:

Example:
import projectq.setups.ibm as ibm_setup
from projectq import MainEngine

eng = MainEngine(engine_list=ibm_setup.get_engine_list())
# eng uses the default Simulator backend

The subpackage decompositions contains all the individual decomposition rules which can be given to, e.g., an AutoReplacer.

Subpackages

Submodules

Each of the submodules contains a setup which can be used to specify the engine_list used by the MainEngine :

projectq.setups._utils

Some utility functions common to some setups.

projectq.setups.aqt

A setup for AQT trapped ion devices.

projectq.setups.default

The default setup which provides an engine_list for the MainEngine.

projectq.setups.grid

A setup to compile to qubits placed in 2-D grid.

projectq.setups.ibm

A setup for IBM quantum chips.

projectq.setups.ionq

A setup for IonQ trapped ion devices.

projectq.setups.linear

A setup to compile to qubits placed in a linear chain or a circle.

projectq.setups.restrictedgateset

Defines a setup to compile to a restricted gate set.

projectq.setups.trapped_ion_decomposer

Apply the restricted gate set setup for trapped ion based quantum computers.

_utils

Some utility functions common to some setups.

projectq.setups._utils.get_engine_list_linear_grid_base(mapper, one_qubit_gates='any', two_qubit_gates=(<projectq.ops._metagates.ControlledGate object>, <projectq.ops._gates.SwapGate object>))[source]

Return an engine list to compile to a 2-D grid of qubits.

Note

If you choose a new gate set for which the compiler does not yet have standard rules, it raises an NoGateDecompositionError or a RuntimeError: maximum recursion depth exceeded…. Also note that even the gate sets which work might not yet be optimized. So make sure to double check and potentially extend the decomposition rules. This implementation currently requires that the one qubit gates must contain Rz and at least one of {Ry(best), Rx, H} and the two qubit gate must contain CNOT (recommended) or CZ.

Note

Classical instructions gates such as e.g. Flush and Measure are automatically allowed.

Example

get_engine_list(num_rows=2, num_columns=3,

one_qubit_gates=(Rz, Ry, Rx, H), two_qubit_gates=(CNOT,))

Parameters:
  • num_rows (int) – Number of rows in the grid

  • num_columns (int) – Number of columns in the grid.

  • one_qubit_gates – “any” allows any one qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. X), it allows all gates which are equal to it. If the gate is a class (Rz), it allows all instances of this class. Default is “any”

  • two_qubit_gates – “any” allows any two qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. CNOT), it allows all gates which are equal to it. If the gate is a class, it allows all instances of this class. Default is (CNOT, Swap).

Raises:

TypeError – If input is for the gates is not “any” or a tuple.

Returns:

A list of suitable compiler engines.

projectq.setups._utils.high_level_gates(eng, cmd)[source]

Remove any MathGates.

projectq.setups._utils.one_and_two_qubit_gates(eng, cmd)[source]

Filter out 1- and 2-qubit gates.

aqt

A setup for AQT trapped ion devices.

Defines a setup allowing to compile code for the AQT trapped ion devices: ->The 4 qubits device ->The 11 qubits simulator ->The 11 qubits noisy simulator

It provides the engine_list for the `MainEngine’ based on the requested device. Decompose the circuit into a Rx/Ry/Rxx gate set that will be translated in the backend in the Rx/Ry/MS gate set.

projectq.setups.aqt.get_engine_list(token=None, device=None)[source]

Return the default list of compiler engine for the AQT platform.

default

The default setup which provides an engine_list for the MainEngine.

It contains LocalOptimizers and an AutoReplacer which uses most of the decompositions rules defined in projectq.setups.decompositions

projectq.setups.default.get_engine_list()[source]

Return the default list of compiler engine.

grid

A setup to compile to qubits placed in 2-D grid.

It provides the engine_list for the MainEngine. This engine list contains an AutoReplacer with most of the gate decompositions of ProjectQ, which are used to decompose a circuit into only two qubit gates and arbitrary single qubit gates. ProjectQ’s GridMapper is then used to introduce the necessary Swap operations to route interacting qubits next to each other. This setup allows to choose the final gate set (with some limitations).

projectq.setups.grid.get_engine_list(num_rows, num_columns, one_qubit_gates='any', two_qubit_gates=(<projectq.ops._metagates.ControlledGate object>, <projectq.ops._gates.SwapGate object>))[source]

Return an engine list to compile to a 2-D grid of qubits.

Note

If you choose a new gate set for which the compiler does not yet have standard rules, it raises an NoGateDecompositionError or a RuntimeError: maximum recursion depth exceeded…. Also note that even the gate sets which work might not yet be optimized. So make sure to double check and potentially extend the decomposition rules. This implementation currently requires that the one qubit gates must contain Rz and at least one of {Ry(best), Rx, H} and the two qubit gate must contain CNOT (recommended) or CZ.

Note

Classical instructions gates such as e.g. Flush and Measure are automatically allowed.

Example

get_engine_list(num_rows=2, num_columns=3,

one_qubit_gates=(Rz, Ry, Rx, H), two_qubit_gates=(CNOT,))

Parameters:
  • num_rows (int) – Number of rows in the grid

  • num_columns (int) – Number of columns in the grid.

  • one_qubit_gates – “any” allows any one qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. X), it allows all gates which are equal to it. If the gate is a class (Rz), it allows all instances of this class. Default is “any”

  • two_qubit_gates – “any” allows any two qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. CNOT), it allows all gates which are equal to it. If the gate is a class, it allows all instances of this class. Default is (CNOT, Swap).

Raises:

TypeError – If input is for the gates is not “any” or a tuple.

Returns:

A list of suitable compiler engines.

ibm

A setup for IBM quantum chips.

Defines a setup allowing to compile code for the IBM quantum chips: * Any 5 qubit devices * the ibmq online simulator * the melbourne 15 qubit device

It provides the engine_list for the `MainEngine’ based on the requested device.

Decompose the circuit into a Rx/Ry/Rz/H/CNOT gate set that will be translated in the backend in the U1/U2/U3/CX gate set.

projectq.setups.ibm.get_engine_list(token=None, device=None)[source]

Return the default list of compiler engine for the IBM QE platform.

projectq.setups.ibm.list2set(coupling_list)[source]

Convert a list() to a set().

ionq

A setup for IonQ trapped ion devices.

Defines a setup allowing to compile code for IonQ trapped ion devices: ->The 11 qubit device ->The 29 qubits simulator

projectq.setups.ionq.get_engine_list(token=None, device=None)[source]

Return the default list of compiler engine for the IonQ platform.

linear

A setup to compile to qubits placed in a linear chain or a circle.

It provides the engine_list for the MainEngine. This engine list contains an AutoReplacer with most of the gate decompositions of ProjectQ, which are used to decompose a circuit into only two qubit gates and arbitrary single qubit gates. ProjectQ’s LinearMapper is then used to introduce the necessary Swap operations to route interacting qubits next to each other. This setup allows to choose the final gate set (with some limitations).

projectq.setups.linear.get_engine_list(num_qubits, cyclic=False, one_qubit_gates='any', two_qubit_gates=(<projectq.ops._metagates.ControlledGate object>, <projectq.ops._gates.SwapGate object>))[source]

Return an engine list to compile to a linear chain of qubits.

Note

If you choose a new gate set for which the compiler does not yet have standard rules, it raises an NoGateDecompositionError or a RuntimeError: maximum recursion depth exceeded…. Also note that even the gate sets which work might not yet be optimized. So make sure to double check and potentially extend the decomposition rules. This implementation currently requires that the one qubit gates must contain Rz and at least one of {Ry(best), Rx, H} and the two qubit gate must contain CNOT (recommended) or CZ.

Note

Classical instructions gates such as e.g. Flush and Measure are automatically allowed.

Example

get_engine_list(num_qubits=10, cyclic=False,

one_qubit_gates=(Rz, Ry, Rx, H), two_qubit_gates=(CNOT,))

Parameters:
  • num_qubits (int) – Number of qubits in the chain

  • cyclic (bool) – If a circle or not. Default is False

  • one_qubit_gates – “any” allows any one qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. X), it allows all gates which are equal to it. If the gate is a class (Rz), it allows all instances of this class. Default is “any”

  • two_qubit_gates – “any” allows any two qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. CNOT), it allows all gates which are equal to it. If the gate is a class, it allows all instances of this class. Default is (CNOT, Swap).

Raises:

TypeError – If input is for the gates is not “any” or a tuple.

Returns:

A list of suitable compiler engines.

restrictedgateset

Defines a setup to compile to a restricted gate set.

It provides the engine_list for the MainEngine. This engine list contains an AutoReplacer with most of the gate decompositions of ProjectQ, which are used to decompose a circuit into a restricted gate set (with some limitations on the choice of gates).

projectq.setups.restrictedgateset.default_chooser(cmd, decomposition_list)[source]

Provide the default chooser function for the AutoReplacer compiler engine.

projectq.setups.restrictedgateset.get_engine_list(one_qubit_gates='any', two_qubit_gates=(<projectq.ops._metagates.ControlledGate object>, ), other_gates=(), compiler_chooser=<function default_chooser>)[source]

Return an engine list to compile to a restricted gate set.

Note

If you choose a new gate set for which the compiler does not yet have standard rules, it raises an NoGateDecompositionError or a RuntimeError: maximum recursion depth exceeded…. Also note that even the gate sets which work might not yet be optimized. So make sure to double check and potentially extend the decomposition rules. This implementation currently requires that the one qubit gates must contain Rz and at least one of {Ry(best), Rx, H} and the two qubit gate must contain CNOT (recommended) or CZ.

Note

Classical instructions gates such as e.g. Flush and Measure are automatically allowed.

Example

get_engine_list(one_qubit_gates=(Rz, Ry, Rx, H),

two_qubit_gates=(CNOT,), other_gates=(TimeEvolution,))

Parameters:
  • one_qubit_gates – “any” allows any one qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. X), it allows all gates which are equal to it. If the gate is a class (Rz), it allows all instances of this class. Default is “any”

  • two_qubit_gates – “any” allows any two qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. CNOT), it allows all gates which are equal to it. If the gate is a class, it allows all instances of this class. Default is (CNOT,).

  • other_gates – A tuple of the allowed gates. If the gates are instances of a class (e.g. QFT), it allows all gates which are equal to it. If the gate is a class, it allows all instances of this class.

  • compiler_chooser – function selecting the decomposition to use in the Autoreplacer engine

Raises:

TypeError – If input is for the gates is not “any” or a tuple. Also if element within tuple is not a class or instance of BasicGate (e.g. CRz which is a shortcut function)

Returns:

A list of suitable compiler engines.

trapped_ion_decomposer

Apply the restricted gate set setup for trapped ion based quantum computers.

It provides the engine_list for the MainEngine, restricting the gate set to Rx and Ry single qubit gates and the Rxx two qubit gates.

A decomposition chooser is implemented following the ideas in QUOTE for reducing the number of Ry gates in the new circuit.

Note

Because the decomposition chooser is only called when a gate has to be decomposed, this reduction will work better when the entire circuit has to be decomposed. Otherwise, If the circuit has both superconding gates and native ion trapped gates the decomposed circuit will not be optimal.

projectq.setups.trapped_ion_decomposer.chooser_Ry_reducer(cmd, decomposition_list)[source]

Choose the decomposition to maximise Ry cancellations.

Choose the decomposition so as to maximise Ry cancellations, based on the previous decomposition used for the given qubit.

Note

Classical instructions gates e.g. Flush and Measure are automatically allowed.

Returns:

A decomposition object from the decomposition_list.

projectq.setups.trapped_ion_decomposer.get_engine_list()[source]

Return an engine list compiling code into a trapped ion based compiled circuit code.

Note

  • Classical instructions gates such as e.g. Flush and Measure are automatically allowed.

  • The restricted gate set engine does not work with Rxx gates, as ProjectQ will by default bounce back and forth between Cz gates and Cx gates. An appropriate decomposition chooser needs to be used!

Returns:

A list of suitable compiler engines.

Module contents

ProjectQ module containing the basic setups for ProjectQ as well as the decomposition rules.