Skip to content

Access _row and _col attributes directly in GridQubit instead of using properties#6075

Merged
maffoo merged 1 commit intomasterfrom
u/maffoo/grid-qubit-row-col
Apr 22, 2023
Merged

Access _row and _col attributes directly in GridQubit instead of using properties#6075
maffoo merged 1 commit intomasterfrom
u/maffoo/grid-qubit-row-col

Conversation

@maffoo
Copy link
Copy Markdown
Contributor

@maffoo maffoo commented Apr 22, 2023

Using self._row and self._col attributes directly instead of properties in the internals of these classes provides a significant speedup, especially since these classes are heavily used. On an internal benchmark, this reduced the total time spent in GridQubit.__eq__ from 20.8s down to 5.7s, a 3.6x speedup.

There are other optimizations we might be able to make in the future, for example by "de-virtualizing" more methods to not rely on generic implementations in the base class, as we have already done for GridQubit.__eq__ itself, but for now this provides a welcome performance boost.

@maffoo maffoo requested review from a team, cduck and vtomole as code owners April 22, 2023 21:47
@maffoo maffoo requested a review from viathor April 22, 2023 21:47
@maffoo maffoo changed the title Access _row and _col attributes directly in GridQubit instead of using properties Access _row and _col attributes directly in GridQubit instead of using properties Apr 22, 2023
@maffoo maffoo merged commit 2a57894 into master Apr 22, 2023
@maffoo maffoo deleted the u/maffoo/grid-qubit-row-col branch April 22, 2023 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants