DVLab-NTU / qsyn

A C++-based growing software system for synthesizing, optimizing, and verifying quantum circuits
Apache License 2.0
168 stars 15 forks source link
quantum quantum-circuit-synthesis quantum-computing quantum-software

license stars contributors release-date pr-welcome g++-11 clang++-16

Qsyn: A Developer-Friendly Quantum Circuit Synthesis Framework for NISQ Era and Beyond

Overview

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:

Getting Started

System Requirements

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.

Installation

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.

Optional Dependencies for Visualization

Visualization functionalities of qsyn depend at runtime on the following dependencies. Please refer to the linked pages for installation instructions of these dependencies:

Compilation

To 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 ```sh sudo apt install libopenblas-dev sudo apt install liblapack-dev ``` If 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`: ```sh make -j8 ``` which triggers our suggested CMake build process. Alternatively, use `make build-g++` or `make build-clang++` to manually specify the compiler.
For MacOS Users Since Qsyn uses some C++20 features that are not yet supported by Apple Clang, you'll need to install another compiler yourself. We recommend installing the `llvm` toolchain with the `brew` package manager. ```sh brew install llvm ``` After installation, `brew` will guide you to configure your environment to use LLVM `clang++` and its associated libraries. You would probably want to install `OpenBLAS` by running ```sh brew install openblas ``` Finally, run the following commands to build `qsyn`: ```sh make -j8 ``` which triggers our suggested CMake build process. Alternatively, use `make build-g++` or `make build-clang++` to manually specify the compiler.
Docker Builds You can also build `qsyn` in a containerized environment by running ```sh make build-docker ``` And run that executable by running ```sh make run-docker ``` Of course, this requires you to have Docker installed on your machine.

Run

Testing

We have provided some test scripts as integrated tests as well as demonstration of use. These scripts are Located under tests/<section>/<subsection>/dof/.

Functionalities

Software architecture

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.

High-level 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

Gate-level Synthesis

qsyn also adapt to different optimization targets by providing different routes to synthesize low-level quantum circuits.

Via ZX-calculus

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

Via Tableau

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

Device Mapping

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

Data Access and Utilities

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

License

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.

Reference

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},
}