Qsyn is a developer-friendly C++
-based Quantum Circuit Compilation framework to aid further development in this field. The main contributions of Qsyn are:
Some of the future work for Qsyn includes:
qsyn
requires c++-20
to build. We support compilation with (1) g++-11
or above or (2) clang++-16
or above. We regularly perform build tests for the two compilers.
Clone the repository to your local machine by running
git clone https://github.com/DVLab-NTU/qsyn.git
cd qsyn
Then, follow the instructions below to install the dependencies and build qsyn
.
Alternatively, you can try out qsyn
in a containerized environment by running
docker run -it --rm dvlab/qsyn:latest
if you have Docker installed on your machine.
Visualization functionalities of qsyn
depend at runtime on the following dependencies. Please refer to the linked pages for installation instructions of these dependencies:
qiskit
, qiskit[visualization]
for drawing quantum circuits
texlive
for drawing ZX-diagrams.
sudo apt-get install texlive-latex-base texlive-latex-extra
To build qsyn
, follow the instructions below:
After successful compilation, run ./qsyn
and enter Qsyn's command-line interface:
./qsyn
qsyn v0.7.0 - Copyright © 2022-2024, DVLab NTUEE.
Licensed under Apache 2.0 License. Release build.
qsyn>
To see what commands are available, type help
in the command-line interface.
qsyn> help
To see the help message of a specific command, type <command> -h
or <command> --help
.
qsyn> qcir read -h
You can also let qsyn
to execute a sequence of commands by passing a script to qsyn
:
./qsyn -v examples/synth.dof
qsyn v0.7.0 - Copyright © 2022-2024, DVLab NTUEE.
Licensed under Apache 2.0 License. Release build.
qsyn> qcir read benchmark/SABRE/large/adr4_197.qasm
# further executing commands...
Some example scripts are provided under examples/
. You can also write your own scripts to automate your workflow.
qsyn
also supports reading commands from scripts. For example, we also provided a ZX-calculus-based optimization flow
by executing the following script in the project folder examples/zxopt.qsyn
:
//!ARGS INPUT
qcir read ${INPUT}
echo "--- pre-optimization ---"
qcir print --stat
// to zx -> full reduction -> extract qcir
qc2zx; zx optimize --full; zx2qc
// post-resyn optimization
qcir optimize
echo "--- post-optimization ---"
qcir print --stat
To run the commands in the above file, supply the script’s file path and arguments after ./qsyn :
./qsyn examples/zxopt.qsyn benchmark/SABRE/large/adr4_197.qasm
This runs the ZX-calculus-based synthesis on the circuit in benchmark/SABRE/large/adr4_197.qasm
.
If you're using qsyn
for the first time, a config file will be created under ~/.config/qsynrc
and can be used to store your aliases, variables, etc. If you lost this file, you can use the command create-qsynrc
to recreate it.
For more options, please refer to the help message of qsyn
by running
./qsyn -h
We have provided some test scripts as integrated tests as well as demonstration of use. These scripts are Located under tests/<section>/<subsection>/dof/
.
To run a test script and compare the result to the reference, type
./scripts/RUN_TESTS <path/to/test> -d
To update the reference to a test script, type
./scripts/RUN_TESTS <path/to/test> -u
You may also run all test scripts by running
make test
To run test in a containerized environment, run
make test-docker
Notice that if you use a different BLAS or LAPACK implementation to build qsyn
, be expect that some of the test scripts may produce different results.
The core interaction with qsyn
is facilitated through its command-line interface (CLI), which processes user input, handles command execution, and manages error reporting. Developers can add additional commands and integrate into the CLI. New strategy can be added without compromising to existing data structure, as all modifications are funneled through well-defined public interfaces.
qsyn
supports real time storage of multiple quantum circuits and intermediate representations by the <dt>
checkout command. Users can take snapshots at any time in the synthesis process and switch to an arbitrary version of stored data.
This architecture is central to qsyn’s flexibility and extensibility. It segregates responsibilities and simplifies command implementations while enhancing its capability as a research tool in quantum circuit synthesis.
qsyn
can process various specifications for quantum circuits by supporting syntheses from Boolean oracles and unitary matrices.
Command | Description |
---|---|
qcir oracle | ROS Boolean oracle synthesis flow |
convert ts qc | Gray-code unitary matrix synthesis |
qsyn
also adapt to different optimization targets by providing different routes to synthesize low-level quantum circuits.
Command | Description |
---|---|
qzq | ZX-calculus-based synth routine |
convert qc zx | convert quantum circuit to ZX-diagram |
zx opt | fully reduce ZX diagram |
convert zx qc | convert ZX-diagram to quantum circuit |
qc opt | basic optimization passes |
Command | Description |
---|---|
qtablq | tableau-based synth routine |
convert qc tabl | convert quantum circuit to tableau |
tabl opt full | iteratively apply the following three |
tabl opt tmerge | phase-merging optimization |
tabl opt hopt | internal H-gate optimization |
tabl opt ph todd | TODD optimization |
convert tabl qc | convert tableau to quantum circuit |
qsyn can target a wide variety of quantum devices by addressing their available gate sets and topological constraints. |
Command | Description |
---|---|---|
device read | read info about a quantum device | |
qc translate | library-based technology mapping | |
qc opt -t | technology-aware optimization passes | |
duostra | Duostra qubit mapping for depth or #SWAPs |
qsyn provides various data representations for quantum logic. <dt> stands for any data representation type, including quantum circuits, ZX diagrams, Tableau, etc. |
Command | Description |
---|---|---|
<dt> list |
list all <dt> s |
|
<dt> checkout |
switch focus between <dt> s |
|
<dt> print |
print <dt> information |
|
<dt> <new | delete> |
add a new/delete a <dt> |
|
<dt> <read | write> |
read and write <dt> |
|
<dt> equiv |
verify equivalence of two <dt> s |
|
<dt> draw |
render visualization of <dt> |
|
convert <dt1> <dt2> |
convert from <dt1> to <dt2> |
There are also some extra utilities: | Command | Description |
---|---|---|
alias | set or unset aliases | |
help | display helps to commands | |
history | show or export command history | |
logger | control log levels | |
set | set or unset variables | |
usage | show time/memory usage |
qsyn
is licensed under the
Apache License 2.0.
Certain functions of qsyn
is enabled by a series of third-party libraries. For a list of these libraries, as well as their license information, please refer to this document.
If you are using Qsyn for your research, it will be greatly appreciated if you cite this publication:
@misc{Lau_Qsyn_2024,
Author = {Mu-Te Lau and Chin-Yi Cheng and Cheng-Hua Lu and Chia-Hsu Chuang and Yi-Hsiang Kuo and Hsiang-Chun Yang and Chien-Tung Kuo and Hsin-Yu Chen and Chen-Ying Tung and Cheng-En Tsai and Guan-Hao Chen and Leng-Kai Lin and Ching-Huan Wang and Tzu-Hsu Wang and Chung-Yang Ric Huang},
Title = {Qsyn: A Developer-Friendly Quantum Circuit Synthesis Framework for NISQ Era and Beyond},
Year = {2024},
Eprint = {arXiv:2405.07197},
}