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

Raise error if broadcasting with MottonenStatePreparation and BasisStatePreparation compute_decomposition #4767

Merged
merged 10 commits into from
Nov 9, 2023

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Oct 31, 2023

Context:
MottonenStatePreparation and BasisStatePreparation fails right now when decomposing a broadcasted state vector because different state vectors have different decompositions.

Description of the Change:

  • Raise an error in MottonenStatePreparation.compute_decomposition and BasisStatePreparation.compute_decomposition if the batch_size if not None and suggest users to use broadcast_expand.

Benefits:
No failures or wrong results when decomposing Mottonen or BasisState

Possible Drawbacks:

Related GitHub Issues:
#4753

@mudit2812 mudit2812 linked an issue Oct 31, 2023 that may be closed by this pull request
1 task
@mudit2812
Copy link
Contributor Author

[sc-48950]

@mudit2812 mudit2812 marked this pull request as ready for review November 1, 2023 14:29
@mudit2812 mudit2812 marked this pull request as draft November 1, 2023 19:30
@mudit2812 mudit2812 changed the title Raise error if broadcasting with MottonenStatePreparation.compute_decomposition Raise error if broadcasting with MottonenStatePreparation and BasisStatePreparation compute_decomposition Nov 2, 2023
@mudit2812 mudit2812 marked this pull request as ready for review November 2, 2023 16:45
@mudit2812 mudit2812 requested a review from a team November 2, 2023 16:45
Copy link

codecov bot commented Nov 2, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (deaf387) 99.64% compared to head (d404845) 99.63%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4767      +/-   ##
==========================================
- Coverage   99.64%   99.63%   -0.02%     
==========================================
  Files         381      381              
  Lines       34336    34121     -215     
==========================================
- Hits        34214    33996     -218     
- Misses        122      125       +3     
Files Coverage Δ
pennylane/templates/state_preparations/basis.py 100.00% <100.00%> (ø)
pennylane/templates/state_preparations/mottonen.py 100.00% <100.00%> (ø)
pennylane/transforms/transpile.py 100.00% <100.00%> (ø)

... and 43 files with indirect coverage changes

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

@mudit2812 mudit2812 requested a review from a team November 3, 2023 17:55
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

broadcast_expand does not fix the problem.

The problem is that op.batch_size will still be None, so broadcast_expand will not register that the template has a batched.

broadcast_expand does work if we set ndim_params = (1,) for MottonenStatePrep.

Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

👍

@mudit2812 mudit2812 enabled auto-merge (squash) November 9, 2023 21:19
@mudit2812 mudit2812 merged commit 3260950 into master Nov 9, 2023
33 checks passed
@mudit2812 mudit2812 deleted the mottonen-decomp branch November 9, 2023 21:36
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.

[BUG]MottonenStatePreparation.compute_decomposition
5 participants