TemplateOptimization
creates ParameterExpression
s with Sympy types when Symengine is available
#11106
Labels
bug
Something isn't working
Environment
What is happening?
The
TemplateOptimization
pass can return circuits that contain Sympy-backedParameterExpression
s even when Symengine is installed and available. This doesn't immediately seem to pose any troubles, mostly because Symengine can work with Sympy objects and converts them internally, Symengine is supposed to be used if available andParameterExpression
assumes that its types are all Symengine types if it is available. This can lead to problems when it wants to call Symengine functions that do not have the same arguments / names as their Sympy equivalents.How can we reproduce the issue?
The output type is some Sympy type, but it should be a Symengine one.
What should happen?
Template optimisation uses sympy internally in order to use
sympy.solve
, but does not necessarily convert its objects back to the native form before creatingParameterExpression
objects. It should arrange for these objects to be cast back to Symengine ones, if it's playing withParameterExpression
at a low level.Any suggestions?
Tbh, the template optimisation code probably doesn't actually need sympy here at all - if we instead restricted the templates to say that parameters can only be used in linearly (templates are just simple), we'd be able to roll our own basic linear simultaneous-equation solver and skip the heavy sympy import and use.
This code isn't used much though, and it could do with a fairly serious refactor, so that's a very low priority.
The text was updated successfully, but these errors were encountered: