基于 C++ 的一种不断发展的软件系统,用于合成、优化和验证量子电路
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:
cmake --version; upgrade via your package manager (e.g. brew install cmake on macOS, or install from cmake.org).Clone the repository to your local machine by running
git clone https://github.com/DVLab-NTU/qsyn.git
cd qsynThen, 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:latestif 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 circuitstexlive for drawing ZX-diagrams.sudo apt-get install texlive-latex-base texlive-latex-extraTo build qsyn, follow the instructions below:
For Linux Users
You'll probably need to install OpenBLAS and LAPACK libraries. For Ubuntu, you can install them by running
sudo apt install libopenblas-dev
sudo apt install liblapack-devIf you are tech-savvy enough to be using a different Linux distribution, we're confident that you can figure out how to install these libraries
Then, run the following commands to build qsyn:
make -j8This uses the default compiler (gcc/g++) and triggers the CMake build. To override the compiler, set CC and CXX in the environment or in a local override file (see Local overrides below).
For MacOS Users
Since Qsyn uses C++20 features not fully supported by Apple Clang, install a C++20-capable compiler. Options:
LLVM (clang++) via Homebrew:
brew install llvmAfter installation, follow brew’s instructions to use LLVM’s clang++ (e.g. add its bin to PATH).
Note: Use
llvm@18on some device may work. The unversionedllvmformula installs the latest LLVM (currently 20+), which has a knownconsteval/FMT_STRINGincompatibility that causes build failures with thefmtversion used by qsyn.
GCC via Homebrew (recommended if you see fmt/consteval or similar build errors with LLVM):
brew install gccThen use GCC for the build by creating a .env.local (see Local overrides below) with:
CC := $(shell brew --prefix gcc)/bin/gcc-15
CXX := $(shell brew --prefix gcc)/bin/g++-15(Replace 15 with your installed GCC version if different.)
Install OpenBLAS:
brew install openblasThen build:
make -j8Local overrides (.env.local)
To keep machine-specific settings (e.g. compiler path) out of the repo, you can use an optional .env.local file at the project root. The Makefile will include it only if the file exists; it is ignored by git (see .gitignore).
Use it to override CC, CXX, or other variables used by the build. Copy the example and edit as needed:
cp .env.local.example .env.local
# edit .env.local (e.g. set CC and CXX for your compiler)Example .env.local (Makefile syntax; use := for your paths):
# Optional: override compilers (e.g. for macOS with Homebrew GCC)
CC := /opt/homebrew/bin/gcc-15
CXX := /opt/homebrew/bin/g++-15Then run make -j8 as usual; the build will use these values.
Docker Builds
You can run qsyn without building (Docker image has a pre-built binary):
docker run -it --rm dvlab/qsyn:latestTo build qsyn inside a container on your machine:
make build-docker
make run-dockerThis requires Docker and uses the image defined in docker/dev.Dockerfile. Note: the image must provide CMake ≥ 3.29; if make build-docker fails with a CMake version error, the base image may need to be updated.
After successful compilation, run ./qsyn and enter Qsyn's command-line interface:
./qsyn
qsyn v0.8.1 - 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> helpTo see the help message of a specific command, type -h or --help.
qsyn> qcir read -hYou can also let qsyn to execute a sequence of commands by passing a script to qsyn:
./qsyn -v examples/synth.dof
qsyn v0.8.1 - 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 --statTo 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.qasmThis 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 -hWe have provided some test scripts as integrated tests as well as demonstration of use. These scripts are Located under tests///dof/.
To run a test script and compare the result to the reference, type
./scripts/RUN_TESTS -dTo update the reference to a test script, type
./scripts/RUN_TESTS -uYou may also run all test scripts by running
make testTo run test in a containerized environment, run
make test-dockerNotice 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 `` 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. `` stands for any data representation type, including quantum circuits, ZX diagrams, Tableau, etc.
| Command | Description |
|---|---|
| `` list | list all ``s |
| `` checkout |
暂无开放 Issues,或尚未同步最近议题。