-
Notifications
You must be signed in to change notification settings - Fork 624
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
StatePrep
accepts sparse matrices as input
#6863
StatePrep
accepts sparse matrices as input
#6863
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 #6863 +/- ##
=======================================
Coverage 99.59% 99.59%
=======================================
Files 480 480
Lines 45421 45474 +53
=======================================
+ Hits 45236 45289 +53
Misses 185 185 ☔ View full report in Codecov by Sentry. |
I'll udpate changelog if we are OK with the current implementation, or until we converge at the final implementation |
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.
Hi @JerryChen97! Nice work! I left a few suggestions and comments.
Also, regarding your PR description, I'd like to point out that CSR stands for Compressed Sparse Row. Adding documentation from the beginning is usually a better choice, but I will let the CORE team decide.
Please feel free to tag me again whenever you're ready.
Cheers!
Co-authored-by: Amintor Dusko <[email protected]>
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.
Good job!
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.
🚀
…-sparse-matrices-as-input' into `StatePrep`-accepts-sparse-matrices-as-input
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.
Nothing else for me except for the last suggestions to the doc. Nice work!
Co-authored-by: Pietropaolo Frisoni <[email protected]>
…-sparse-matrices-as-input' into `StatePrep`-accepts-sparse-matrices-as-input
Context:
To make PennyLane use sparse matrics, at the atomic level we need to provide at least two features:
QubitUnitary
) have their sprase version along with the default sparse-sparse, sparse-dense multiplicationThis Pull Request focus on fulfilling the first.
Note that up to v0.40, PL implements state initialization using class
StatePrep
fromops/qubit/state_preparation.py
. Conceptually, we treated the state preparation as a generalized operation here, although unlike many other operators which are typically differentiable,StatePrep
shall be expected as non-differentiable in most of the practical context.Recall the interface of
StatePrep
,where
state
is the input values for the initalization,wires
is the total number of qubits of the final state,pad_with
refers to a specific feature with which the user can use a shorterstate
of length less than2**wires
and PL will automatically fill the remaining component with the givenpad_with
.normalize
andvalidate_norm
are standard controls for the norm preprocessing of a state-vector.Revisiting this, we would like to support specific input type of
state
as sparse matrices. Specifically, for simplicity of the first feature, we just usecsr_matrix
fromSciPy.sparse
(Compressed Sparse RowColumnformat; check https://docs.scipy.org/doc/scipy/reference/sparse.html for futher details). Meanwhile, note that a nonzeropad_with
is clearly against the idea of sparsity since it makes the state dense, so we will disable this option if the previous sparsity ofstate
is given by a user.Description of the Change:
StatePrep
, implementing it overloading_sparse_statevec_permute
to align with the original defaultStatePrep.state_vector
where the input states can be embedded into the given larger wire sets with permuted wire order.check the parent classes for other supported operations, e.g. equalupdated: out-of-scope and not necesary. Leave it to future improvement.Benefits:
StatePrep
by overloading it with new features of sparse matrices.Possible Drawbacks:
StatePrep
is actually facing public users, and it does not make sense to add notes in docs before the successful implementation of the whole workflow. They will be added in the future PR that complets the end-to-end sparse-matrix feature of PennyLane (i.e., at least a measurement can be done, which requires modification on the qubit simulator workflow)Related GitHub Issues:
[sc-82067]