-
Notifications
You must be signed in to change notification settings - Fork 210
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
add support for Parameters to SparseLabelOp #891
add support for Parameters to SparseLabelOp #891
Conversation
Pull Request Test Coverage Report for Build 3364057348
💛 - Coveralls |
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.
Thank you, Kevin!
Besides these minor comments just a question: did you happen to also look into how the PolynomialTensor
class can handle Parameter
objects? In theory, this should be possible and I had done some rough testing a while back but not looked into it in more detail.
We can add support for that as part of another PR and a separate tracking issue, but I wanted to ask first, whether you had already looked into this 👍
I did not look into it in much detail. Let's leave that as a separate issue and separate PR. I think using Parameters with PolynomialTensor is a very niche use case so it is not a high priority. PolynomialTensor is mainly useful for linear algebra operations, and those would not be possible if it had Parameters. |
Quite on the contrary. Enabling parameterized One example where a parameterized Just a proof of concept: import numpy as np
from qiskit.circuit import Parameter
from qiskit_nature.second_q.operators import FermionicOp, PolynomialTensor
a = Parameter("a")
b = Parameter("b")
mata = np.eye(2, dtype=object)
mata[0, 0] = a
matb = np.zeros((2, 2), dtype=object)
matb[0, 1] = b
matb[1, 0] = -b
pt_a = PolynomialTensor({"+-": mata})
pt_b = PolynomialTensor({"+-": matb})
print(pt_a + pt_b)
print(pt_a @ pt_b)
op = FermionicOp.from_polynomial_tensor(pt_a + pt_b)
print(op)
op = FermionicOp.from_polynomial_tensor(pt_a @ pt_b)
print(op) Outputs (omitting zero-terms because chop needs a little work):
|
By linear algebra I meant eigenvalue decompositions and the like, not just matrix multiplication. Isn't that needed for computing orbital rotations? |
Those would not work, yes. The way that the orbital rotations are done there, I do not think its needed. Although this may not hold generally speaking. |
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.
Other than this, this LGTM 👍
Co-authored-by: Max Rossmannek <[email protected]>
I think this is broken because of a bug introduced by #893. See https://github.com/Qiskit/qiskit-nature/pull/893/files#r998269022. |
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.
Just one last clarification, other than that this is good to go 👍
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.
Thanks, Kevin!
This is a more general question. What do we expect of such parameterized operators. If I look at a parameterized quantum circuit I have methods to get parameters and also to bind values etc. Might I want this at this level - I see that you've done similar to SparsePauliOp but I guess I could ask the same question of that too. |
Ok, I've added the method. Also, in order to support assigning parameters in place, I changed the type of the internal |
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.
Also, in order to support assigning parameters in place, I changed the type of the internal data container from Mapping to dict.
I do not understand why you think this is necessary. The public API can report Mapping
just fine. The fact that we use a dict
internally for storage does not affect this.
When |
Alright I have also discussed with @woodsp-ibm offline. We would like to do the following:
|
In accordance with our offline discussion, I've reverted the change from |
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.
Just some minor comments. Other than this, this is looking good 👍
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.
This LGTM 👍
Is there anything else? If not I'll go ahead and fix the merge conflicts. |
Not from me, let's get the conflict sorted then. |
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.
LGTM, thanks Kevin!
* add support for Parameters to SparseLabelOp * fix isinstance for python < 3.10 * improve docs * chop zero Parameter * Update test/second_q/operators/test_sparse_label_op.py Co-authored-by: Max Rossmannek <[email protected]> * fix test * add is_parameterized and check it for unsupported operations * add assign_parameters * fix chop doc * lint * add parameters method * use dict instead of Mapping for data * return self instead of None for inplace * Revert "use dict instead of Mapping for data" This reverts commit 3480c79. * remove inplace option for assign_parameters * address comments * Update qiskit_nature/second_q/operators/sparse_label_op.py * fix equiv Co-authored-by: Max Rossmannek <[email protected]>
Summary
Part of #828
Details and comments
Also fixes #892