qiskit-community / qiskit-aqua

Quantum Algorithms & Applications (**DEPRECATED** since April 2021 - see readme for more info)
https://qiskit.org/aqua
Apache License 2.0
571 stars 377 forks source link

[Stable] Handle symengine based parameter expressions (#1586) #1591

Closed manoelmarques closed 3 years ago

manoelmarques commented 3 years ago

In Qiskit/qiskit-terra#6270 symengine is being added as an optional (but default on common platforms) backend for parameters and parameter expressions. However, the aqua version of the gradient code there is an implicit assumption that parameterexpressions are internally just wrappers of sympy expressions. This assumption about the internals of terra breaks with Qiskit/qiskit-terra#6270 where they might be symengine or sympy expressions. While symengine and sympy expressions are interchangeable this can only be done with an explicit conversion step (for example, sympy.sympify(symengine.Symbol('x'))). This commit fixes this by updating the derivative base class as was done for terra's version in Qiskit/qiskit-terra#6270 so that the deprecated aqua copy continues to work wither versions of terra after Qiskit/qiskit-terra#6270 merges.

Co-authored-by: Manoel Marques Manoel.Marques@ibm.com

Summary

Details and comments