cda-tum / mqt-qcec

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

🐛 fix ZX-checker inadvertedly terminating early #382

Closed burgholzer closed 3 months ago

burgholzer commented 3 months ago

Description

While experimenting on some benchmarks, it turned out that, sometimes, the ZX checker would just stop simplification even though further simplifications were possible. This PR adresses the underlying bug by revamping and simplifying the handling of the stopping criterion during ZX simplification.

A (not necessarily minimal) reproducer for the bug is:

from mqt.bench import CompilerSettings, QiskitSettings, get_benchmark
from mqt.qcec import verify_compilation

alg = "ae"
num_qubits = 7

# construct the first circuit
qc1 = get_benchmark(alg, circuit_size=num_qubits, level="alg")

# construct the second circuit
optimization_level = 2
settings = CompilerSettings(qiskit=QiskitSettings(optimization_level=2))
qc2 = get_benchmark(alg, circuit_size=num_qubits, level="nativegates", compiler_settings=settings)

    # verify the compilation only using the ZX checker
result2 = verify_compilation(
    qc1,
    qc2,
    optimization_level=optimization_level,
    run_alternating_checker=False,
    run_zx_checker=True,
    run_simulation_checker=False,
)
print(f"ZX-Checker \t|\t {result2.considered_equivalent()} \t|\t {result2.check_time}")

Checklist:

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.4%. Comparing base (e45f80f) to head (d6c6c46).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/cda-tum/mqt-qcec/pull/382/graphs/tree.svg?width=650&height=150&src=pr&token=eKL7Ya7iep&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum)](https://app.codecov.io/gh/cda-tum/mqt-qcec/pull/382?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) ```diff @@ Coverage Diff @@ ## main #382 +/- ## ======================================= - Coverage 96.4% 96.4% -0.1% ======================================= Files 34 34 Lines 1765 1759 -6 Branches 218 222 +4 ======================================= - Hits 1703 1697 -6 Misses 62 62 ``` | [Flag](https://app.codecov.io/gh/cda-tum/mqt-qcec/pull/382/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | Coverage Δ | | |---|---|---| | [cpp](https://app.codecov.io/gh/cda-tum/mqt-qcec/pull/382/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | `96.2% <100.0%> (-0.1%)` | :arrow_down: | | [python](https://app.codecov.io/gh/cda-tum/mqt-qcec/pull/382/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | `97.2% <ø> (ø)` | | | [Files](https://app.codecov.io/gh/cda-tum/mqt-qcec/pull/382?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | Coverage Δ | | |---|---|---| | [include/checker/zx/ZXChecker.hpp](https://app.codecov.io/gh/cda-tum/mqt-qcec/pull/382?src=pr&el=tree&filepath=include%2Fchecker%2Fzx%2FZXChecker.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9jaGVja2VyL3p4L1pYQ2hlY2tlci5ocHA=) | `100.0% <100.0%> (ø)` | | | [src/checker/zx/ZXChecker.cpp](https://app.codecov.io/gh/cda-tum/mqt-qcec/pull/382?src=pr&el=tree&filepath=src%2Fchecker%2Fzx%2FZXChecker.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-c3JjL2NoZWNrZXIvengvWlhDaGVja2VyLmNwcA==) | `100.0% <100.0%> (+0.6%)` | :arrow_up: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/cda-tum/mqt-qcec/pull/382/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum)