Quantum Circuit Optimizer
- Support two types of gate-count reduction methods:
-
- using ZX-calculus
-
- using Phase Polynomial
-
- Implemented in C++ language
- Provide command line tool, C++ library and Python package.
Install the following softwares first.
$ sudo apt install nlohmann-json3-dev
$ sudo apt install graphviz
$ sudo apt install libeigen3-dev
For Python package, need to install the folloing package.
$ pip install nanobind
Install command line tool, C++ library and related hedder files as follows,
$ git clone https://github.com/samn33/sharqit.git
$ mkdir -p ~/lib ~/bin ~/include/sharqit
$ cd sharqit/sharqit/cpp
$ make
$ make install
Add following lines to your ~/.bashrc. (If you are using another shell, replace as appropriate.)
export LD_LIBRARY_PATH="${HOME}/lib:$LD_LIBRARY_PATH"
export PATH="${HOME}/bin:$PATH"
$ pip install sharqit
Or build from source codes (PyPI).
$ pip install --no-binary :all: sharqit
Or dowonload and build from source codes (Github),
$ git clone https://github.com/samn33/sharqit.git
$ cd sharqit
$ python setup.py install --user
$ make uninstall
$ pip uninstall sharqit
Prepare the quantum circuit you want to optimize as follows.
$ cat sample.sqc
T 1
H 0
H 1
CX 0 1
H 0
H 1
T+ 1
You can display the quantum circuit.
$ sharqit --show sample.sqc
q[0] --H-----*--H------
q[1] --T--H--X--H--T+--
Optimize and display the result.
$ sharqit --opt sample.sqc > foo.sqc
$ sharqit --show foo.sqc
q[0] --X--
q[1] --*--
Print help message.
$ sharqit --help
An example of C++ code that uses the sharqit c++ library.
$ cat sample.cpp
#include "sharqit/sharqit.h"
int main()
{
Sharqit::QCirc qc_in;
qc_in.t(1);
qc_in.h(0);
qc_in.h(1);
qc_in.cx(0,1);
qc_in.h(0);
qc_in.h(1);
qc_in.tdg(1);
qc_in.show();
Sharqit::Optimizer opt;
Sharqit::QCirc qc_out = opt.reduce_gates(qc_in, "zx");
qc_out.show();
return 0;
}
Build it.
$ g++ -O4 -std=c++17 -L ~/lib -I ~/include -I /usr/include/eigen3 sample.cpp -lshrqt
Execute a.out.
$ ./a.out
q[0] --H-----*--H------
q[1] --T--H--X--H--T+--
q[0] --X--
q[1] --*--
An example of Python code that uses the sharqit package.
$ cat sample.py
from sharqit import QCirc, Optimizer
qc_in = QCirc()
qc_in.t(1)
qc_in.h(0)
qc_in.h(1)
qc_in.cx(0,1)
qc_in.h(0)
qc_in.h(1)
qc_in.tdg(1)
qc_in.show()
opt = Optimizer()
qc_out = opt.reduce_gates(qc_in, "zx")
qc_out.show()
Execute the code.
$ python sample.py
q[0] --H-----*--H------
q[1] --T--H--X--H--T+--
q[0] --X--
q[1] --*--
Sample code converting from qasm file is here.
Processing time, T-count, 2Q-count, Gate-count of 'sharqit' are compared with PyZX. The 'zx' means the metohd using ZXCalculus, the 'pp' means the method using PhasePolynomial. The operating environment is 13th Gen Intel(R) Core(TM) i7-1355U @5GHz, 16GB RAM.
Quantum circuit data used in the benchmarks are from optimizer: Benchmark quantum circuits before and after optimization.
Papers about T-count reduction using ZX-calculus.
-
Ross Duncan, Aleks Kissinger, Simon Perdrix, John van de Wetering, "Graph-theoretic Simplification of Quantum Circuits with the ZX-calculus", arXiv:1902.03178
-
Aleks Kissinger, John van de Wetering, "Reducing T-count with the ZX-calculus", arXiv:1903.10477
-
Miriam Backens, Hector Miller-Bakewell, Giovanni de Felice, Leo Lobski, John van de Wetering, "There and back again: A circuit extraction tale", arXiv:2003.01664
-
Korbinian Staudacher, "Optimization Approaches for Quantum Circuits using ZX-calculus" Ludwig maximilian university of munich thesis
Papers about gate-count reduction using Phase Polynomial.
- Yunseong Nam, Neil J. Ross, Yuan Su, Andrew M. Childs, Dmitri Maslov, "Automated optimization of large quantum circuits with continuous parameters", arXiv:1710.07345
- Linux (Ubuntu 22.04 LTS)
- Python 3.10
MIT