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:
ControlFunctionOracle
: Synthesizes a reversible circuit from Boolean control functionPermutationOracle
: Synthesizes a reversible circuit for a permutationPhaseOracle
: Synthesizes phase circuit from an arbitrary Boolean function
Refer to RevKit documentation on how to compile RevKit as a Python module.
Note
The RevKit Python module must be installed in order to use this ProjectQ library.
There exist precompiled binaries for Ubuntu 14.04 (trusty), 16.04 (xenial), and 17.10 (artful). You can install them with:
sudo add-apt-repository ppa:msoeken/ppa
sudo apt-get update
sudo apt-get install cirkit
These must be run with the Python installation from the distribution (either Python 2.x or Python 3.x).
For all other systems, RevKit must be compiled from scratch and the RevKit module must be in the Python module path.
One way to add it is by modifying the PYTHONPATH
environment variable.
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)
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
, or232
.Example
This example creates a circuit that causes to invert qubit
d
, the majority-of-three function evaluates to true for the control qubitsa
,b
, andc
.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 an And-inverter graph and requires no additional ancillae (e.g.,
revkit.esopbs(aig = True)
). Can also be a nullary lambda that calls several RevKit commands. Default: ``lambda: revkit.esopbs(aig = True,exorcism = True)``
-
-
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
orrevkit.dbs
). Can also be a nullary lambda that calls several RevKit commands. Default:revkit.tbs
-
-
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
, or232
.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
, andc
.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 an And-inverter graph and requires no additional ancillae (e.g., revkit.esopps()
). Can also be a nullary lambda that calls several RevKit commands. Default:lambda: revkit.esopps()
-