revkit

This library integrates RevKit into ProjectQ to allow some automatic synthesis routines for reversible logic. The library adds the following operations that can be used to construct quantum circuits:

RevKit can be installed from PyPi with pip install revkit.

Note

The RevKit Python module must be installed in order to use this ProjectQ library.

There exist precompiled binaries in PyPi, as well as a source distribution. Note that a C++ compiler with C++17 support is required to build the RevKit python module from source. Examples for compatible compilers are Clang 6.0, GCC 7.3, and GCC 8.1.

The integration of RevKit into ProjectQ and other quantum programming languages is described in the paper

  • Mathias Soeken, Thomas Haener, and Martin Roetteler “Programming Quantum Computers Using Design Automation,” in: Design Automation and Test in Europe (2018) [arXiv:1803.01022]

Module contents

class projectq.libs.revkit.ControlFunctionOracle(function, **kwargs)[source]

Synthesizes a negation controlled by an arbitrary control function.

This creates a circuit for a NOT gate which is controlled by an arbitrary Boolean control function. The control function is provided as integer representation of the function’s truth table in binary notation. For example, for the majority-of-three function, which truth table 11101000, the value for function can be, e.g., 0b11101000, 0xe8, or 232.

Example

This example creates a circuit that causes to invert qubit d, the majority-of-three function evaluates to true for the control qubits a, b, and c.

ControlFunctionOracle(0x8e) | ([a, b, c], d)
__init__(function, **kwargs)[source]

Initializes a control function oracle.

Parameters:function (int) – Function truth table.
Keyword Arguments:
 synth – A RevKit synthesis command which creates a reversible circuit based on a truth table and requires no additional ancillae (e.g., revkit.esopbs). Can also be a nullary lambda that calls several RevKit commands. Default: revkit.esopbs
__or__(qubits)[source]

Applies control function to qubits (and synthesizes circuit).

Parameters:qubits (tuple<Qureg>) – Qubits to which the control function is being applied. The first n qubits are for the controls, the last qubit is for the target qubit.
class projectq.libs.revkit.PermutationOracle(permutation, **kwargs)[source]

Synthesizes a permutation using RevKit.

Given a permutation over 2**q elements (starting from 0), this class helps to automatically find a reversible circuit over q qubits that realizes that permutation.

Example

PermutationOracle([0, 2, 1, 3]) | (a, b)
__init__(permutation, **kwargs)[source]

Initializes a permutation oracle.

Parameters:permutation (list<int>) – Permutation (starting from 0).
Keyword Arguments:
 synth – A RevKit synthesis command which creates a reversible circuit based on a reversible truth table (e.g., revkit.tbs or revkit.dbs). Can also be a nullary lambda that calls several RevKit commands. Default: revkit.tbs
__or__(qubits)[source]

Applies permutation to qubits (and synthesizes circuit).

Parameters:qubits (tuple<Qureg>) – Qubits to which the permutation is being applied.
class projectq.libs.revkit.PhaseOracle(function, **kwargs)[source]

Synthesizes phase circuit from an arbitrary Boolean function.

This creates a phase circuit from a Boolean function. It inverts the phase of all amplitudes for which the function evaluates to 1. The Boolean function is provided as integer representation of the function’s truth table in binary notation. For example, for the majority-of-three function, which truth table 11101000, the value for function can be, e.g., 0b11101000, 0xe8, or 232.

Note that a phase circuit can only accurately be found for a normal function, i.e., a function that maps the input pattern 0, 0, …, 0 to 0. The circuits for a function and its inverse are the same.

Example

This example creates a phase circuit based on the majority-of-three function on qubits a, b, and c.

PhaseOracle(0x8e) | (a, b, c)
__init__(function, **kwargs)[source]

Initializes a phase oracle.

Parameters:function (int) – Function truth table.
Keyword Arguments:
 synth – A RevKit synthesis command which creates a reversible circuit based on a truth table and requires no additional ancillae (e.g., revkit.esopps). Can also be a nullary lambda that calls several RevKit commands. Default: revkit.esopps
__or__(qubits)[source]

Applies phase circuit to qubits (and synthesizes circuit).

Parameters:qubits (tuple<Qureg>) – Qubits to which the phase circuit is being applied.