-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Implement SparsePauliOp.assign_parameters
#8966
Comments
I am thinking that the handling of binding is user’s job or Parameter module’s job. I don’t think at least it is SparsePauliOp's job now. We may still have a helper function in Parameter, but I don’t want to make a method that assumes that it has a Parameter. What should we do if it’s Example of helper function I am thinking: def get_parameters(array) -> ParameterView:
ret = set()
for a in array:
if isinstance(a, ParameterExpression):
ret |= a.parameters
return ParameterView(ret)
def assign_parameters(array, parameter_values):
if isinstance(parameter_values, list):
parameter_values = dict(zip(get_parameters(array), parameter_values))
for i, a in enumerate(array):
if isinstance(a, ParameterExpression):
for key in a.parameters & parameter_values.keys():
a = a.assign(key, parameter_values[key])
if not a.parameters:
a = complex(a)
array[i] = a
return array
spo = SparsePauliOp(["II", "XZ", "II"], np.array([Parameter("a"), Parameter("b"), 3+1j]))
assign_parameters(spo.coeffs, [2, 9]) Added: the order of parameters is undefined. I'm not sure if the user want to sort. |
Alright, thank you! 👍 Feel free to close this issue if you feel like this resolves it. I am open to whether or not this functionality should be added. |
When opflow was done with Parameter support we had consistency in the way the object supported Parameters with the same the methods as a parameterized circuit for the parameterized operator. My take is that it would nice to have the same support here with the Parameter support/objects Terra has. If you are allowing other types as coeffs then I agree the onus is on an end user. But for Parameter support my take would be to have the SparsePauliOp support it for consistency and ease of end user use. |
I also think it would be good to have proper support of Qiskit's As Steve said already, we of course don't support binding any variable type but since the |
Issue resolved by #9796. |
What should we add?
#8620 added support for
Parameter
objects to be used inside ofSparsePauliOp
s, porting this functionality fromopflow
toquantum_info
and paving the way for a switch of the algorithms and application modules to be using purelyquantum_info
in the future.However, once key functionality for this to be useful is still missing; and that is the implementation of
SparsePauliOp.assign_parameters
. Without it, there is no convenient way of actually using a parameterizedSparsePauliOp
instance.The text was updated successfully, but these errors were encountered: