Skip to main content

QCEC - A JKQ tool for Quantum Circuit Equivalence Checking

Project description

PyPI GitHub Workflow Status Codecov branch GitHub toolset: JKQ arXiv arXiv arXiv

QCEC - A JKQ tool for Quantum Circuit Equivalence Checking

A JKQ tool for Quantum Circuit Equivalence Checking by the Institute for Integrated Circuits at the Johannes Kepler University Linz based on methods proposed in [1], [2], [3].

[1] L. Burgholzer and R. Wille. "Advanced Equivalence Checking for Quantum Circuits". IEEE Transactions on Computer Aided Design of Integrated Circuits and Systems (TCAD), 2021 (pre-print arXiv:2004.08420)

[2] L. Burgholzer, R. Raymond, and R. Wille. "Verifying Results of the IBM Qiskit Quantum Circuit Compilation Flow". In International Conference on Quantum Computing and Engineering (QCE), 2020 (pre-print arXiv:2009.02376)

[3] L. Burgholzer, R. Kueng, and R. Wille. "Random Stimuli Generation for the Verification of Quantum Circuits". In Asia and South Pacific Design Automation Conference (ASP-DAC), 2021 (pre-print arxiv:2011.07288)

This tool can be used for checking the equivalence of two quantum circuits provided in any of the following formats:

with the following available methods:

  • Reference - Construct and compare the DD for both circuits [1, Section III.B],
  • G \rightarrow \mathbb{I} \leftarrow G' - Starting from the identity I, either apply gates from G or (inverted) gates from G' according to one of the following strategies [1, Section IV.A]:
    • Naive - Alternate between applications of G and G' [1, Section V.A],
    • Proportional - Proportionally apply gates according to the gate count ratio of G and G' [1, Section V.B],
    • Lookahead - Always apply the gate yielding the smaller DD [1, Section V.C],
  • Simulation - Conduct simulation runs to prove non-equivalence or give a strong indication of equivalence [1, Section IV.B] using:
  • Verification of compilation results - A dedicated scheme for verifying results of the IBM Qiskit Compilation Flow explicitly exploiting certain knowledge about the compilation process. [2]

The tool builds upon our decision diagram (DD) package as well as our quantum functionality representation (QFR). For more information, please visit iic.jku.at/eda/research/quantum_verification. If you want to visually explore decision diagrams for quantum computing, check out our installation-free web-tool JKQ DDVis.

If you have any questions, feel free to contact us via iic-quantum@jku.at or by creating an issue on GitHub.

Usage

JKQ QCEC is mainly developed as a C++ library with a commandline interface. However, using it in Python is as easy as

pip install jkq.qcec

and then in Python

from jkq import qcec
qcec.verify(circ1, circ2,  **kwargs)

where the verify function is defined as follows:

"""
Interface to the JKQ QCEC tool for verifying quantum circuits

Params:
    circ1 – Qiskit QuantumCircuit object, path to circuit file or Qiskit QuantumCircuit pickle (required)
    circ2 – Qiskit QuantumCircuit object, path to circuit file or Qiskit QuantumCircuit pickle (required)
    method – Equivalence checking method to use (reference | naive | *proportional* | lookahead | simulation | compilationflow)
    tolerance – Numerical tolerance used during computation
    nsims – Number of simulations to conduct (for simulation method)
    fidelity – Fidelity limit for comparison (for simulation method)
    stimuliType - Type of stimuli to use (for simulation method: *classical* | localquantum | globalquantum)
    csv – Create CSV string for result
    statistics – Print statistics
    storeCEXinput: Store counterexample input state vector (for simulation method)
    storeCEXoutput: Store resulting counterexample state vectors (for simulation method)
    swapGateFusion – Optimization pass reconstructing SWAP operations
    singleQubitGateFusion – Optimization pass fusing consecutive single qubit gates
    removeDiagonalGatesBeforeMeasure – Optimization pass removing diagonal gates before measurements
Returns:
    JSON object containing results
"""
def verify(circ1, circ2,
           method: Method = Method.proportional,
           tolerance: float = 1e-13,
           nsims: int = 16,
           fidelity: float = 0.999,
           stimuliType: StimuliType = StimuliType.classical,
           csv: bool = False,
           statistics: bool = False,
           storeCEXinput: bool = False,
           storeCEXoutput: bool = False,
           swapGateFusion: bool = False,
           singleQubitGateFusion: bool = False,
           removeDiagonalGatesBeforeMeasure: bool = False) -> object

Integration of IBM Qiskit

The JKQ QCEC tool is designed to natively integrate with IBM Qiskit. In particular, using our tool to verify, e.g., the results of IBM Qiskit's quantum circuit compilation flow, is as easy as:

from jkq import qcec
from qiskit import QuantumCircuit, transpile

# create your quantum circuit
qc = <...> 

# append measurements to save output mapping of physical to logical (qu)bits
qc.measure_all() 

# compile circuit to appropriate backend using some optimization level
qc_comp = transpile(qc, backend=<...>, optimization_level=<0 | 1 | 2 | 3>) 

# verify the compilation result
qcec.verify(qc, qc_comp, method=qcec.Method.compilationflow, statistics=True)

Command-line Executable

JKQ QCEC also provides a standalone executable with command-line interface called qcec_app. It provides the same options as the Python module as flags (e.g., --ps for printing statistics, or --method <method>for setting the method). Per default, this produces JSON formatted output. If the --csv flag is present, a CSV entry according to the following header is printed

filename1;nqubits1;ngates1;filename2;nqubits2;ngates2;expectedEquivalent;equivalent;method;time;maxActive;nsims

For a full list of options, call qcec_app --help.

Library Organisation

Internally the JKQ QCEC library works in the following way

  • Import both input files into a qc::QuantumComputation object
    std::string file1 = "<PATH_TO_FILE_1>";
    qc::QuantumComputation qc1(file1);
    
    std::string file2 = "<PATH_TO_FILE_2>";
    qc::QuantumComputation qc2(file2);
    
  • Instantiate an ec::EquivalenceChecker object with both circuits
    ec::Method method = ec::{ Reference | Naive | Proportional | Lookahead };
    auto eq = ec::ImprovedDDEquivalenceChecker(qc1, qc2, method);
    
    or
    auto eq = ec::PowerOfSimulationEquivalenceChecker(qc1, qc2);
    
    or
    auto eq = ec::CompilationFlowEquivalenceChecker(qc1, qc2);
    
  • Set configuration options, e.g.,
    ec::Configuration config{};
    config.printStatistics = true;
    
  • Perform the actual equivalence check
    eq.check(config);
    
  • Print the results
    ec.printJSONResult(config.printStatistics);
    
    or access them through the eq.results member.

System requirements

Building (and running) is continuously tested under Linux, MacOS, and Windows using the latest available system versions for GitHub Actions. However, the implementation should be compatible with any current C++ compiler supporting C++17 and a minimum CMake version of 3.13.

Setup, Configure, and Build

To start off, clone this repository using

git clone --recurse-submodules -j8 https://github.com/iic-jku/qcec 

Note the --recurse-submodules flag. It is required to also clone all the required submodules. If you happen to forget passing the flag on your initial clone, you can initialize all the submodules by executing git submodule update --init --recursive in the main project directory.

Our projects use CMake as the main build configuration tool. Building a project using CMake is a two-stage process. First, CMake needs to be configured by calling

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release

This tells CMake to search the current directory . (passed via -S) for a CMakeLists.txt file and process it into a directory build (passed via -B). The flag -DCMAKE_BUILD_TYPE=Release tells CMake to configure a Release build (as opposed to, e.g., a Debug build).

After configuring with CMake, the project can be built by calling

 cmake --build build --config Release

