Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix performance issue in parsing bit indices in QPY #11944

Merged
merged 4 commits into from
Mar 4, 2024

Conversation

mtreinish
Copy link
Member

Summary

This commit fixes a performance issue in the deserialization of QPY payloads. Previously when parsing every instruction the deserialization would build up a dictionary of indices to bits so that when we load the bit index in the qargs and cargs for each instruction. This mean the worst case scaling of this section was O(n * m) for n instructions and m bits, which for very large circuits could end up dominating the time spent in deserialization. However, this was unnecessary work because it is rebuilding a mapping from index to bit as a dictionary, but that mapping already existed in the bit lists the circuit is carrying around. This commit fixes the performance issue by removing the dictionary generation and just using the bit lists directly.

Details and comments

This commit fixes a performance issue in the deserialization of QPY
payloads. Previously when parsing every instruction the deserialization
would build up a dictionary of indices to bits so that when we load the
bit index in the qargs and cargs for each instruction. This mean the
worst case scaling of this section was O(n * m) for n instructions and
m bits, which for very large circuits could end up dominating the time
spent in deserialization. However, this was unecessary work because it
is rebuilding a mapping from index to bit as a dictionary, but that
mapping already existed in the bit lists the circuit is carrying around.
This commit fixes the performance issue by removing the dictionary
generation and just using the bit lists directly.
@mtreinish mtreinish added stable backport potential The bug might be minimal and/or import enough to be port to stable performance Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qpy Related to QPY serialization labels Mar 4, 2024
@mtreinish mtreinish added this to the 1.0.2 milestone Mar 4, 2024
@mtreinish mtreinish requested a review from a team as a code owner March 4, 2024 15:52
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @mtreinish
  • @nkanazawa1989

@coveralls
Copy link

coveralls commented Mar 4, 2024

Pull Request Test Coverage Report for Build 8143454235

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 9 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.008%) to 89.302%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 3 90.93%
crates/qasm2/src/parse.rs 6 97.15%
Totals Coverage Status
Change from base Build 8143436750: 0.008%
Covered Lines: 59118
Relevant Lines: 66200

💛 - Coveralls

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly there's an argument for reducing the number of calls to the QuantumCircuit.qubits property getter (since that goes via CircuitData::qubits), but that's probably very small potatoes at best.

@jakelishman jakelishman enabled auto-merge March 4, 2024 16:21
@jakelishman jakelishman added this pull request to the merge queue Mar 4, 2024
Merged via the queue into Qiskit:main with commit f4b50fb Mar 4, 2024
12 checks passed
mergify bot pushed a commit that referenced this pull request Mar 4, 2024
* Fix performance issue in parsing bit indices in QPY

This commit fixes a performance issue in the deserialization of QPY
payloads. Previously when parsing every instruction the deserialization
would build up a dictionary of indices to bits so that when we load the
bit index in the qargs and cargs for each instruction. This mean the
worst case scaling of this section was O(n * m) for n instructions and
m bits, which for very large circuits could end up dominating the time
spent in deserialization. However, this was unecessary work because it
is rebuilding a mapping from index to bit as a dictionary, but that
mapping already existed in the bit lists the circuit is carrying around.
This commit fixes the performance issue by removing the dictionary
generation and just using the bit lists directly.

* Add release note

* Simplify logic

(cherry picked from commit f4b50fb)
github-merge-queue bot pushed a commit that referenced this pull request Mar 4, 2024
* Fix performance issue in parsing bit indices in QPY

This commit fixes a performance issue in the deserialization of QPY
payloads. Previously when parsing every instruction the deserialization
would build up a dictionary of indices to bits so that when we load the
bit index in the qargs and cargs for each instruction. This mean the
worst case scaling of this section was O(n * m) for n instructions and
m bits, which for very large circuits could end up dominating the time
spent in deserialization. However, this was unecessary work because it
is rebuilding a mapping from index to bit as a dictionary, but that
mapping already existed in the bit lists the circuit is carrying around.
This commit fixes the performance issue by removing the dictionary
generation and just using the bit lists directly.

* Add release note

* Simplify logic

(cherry picked from commit f4b50fb)

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
@mtreinish mtreinish deleted the fix-perf-qpy-load branch March 4, 2024 21:24
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Mar 11, 2024
* Fix performance issue in parsing bit indices in QPY

This commit fixes a performance issue in the deserialization of QPY
payloads. Previously when parsing every instruction the deserialization
would build up a dictionary of indices to bits so that when we load the
bit index in the qargs and cargs for each instruction. This mean the
worst case scaling of this section was O(n * m) for n instructions and
m bits, which for very large circuits could end up dominating the time
spent in deserialization. However, this was unecessary work because it
is rebuilding a mapping from index to bit as a dictionary, but that
mapping already existed in the bit lists the circuit is carrying around.
This commit fixes the performance issue by removing the dictionary
generation and just using the bit lists directly.

* Add release note

* Simplify logic
IsmaelCesar pushed a commit to comp-quantica/qiskit-terra that referenced this pull request Mar 13, 2024
* Fix performance issue in parsing bit indices in QPY

This commit fixes a performance issue in the deserialization of QPY
payloads. Previously when parsing every instruction the deserialization
would build up a dictionary of indices to bits so that when we load the
bit index in the qargs and cargs for each instruction. This mean the
worst case scaling of this section was O(n * m) for n instructions and
m bits, which for very large circuits could end up dominating the time
spent in deserialization. However, this was unecessary work because it
is rebuilding a mapping from index to bit as a dictionary, but that
mapping already existed in the bit lists the circuit is carrying around.
This commit fixes the performance issue by removing the dictionary
generation and just using the bit lists directly.

* Add release note

* Simplify logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qpy Related to QPY serialization performance stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants