Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion qiskit_nature/second_q/operators/sparse_label_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,9 @@ def assign_parameters(self, parameters: Mapping[ParameterExpression, _TCoeff]) -
A new operator with the parameters assigned.
"""
data = {
key: parameters[value] if value in parameters else value
key: value.bind(parameters, allow_unknown_parameters=True)
Comment thread
kevinsung marked this conversation as resolved.
Outdated
if isinstance(value, ParameterExpression)
else value
for key, value in self._data.items()
}
return self._new_instance(data, other=self)
Expand Down
10 changes: 10 additions & 0 deletions test/second_q/operators/test_sparse_label_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def test_add(self):

self.assertEqual(test_op, target_op)

with self.subTest("parameter + parameter"):
test_op = DummySparseLabelOp({"+_0 -_1": a}) + DummySparseLabelOp({"+_1 -_0": a})
target_op = DummySparseLabelOp({"+_0 -_1": a, "+_1 -_0": a})

self.assertEqual(test_op, target_op)

Comment thread
kevinsung marked this conversation as resolved.
Outdated
with self.subTest("new key"):
test_op = DummySparseLabelOp(op1) + DummySparseLabelOp(op3)
target_op = DummySparseLabelOp(
Expand Down Expand Up @@ -418,6 +424,10 @@ def test_assign_parameters(self):
self.assertEqual(assigned_op, DummySparseLabelOp({"+_0 -_1": 1.0, "+_0 -_2": b}))
self.assertEqual(op, DummySparseLabelOp({"+_0 -_1": a, "+_0 -_2": b}))

op = DummySparseLabelOp({"+_0 -_1": a + 1}) + DummySparseLabelOp({"+_1 -_0": a})
assigned_op = op.assign_parameters({a: 1})
self.assertEqual(assigned_op, DummySparseLabelOp({"+_0 -_1": 2, "+_1 -_0": 1}))

def test_round(self):
"""test round function"""
with self.subTest("round just real part"):
Expand Down