This tries to build the project in the build directory (passed via --build). Some operating systems and developer environments explicitly require a configuration to be set, which is why the --config flag is also passed to the build command. The flag --parallel <NUMBER_OF_THREADS> may be added to trigger a parallel build.

Building the project this way generates

  • the main library libqcec.a (Unix) / qcec.lib (Windows) in the build/src directory
  • the commandline executables qcec_app and qcec_sim_app (for simulation-based verification) in the build/apps directory
  • a test executable qcec_test containing a small set of unit tests in the build/test directory (only if -DBUILD_QCEC_TESTS=ON is passed to CMake during configuration)
  • a small demo example executable qcec_example in the build/test directory (only if -DBUILD_QCEC_TESTS=ON is passed to CMake during configuration)

Reference

If you use our tool for your research, we will be thankful if you refer to it by citing the appropriate publication:

[1] L. Burgholzer and R. Wille. "Advanced Equivalence Checking for Quantum Circuits". IEEE Trans. on CAD of Integrated Circuits and Systems (TCAD), 2021
@article{burgholzer2021advanced,
    author = {Burgholzer, Lukas and Wille, Robert},
    title = {Advanced Equivalence Checking for Quantum Circuits},
    journaltitle = {{IEEE} Transactions on {CAD} of Integrated Circuits and Systems},
    year = {2021}
}
[2] L. Burgholzer, R. Raymond, and R. Wille. "Verifying Results of the IBM Qiskit Quantum Circuit Compilation Flow". In International Conference on Quantum Computing and Engineering (QCE), 2020
@inproceedings{burgholzer2020verifyingResultsIBM,
  title = {Verifying results of the {{IBM Qiskit}} quantum circuit compilation flow},
  booktitle = {International Conference on Quantum Computing and Engineering},
  author = {Burgholzer, Lukas and Raymond, Rudy and Wille, Robert},
  year = {2020}
}
[3] L. Burgholzer, R. Kueng, and R. Wille. "Random Stimuli Generation for the Verification of Quantum Circuits". Asia and South Pacific Design Automation Conference (ASP-DAC), 2021
@inproceedings{burgholzer2021randomStimuliGenerationQuantum,
  title = {Random stimuli generation for the verification of quantum circuits},
  booktitle = {Asia and South Pacific Design Automation Conference},
  author = {Burgholzer, Lukas and Richard, Kueng and Wille, Robert},
  year = {2021}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jkq.qcec-1.7.3.tar.gz (7.7 MB view hashes)

Uploaded Source

Built Distributions

jkq.qcec-1.7.3-cp39-cp39-win_amd64.whl (606.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

jkq.qcec-1.7.3-cp39-cp39-manylinux2014_x86_64.whl (425.5 kB view hashes)

Uploaded CPython 3.9

jkq.qcec-1.7.3-cp39-cp39-macosx_10_9_x86_64.whl (382.1 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

jkq.qcec-1.7.3-cp38-cp38-win_amd64.whl (606.1 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

jkq.qcec-1.7.3-cp38-cp38-manylinux2014_x86_64.whl (425.4 kB view hashes)

Uploaded CPython 3.8

jkq.qcec-1.7.3-cp38-cp38-macosx_10_9_x86_64.whl (382.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

jkq.qcec-1.7.3-cp37-cp37m-win_amd64.whl (610.9 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

jkq.qcec-1.7.3-cp37-cp37m-manylinux2014_x86_64.whl (430.2 kB view hashes)

Uploaded CPython 3.7m

jkq.qcec-1.7.3-cp37-cp37m-macosx_10_9_x86_64.whl (379.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

jkq.qcec-1.7.3-cp36-cp36m-win_amd64.whl (610.8 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

jkq.qcec-1.7.3-cp36-cp36m-manylinux2014_x86_64.whl (430.0 kB view hashes)

Uploaded CPython 3.6m

jkq.qcec-1.7.3-cp36-cp36m-macosx_10_9_x86_64.whl (379.3 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page