-
Notifications
You must be signed in to change notification settings - Fork 595
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
Lazy loading of Quantumscript properties #5696
Conversation
Hello. You may have forgotten to update the changelog!
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5696 +/- ##
==========================================
- Coverage 99.68% 99.67% -0.01%
==========================================
Files 416 416
Lines 39049 38808 -241
==========================================
- Hits 38925 38683 -242
- Misses 124 125 +1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just one comment, otherwise ready to approve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me 🎉
…utes add invalidation logic for cached_properties in qscript
…uctor and methods
add logic to check if obs_sharing_wires has not been calculated or if its empty
6fb4498
to
6d2c9ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, one very tiny suggestion and then I'll approve.
Context:
Eager initialization of parameters inside the constructor of
QuantumScript
induces a high classical overhead.Description of the Change:
The following attributes of
QuantumScript
are no longer initialized in the constructor, but only when needed:par_info
,obs_sharing_wires
, andobs_sharing_wires_id
are now public attributes as they were used in several files outside theQuantumScript
class. Examples of this behaviour are:The most expensive attributes:
par_info
andwires
are now a@cached_property
to avoid calculating them every time they are needed.When used inside the
QuantumTape
context, the_update()
method is called to invalidate the cached value and allow for recalculation.Benefits:
Reduce in the classical overhead of creating a
QuantumScript
. For instance, for the following code:The
QuantumScript
creation time decreases from 62.51% of the whole time, to 41.92%.Related Shortcut Stories:
[sc-45973]