Skip to content

Commit

Permalink
Parameter conjugate (#4619)
Browse files Browse the repository at this point in the history
* add reno

* add test
  • Loading branch information
Cryoris authored Jun 26, 2020
1 parent 9c1cf93 commit 5f71bf2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions qiskit/circuit/parameterexpression.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def parameters(self):
"""Returns a set of the unbound Parameters in the expression."""
return set(self._parameter_symbols.keys())

def conjugate(self):
"""Return the conjugate, which is the ParameterExpression itself, since it is real."""
return self

def bind(self, parameter_values):
"""Binds the provided set of parameters to their corresponding values.
Expand Down
7 changes: 7 additions & 0 deletions releasenotes/notes/parameter-conjugate-a16fd7ae0dc18ede.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
Add a ``conjugate`` method to the ``ParameterExpression`` to allow
calling ``numpy.conj()`` without raising an error. Since the
``ParameterExpression`` is real, it returns itself.
This behaviour is analogous to Python floats/ints.
5 changes: 5 additions & 0 deletions test/python/circuit/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,11 @@ def test_substituting_compound_expression(self):

self.assertEqual(updated_expr, expected)

def test_conjugate(self):
"""Test calling conjugate on a ParameterExpression."""
x = Parameter('x')
self.assertEqual(x, x.conjugate()) # Parameters are real, therefore conjugate returns self


class TestParameterEquality(QiskitTestCase):
"""Test equality of Parameters and ParameterExpressions."""
Expand Down

0 comments on commit 5f71bf2

Please sign in to comment.