cda-tum / mqt-qmap

MQT QMAP - A tool for Quantum Circuit Mapping written in C++
https://mqt.readthedocs.io/projects/qmap
MIT License
99 stars 26 forks source link

ValueError: Error during mapping: Circuit contains gates with more than one control. Please make sure that the input circuit's gates are decomposed to the appropriate gate set! #263

Open YongsooHWANG opened 1 year ago

YongsooHWANG commented 1 year ago

mqt.qmap version

mqt.qmap == 2.1.2

OS

ubuntu

Python version

3.8

C++ compiler

No response

Additional environment information

No response

Description

For some benchmark algorithms, the following error happens.

qc_mapped, res = qmap.compile(qc, arch, method="exact") File "/home/user/anaconda3/lib/python3.8/site-packages/mqt/qmap/compile.py", line 138, in compile results = map(circ, architecture, config) ValueError: Error during mapping: Circuit contains gates with more than one control. Please make sure that the input circuit's gates are decomposed to the appropriate gate set!

Screen Shot 2023-03-15 at 4 16 04 PM

Expected behavior

No response

How to Reproduce

from mqt import qmap, bench from qiskit.providers.fake_provider import FakeNairobi

arch = FakeNairobi() qc = bench.get_benchmark(benchmark_name="qft", circuit_size=7, level="indep")

qc_mapped, res = qmap.compile(qc, arch, method="exact")

burgholzer commented 1 year ago

Hey 👋🏼

Thanks for submitting this bug report. The cause for the exception is the (currently) underlying assumption of QMAP that the input circuit only consists of arbitrary single-qubit gates and CNOT gates, i.e., that the only supported two-qubit gate is the CNOT. While the code doesn't complain currently, when another controlled-rotation gate is used in the circuit (such as a cs gate), it does throw an exception if a two-target gate is encountered. This is precisely what happens above in case of the QFT circuit, which contains SWAP operations at the very end.

There is an ongoing development in #235 for supporting arbitrary two-qubit gates. Once that is in, this example should work out-of-the-box. So I'll close this issue once #235 is merged.

For the moment, a possible workaround is to explicitly decompose the input circuit to basis gates, e.g., via

from mqt import qmap, bench
from qiskit.providers.fake_provider import FakeNairobi
from qiskit import transpile

arch = FakeNairobi()
qc = bench.get_benchmark(benchmark_name="qft", circuit_size=7, level="indep")
qc_basis_gates = transpile(qc, basis_gates=arch.configuration().basis_gates)
qc_mapped, res = qmap.compile(qc_basis_gates, arch, method="exact")

Note, however, that decomposition will most likely introduce further CNOT gates and increase the depth of the circuit, which makes the subsequent mapping problem harder/more complex. As a result, this can only be considered a temporary workaround that does not reflect the real performance.