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.
Check for existence of symengine handling in Terra
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