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

MPSPrep adding extra empty qubit #1064

Merged
merged 28 commits into from
Feb 25, 2025
Merged

MPSPrep adding extra empty qubit #1064

merged 28 commits into from
Feb 25, 2025

Conversation

LuisAlfredoNu
Copy link
Contributor

@LuisAlfredoNu LuisAlfredoNu commented Feb 12, 2025

Context:
Lightning Tensor can use an MPS as input but should be passed through the circuit operation qml.MPSPrep but must have the same shape as the allocated MPS.

Description of the Change:
This PR adds the following features to Lightning Tensor:

  • Allow qml.MPSPrep to accept an MPS with len(MPS) = n_wires-1
  • Expand the input MPS to fit with the allocated MPS.

The following algorithm was implemented

  • Padding with zeros the tensor $B_i$ to fit the tensor shape $A_{i+1}$ up to $i = N/2$ where $N$ is the total number of tensors in $B$
  • Add the identity matrix with shape (1,2,2) at the beginning of $B$
  • Restore the $B$ MPS into a right-canonical form to spread the new site information across the entire MPS.

Benefits:
More flexibility to work with LT and provide custom MPS.

Possible Drawbacks:

Related GitHub Issues:

[sc-84509]

@LuisAlfredoNu LuisAlfredoNu added the ci:use-gpu-runner Enable usage of GPU runner for this Pull Request label Feb 12, 2025
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.36%. Comparing base (dcebe62) to head (09a31c5).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1064      +/-   ##
==========================================
+ Coverage   96.09%   97.36%   +1.27%     
==========================================
  Files         232      111     -121     
  Lines       39079    16976   -22103     
==========================================
- Hits        37552    16529   -21023     
+ Misses       1527      447    -1080     

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

@LuisAlfredoNu LuisAlfredoNu marked this pull request as ready for review February 13, 2025 20:27
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit .github/CHANGELOG.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

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 @LuisAlfredoNu! Nice work ⚡

Copy link
Member

@multiphaseCFD multiphaseCFD left a comment

Choose a reason for hiding this comment

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

Thank you @LuisAlfredoNu for your excellent work. This enhancement will improve the performance of the LT process with block2 data and provides a way to verify the canonical form of MPS site data.

My only question for discussion is whether LT is the most appropriate location for this feature. I'm concerned about the potential risk due to the current lack of safety checks. If we keep this functionality within LT, there's a possibility of issues arising. For example, a user might intend to analyze an n_wires system and correctly provide n_wires MPS site data to MPSPrep. However, if they accidentally provide n_wires-1 MPS site data, the LT process might not detect the discrepancy and throw an error beforehand. I'd like to open this up for discussion with the team.

CC: @maliasadi @josephleekl @AmintorDusko

@LuisAlfredoNu
Copy link
Contributor Author

LuisAlfredoNu commented Feb 21, 2025

My only question for discussion is whether LT is the most appropriate location for this feature. I'm concerned about the potential risk due to the current lack of safety checks. If we keep this functionality within LT, there's a possibility of issues arising. For example, a user might intend to analyze an n_wires system and correctly provide n_wires MPS site data to MPSPrep. However, if they accidentally provide n_wires-1 MPS site data, the LT process might not detect the discrepancy and throw an error beforehand. I'd like to open this up for discussion with the team.

Thank you @multiphaseCFD for your review. The situation that you mention throws a proper error to the user, if they try to do that then LT will show the error:

Error in PennyLane Lightning: The incoming MPS does not have the correct layout for lightning.tensor.

because the input MPS and the target MPS don't match in dimension. I will add an extra test to clarify this situation.

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.

Nice work @LuisAlfredoNu! 🎸 Happy to approve after updating docstrings ✍️

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.

Nice job! Thank you!

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 @LuisAlfredoNu! Happy to approve the impl 🙌

@LuisAlfredoNu LuisAlfredoNu merged commit d9d011e into master Feb 25, 2025
72 of 73 checks passed
@LuisAlfredoNu LuisAlfredoNu deleted the remove_MPS_limit branch February 25, 2025 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:use-gpu-runner Enable usage of GPU runner for this Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants