cda-tum / mqt-qcec

MQT QCEC - A tool for Quantum Circuit Equivalence Checking
https://mqt.readthedocs.io/projects/qcec
MIT License
90 stars 20 forks source link

Python interface #2

Closed yourball closed 3 years ago

yourball commented 3 years ago

Hi,

I was wondering if it is possible to add a Python interface for your project? That would be very helpful for the platform I'm working on (Arline Benchmarks, automated benchmarking for quantum compilers, https://github.com/ArlineQ/arline_benchmarks). Also it would be super helpful for a broad audience of quantum researchers and developers.

Me and my team looked into that, there are some automatic python wrappers for C++ code such as pybind11, SWIG. Did you guys consider something like that?

Thanks!

burgholzer commented 3 years ago

Hi,

I just pushed a new update which contains Python bindings for the tool. you should be able to install them using pip. See the updated README for the available options.

Let me know if this works for you, or if you encountered any problems.

yourball commented 3 years ago

Hi, thanks a lot for doing this!

Just a side question. Do I understand correctly that two circuits which are different by a diagonal gate just before the measurements will be interpreted as non-equivalent? Say, two circuits like:

qc1: X q[0]; measure q[0] -> c[0];

and qc2: X q[0]; Z q[0]; measure q[0] -> c[0];

Qiskit has a RemoveDiagnoalBeforeMeasure subroutine as a part of transpiler

burgholzer commented 3 years ago

Hi,

you're welcome. I am currently working on making the Python package available through PyPi so it is even easier to incorporate.

On your question: That’s correct. Technically the two circuits do not represent the same unitary functionality. Although you are right, that these two circuits behave the same upon measurement.

I could implement an (optional) optimization pass for our tool which mimics Qiskit’s transpiler pass. Would that help?

yourball commented 3 years ago

Cool, pypi indeed would be an ideal option.

Yeah, if you could implement such an optional pass, it would be great!

burgholzer commented 3 years ago

Would you mind creating a separate issue for this in order to keep everything self-contained?

burgholzer commented 3 years ago

JKQ QCEC is now available via PyPI πŸ˜ƒ

pip install jkq.qcec

It can then be used in Python via

from jkq import qcec
qcec.verify(...)

where the verify function is defined as follows:

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

Params:
    file1 – Path to first file (required)
    file2 – Path to second file (required)
    method – Equivalence checking method to use (reference | naive | *proportional* | lookahead | simulation | compilation flow)
    tolerance – Numerical tolerance used during computation
    nsims – Number of simulations to conduct (for simulation method)
    fidelity – Fidelity limit for comparison (for simulation method)
    csv – Create CSV string for result
    statistics – Print statistics
    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(file1: Union[str, bytes, PathLike],
            file2: Union[str, bytes, PathLike],
            method: Method = Method.proportional,
            tolerance: float = 1e-13,
            nsims: int = 16,
            fidelity: float = 0.999,
            csv: bool = False,
            statistics: bool = False,
            swapGateFusion: bool = False,
            singleQubitGateFusion: bool = False,
            removeDiagonalGatesBeforeMeasure: bool = False) -> object