Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
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
13 changes: 3 additions & 10 deletions qiskit/circuit/parameterexpression.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,24 +521,17 @@ def __eq__(self, other):
def is_real(self):
"""Return whether the expression is real"""

# workaround for symengine behavior that const * (0 + 1 * I) is not real
# see https://github.com/symengine/symengine.py/issues/414
if _optionals.HAS_SYMENGINE and self._symbol_expr.is_real is None:
symbol_expr = self._symbol_expr.evalf()
else:
symbol_expr = self._symbol_expr

if not symbol_expr.is_real and symbol_expr.is_real is not None:
if not self._symbol_expr.is_real and self._symbol_expr.is_real is not None:
# Symengine returns false for is_real on the expression if
# there is a imaginary component (even if that component is 0),
# but the parameter will evaluate as real. Check that if the
# expression's is_real attribute returns false that we have a
# non-zero imaginary
if _optionals.HAS_SYMENGINE:
if symbol_expr.imag == 0.0:
if self.symbol_expr.imag == 0.0:
Comment thread
1ucian0 marked this conversation as resolved.
Outdated
return True
return False
return symbol_expr.is_real
return self.symbol_expr.is_real
Comment thread
1ucian0 marked this conversation as resolved.
Outdated

def sympify(self):
"""Return symbolic expression as a raw Sympy or Symengine object.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sympy>=1.3
dill>=0.3
python-dateutil>=2.8.0
stevedore>=3.0.0
symengine>=0.9 ; platform_machine == 'x86_64' or platform_machine == 'aarch64' or platform_machine == 'ppc64le' or platform_machine == 'amd64' or platform_machine == 'arm64'
symengine>=0.10 ; platform_machine == 'x86_64' or platform_machine == 'aarch64' or platform_machine == 'ppc64le' or platform_machine == 'amd64' or platform_machine == 'arm64'
shared-memory38;python_version<'3.8'
typing-extensions; python_version < '3.8'
singledispatchmethod; python_version < '3.8'
Expand Down