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.11k stars 2.34k forks source link

Reduce cost of `DAGCircuit.input_map` and `output_map` accesses #13023

Open jakelishman opened 1 month ago

jakelishman commented 1 month ago
          This recreates the entire dict (which could be 100s of qubits + clbits) on every lookup.

I actually expected it to have more of an impact on transpiler performance, but it seems like we only have a couple of transpiler passes that touch them - the disjoint utils and the "remove final X" passes. I think those are sufficient non-critical we can ignore it for this first PR, but it's definitely a performance pitfall we should rectify for user passes.

_Originally posted by @jakelishman in https://github.com/Qiskit/qiskit/pull/12550#discussion_r1717036989_

At the moment, the Rust-space input_map and output_map properties recreate Python dictionaries on every access, meaning operations like [dag.input_map[qubit] for qubit in dag.qubits] have suddenly become quadratic in the number of qubits, rather than linear. This doesn't bite us too much in practice in the transpiler immediately, but it's absolutely a performance pitfall waiting to happen in the current structure.