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.default Defines the default setup which provides an engine_list for the MainEngine
projectq.setups.grid Defines a setup to compile to qubits placed in 2-D grid.
projectq.setups.ibm Defines a setup useful for the IBM QE chip with 5 qubits.
projectq.setups.ibm16 Defines a setup useful for the IBM QE chip with 16 qubits.
projectq.setups.linear Defines 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.

default

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

grid

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

Returns 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 implemention 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.grid.high_level_gates(eng, cmd)[source]

Remove any MathGates.

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

ibm

Defines a setup useful for the IBM QE chip with 5 qubits.

It provides the engine_list for the MainEngine, and contains an AutoReplacer with most of the gate decompositions of ProjectQ, among others it includes:

  • Controlled z-rotations –> Controlled NOTs and single-qubit rotations
  • Toffoli gate –> CNOT and single-qubit gates
  • m-Controlled global phases –> (m-1)-controlled phase-shifts
  • Global phases –> ignore
  • (controlled) Swap gates –> CNOTs and Toffolis
  • Arbitrary single qubit gates –> Rz and Ry
  • Controlled arbitrary single qubit gates –> Rz, Ry, and CNOT gates

Moreover, it contains LocalOptimizers and a custom mapper for the CNOT gates.

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

ibm16

Defines a setup useful for the IBM QE chip with 16 qubits.

It provides the engine_list for the MainEngine, and contains an AutoReplacer with most of the gate decompositions of ProjectQ, among others it includes:

  • Controlled z-rotations –> Controlled NOTs and single-qubit rotations
  • Toffoli gate –> CNOT and single-qubit gates
  • m-Controlled global phases –> (m-1)-controlled phase-shifts
  • Global phases –> ignore
  • (controlled) Swap gates –> CNOTs and Toffolis
  • Arbitrary single qubit gates –> Rz and Ry
  • Controlled arbitrary single qubit gates –> Rz, Ry, and CNOT gates

Moreover, it contains LocalOptimizers.

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

linear

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

Returns 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 implemention 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.

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

Remove any MathGates.

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

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 limitions on the choice of gates).

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

Returns 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 implemention 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.
Raises:

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

Returns:

A list of suitable compiler engines.

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

Remove any MathGates.

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

Module contents