forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add merging of
Interner
s (Qiskit#13752)
* Add merging of `Interner` instances This makes it possible to merge one interner into another, using a map-and-filter function to explain how the values should be considered afterwards. The main use-case for this is in DAG and circuit substitution methods, where we want to be able to map `PackedInstruction`s from a small circuit to new ones on a larger circuit, without having to unwrap and re-hash the interned slices once for instruction; instead, we do that once _per interner key_, and then have a no-hash direct lookup table to remap the interner keys directly. The methods here are designed to directly allow the reuse of the heap allocations used to track the interner key mappings, to help reduce the number of small-scale allocations done in substitution methods. The filtering part of the mapping is because one cannot typically be certain that an `Interner` contains the minimally necessary keys, especially for DAGs; it can well be that substitutions and bit removals cause old data to be present. * Use new `Interner` merging in `DAGCircuit::from_circuit` This converts one obvious candidate for the new interner-merging functionality. There are several others in the codebase (all uses of `DAGCircuit::extend`, for example, and several other full rebuilds), but the structure of their code wasn't designed with this in mind, so the modifications would typically be far more involved and more suitable for separate patches. Using a timing script: ```python import itertools from qiskit.circuit import QuantumCircuit from qiskit.converters import circuit_to_dag qc = QuantumCircuit(100, 100) for pair in itertools.permutations(qc.qubits, 2): qc.rz(0, pair[0]) qc.sx(pair[0]) qc.rz(0, pair[0]) qc.rz(0, pair[1]) qc.sx(pair[1]) qc.rz(0, pair[1]) qc.cx(*pair) %timeit circuit_to_dag(qc, copy_operations=False) ``` this patch showed an improvement from 18.5(6)ms to 14.4(5)ms on my machine, which is a 22% speedup, though admittedly this particular function was doing larger-scale allocation work that could be removed than other candidate replacements are. * Fix typo Co-authored-by: Kevin Hartman <[email protected]> * Fix typos Co-authored-by: Raynel Sanchez <[email protected]> --------- Co-authored-by: Kevin Hartman <[email protected]> Co-authored-by: Raynel Sanchez <[email protected]>
- Loading branch information
1 parent
3c805dd
commit 315d6ad
Showing
3 changed files
with
593 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.