From 981c4707347ae2269241485f06dc3abbc5fb5f47 Mon Sep 17 00:00:00 2001 From: Sameer Dambal Date: Fri, 1 Sep 2023 15:15:48 -0500 Subject: [PATCH] commiting suggested changes with updated email to clear CLA issues --- ...ure-parameterexpression-57693dd69103dc8c.yaml | 16 +++++++++------- test/python/circuit/test_parameters.py | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml b/releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml index badc822fe4d5..b9738207167c 100644 --- a/releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml +++ b/releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml @@ -1,16 +1,18 @@ --- features: - | - Introduced a new feature that adds support for calculating the sign of the Parameter of the value of an expression of a Parameter class. - Instead of using numpy or other libraries, the user can use the instance of the ParameterExpression class to calculate the sign. + Added support for expressing the sign of a :class: 'ParameterExpression' + Instead of assigning a concrete value and using ''numpy.sign'' or other library functions, the user can use the instance of the ParameterExpression + class to calculate the sign and can work with the sign before the expression is fully assigned. It can be used as follows:: - from qiskit.circuit import Parameter + from qiskit.circuit import Parameter - b = Parameter("phi") - sign_value = b.sign() - print("sign of Parameter is: ", sign_value) + b = Parameter("phi") + sign_value = b.sign() + print("sign of an unassigned Parameter is: ", sign_value) + print("Sign of a Parameter assigned to -3 is: ", sign_value.assign(b,-3)) - Refer to ` #10360 `__ for more details. + Refer to ' #10360'__ for more details. diff --git a/test/python/circuit/test_parameters.py b/test/python/circuit/test_parameters.py index 1b6c7d8fa390..b74eef431b2e 100644 --- a/test/python/circuit/test_parameters.py +++ b/test/python/circuit/test_parameters.py @@ -945,6 +945,8 @@ def test_sign_of_parameter(self): b = Parameter("phi") sign_of_parameter = b.sign() self.assertEqual(sign_of_parameter.assign(b, -3), -1) + self.assertEqual(sign_of_parameter.assign(b, 2), 1) + self.assertEqual(sign_of_parameter.assign(b, 0), 0) @combine(target_type=["gate", "instruction"], parameter_type=["numbers", "parameters"]) def test_decompose_propagates_bound_parameters(self, target_type, parameter_type):