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

Move functions to base class #841

Merged
merged 13 commits into from
Aug 9, 2024

Conversation

erick-xanadu
Copy link
Contributor

@erick-xanadu erick-xanadu commented Aug 8, 2024

Context: Some of these functions are needed in Catalyst. Since Catalyst does not use LM, but instead uses LightningDynamic, the least upper bound in the class hierarchy is StateVectorLQubit.

Description of the Change: Move these functions to StateVetctorLQubit.

Benefits: Code-reuse

Possible Drawbacks:

Related GitHub Issues:

@erick-xanadu erick-xanadu marked this pull request as ready for review August 8, 2024 16:27
Copy link

codecov bot commented Aug 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.33%. Comparing base (8f517d2) to head (0545954).
Report is 87 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (8f517d2) and HEAD (0545954). Click for more details.

HEAD has 63 uploads less than BASE
Flag BASE (8f517d2) HEAD (0545954)
70 7
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #841      +/-   ##
==========================================
- Coverage   98.42%   92.33%   -6.10%     
==========================================
  Files         116       70      -46     
  Lines       18660    11211    -7449     
==========================================
- Hits        18367    10352    -8015     
- Misses        293      859     +566     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@maliasadi maliasadi left a comment

Choose a reason for hiding this comment

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

@erick-xanadu What was the issue with adding these methods to StateVectorLQubitDynamic? Any plan to get this support for LK in a followup PR?

Copy link
Contributor

@AmintorDusko AmintorDusko left a comment

Choose a reason for hiding this comment

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

The StateVectorLQubit has no explicit storage data type.
It might be tricky moving it here, or even unsafe.

@erick-xanadu
Copy link
Contributor Author

erick-xanadu commented Aug 8, 2024

@erick-xanadu What was the issue with adding these methods to StateVectorLQubitDynamic? Any plan to get this support for LK in a followup PR?

@maliasadi The idea was to reuse code. So moving these to the base class is only for increasing code reuse. LK's implementation is already in the base class.

@erick-xanadu
Copy link
Contributor Author

erick-xanadu commented Aug 8, 2024

The StateVectorLQubit has no explicit storage data type.
It might be tricky moving it here, or even unsafe.

@AmintorDusko Happy to close this ticket then. I'll leave it up for a bit of further discussion. The disadvantage is that we would copy these methods over. Right now for example, I am working on other two methods that will call these methods. And that means we would also have to copy these over in Catalyst.

@erick-xanadu
Copy link
Contributor Author

erick-xanadu commented Aug 8, 2024

@AmintorDusko alternatively, there could be another class between these two that implement these methods and Lightning Dynamic inherits from that one. Not sure how that would impact performance though. I know there is some static devirtualization being done through templates.

@vincentmr
Copy link
Contributor

The StateVectorLQubit has no explicit storage data type.

What is preventing us from getting a pointer to the data and modifying it? All the gates are applied in this way already, so isn't it natural to do the StatePrep similarly?

@AmintorDusko
Copy link
Contributor

The StateVectorLQubit has no explicit storage data type.
It might be tricky moving it here, or even unsafe.

@AmintorDusko Happy to close this ticket then. I'll leave it up for a bit of further discussion. The disadvantage is that we would copy these methods over. Right now for example, I am working on other two methods that will call these methods. And that means we would also have to copy these over in Catalyst.

Hey @erick-xanadu, feel free to proceed and get the team's opinion on that.
You don't need to close the PR.
I agree that copying is an advantage, especially in the maintenance context.
We can improve safety by including some checks in the methods, like checking the indices size and comparing it with the statevector size, before proceeding. What do you think?

@AmintorDusko
Copy link
Contributor

The StateVectorLQubit has no explicit storage data type.

What is preventing us from getting a pointer to the data and modifying it? All the gates are applied in this way already, so isn't it natural to do the StatePrep similarly?

Nothing. See my comment addressing Eric.

@erick-xanadu
Copy link
Contributor Author

erick-xanadu commented Aug 8, 2024

We can improve safety by including some checks in the methods, like checking the indices size and comparing it with the statevector size, before proceeding. What do you think?

@AmintorDusko , added extra checks here: 7ddcc06

Copy link
Contributor

@vincentmr vincentmr left a comment

Choose a reason for hiding this comment

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

A couple suggestions, but I think it will be ready to merge after.

.github/CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Vincent Michaud-Rioux <[email protected]>
Copy link
Contributor

@vincentmr vincentmr left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @erick-xanadu . Feel free to merge once the CI is green (I think you'll need to run make format).

Copy link
Member

@maliasadi maliasadi left a comment

Choose a reason for hiding this comment

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

Thanks @erick-xanadu! 🙌 Happy to approve after resolving my comment for setStateVector

@erick-xanadu erick-xanadu merged commit 3993e0b into master Aug 9, 2024
70 of 71 checks passed
@erick-xanadu erick-xanadu deleted the eochoa/2024-08-08/move-to-base-class branch August 9, 2024 20:47
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.

5 participants