Skip to content

Commit

Permalink
Merge branch 'Qiskit:main' into move-target
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss authored Jun 4, 2024
2 parents cdf762e + 797bb28 commit 29c34ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion qiskit/circuit/parameterexpression.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,11 @@ def __rsub__(self, other):
def __mul__(self, other):
return self._apply_operation(operator.mul, other)

def __pos__(self):
return self._apply_operation(operator.mul, 1)

def __neg__(self):
return self._apply_operation(operator.mul, -1.0)
return self._apply_operation(operator.mul, -1)

def __rmul__(self, other):
return self._apply_operation(operator.mul, other, reflected=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features_circuits:
- |
:class:`.ParameterExpression` now supports the unary ``+`` operator.
7 changes: 7 additions & 0 deletions test/python/circuit/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,13 @@ def test_negated_expression(self):

self.assertEqual(float(bound_expr2), 3)

def test_positive_expression(self):
"""This tests parameter unary plus."""
x = Parameter("x")
y = +x
self.assertEqual(float(y.bind({x: 1})), 1.0)
self.assertIsInstance(+x, type(-x))

def test_standard_cu3(self):
"""This tests parameter negation in standard extension gate cu3."""
from qiskit.circuit.library import CU3Gate
Expand Down

0 comments on commit 29c34ce

Please sign in to comment.