libs.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
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]
RevKit support for control function oracles. |
|
RevKit support for permutation oracles. |
|
RevKit support for phase oracles. |
|
Module containing some utility functions |
|
Synthesize a negation controlled by an arbitrary control function. |
|
Synthesize a permutation using RevKit. |
|
|
Synthesize phase circuit from an arbitrary Boolean function. |
Submodules
_control_function
RevKit support for control function oracles.
- class projectq.libs.revkit._control_function.ControlFunctionOracle(function, **kwargs)[source]
Synthesize 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)
_permutation
RevKit support for permutation oracles.
- class projectq.libs.revkit._permutation.PermutationOracle(permutation, **kwargs)[source]
Synthesize 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)
_phase
RevKit support for phase oracles.
- class projectq.libs.revkit._phase.PhaseOracle(function, **kwargs)[source]
Synthesize 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)
_utils
Module containing some utility functions
Module contents
Module containing code to interface with RevKit
- class projectq.libs.revkit.ControlFunctionOracle(function, **kwargs)[source]
Synthesize 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]
Initialize 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
- class projectq.libs.revkit.PermutationOracle(permutation, **kwargs)[source]
Synthesize 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]
Initialize 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]
Synthesize 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]
Initialize 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