Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.13k stars 2.35k forks source link

Port XXDecomposer to Rust #12005

Open mtreinish opened 6 months ago

mtreinish commented 6 months ago

In the default 2q unitary synthesis plugin we use the TwoQubitBasisDecomposer and the XXDecomposer based on the target (both the basis and fidelities). To finish #8774 and have a parallel rust implementation of the default synthesis plugin we need to port the XXDecomposer class and likely the entire qiskit/synthesis/two_qubit/xx_decompose subpackage to rust.

mtreinish commented 6 months ago

Now that #12004 has been implemented the XX decomposer is potentially the slowest part of optimization level 3 transpile. I ran a 100 qubit QV with a depth of 30 and generated this profile using main:

Screenshot_2024-03-28_17-23-21

The highlighted section that takes 46.6 seconds is the time spent in the XXDecomposer and it's taking ~50% of the total transpile time.

I generated that profile by running the following under cprofile:

import time
from qiskit import transpile
from qiskit.transpiler import CouplingMap
from qiskit.providers.fake_provider import GenericBackendV2
from qiskit.circuit.library import QuantumVolume

cmap = CouplingMap.from_heavy_hex(19)

backend = GenericBackendV2(len(cmap.graph), coupling_map=cmap, basis_gates=['cx', 'rz', 'sx', 'x', 'id'])

qc = QuantumVolume(100, depth=30)
qc.measure_all()
start = time.perf_counter()
transpile(qc, backend, optimization_level=3)
stop = time.perf_counter()
print(stop - start)
levbishop commented 6 months ago

The xxdecomposer should be sped up, but for that basis set it seems like we shouldn't be calling it at all since the only xx class gate available is cx and the twoqubitbasisdecomposer should be giving optimal decomposition for that already?

mtreinish commented 6 months ago

Hmm, that's a good point let me look at the UnitarySynthesis pass's default plugin and see why it's running the XX decomposer at all. There very likely is a logic bug in the pass for figuring out which decomposer to run in the Target path. The basis_gates list path is very simple it only runs XXDecomposer if rzx is in the basis gates.

levbishop commented 6 months ago

Just in general it would probably be nice UnitarySynthesis would do some logging about what decomposers it's trying and why.