Ticket #98 (closed idea: worksforme)

Opened 6 years ago

Last modified 3 years ago

add a constraint function generator with support for symbolic math

Reported by: mmckerns Owned by: mmckerns
Priority: minor Milestone: mystic-0.2a2
Component: mystic.constraints Keywords:
Cc:

Description (last modified by mmckerns) (diff)

add support for symbolic math (i.e. sympy)

add a constraint function generator. should have the ability to turn symbolic math into a constraints function

Change History

comment:1 Changed 6 years ago by mmckerns

from Chris Farrow:

The best way I found to make callables is with the lambdify function. It seems that this is the only way to process equations that require numpy arrays as input. Sympy is quite fast, it beat diffpy.srfit.equation in several of my tests.

There is one major problem that I have with sympy, and that is you can't compose symbolic and numeric routines. For example, the Debye equation requires some numerical integration. This could be implemented by sympy.Integral, but it seems more natural (and common) to write a numeric routine. Furthermore, legacy code will be numeric, not symbolic. So, once I have a numeric routine, how do I use sympy to compose this with another routine? As far as I can tell this cannot be done easily. Perhaps some string magic and lambda functions would do the trick, but then we're not really using sympy.

Some follow-up: It looks like  openopt.FuncDesigner might be able to satisfy my use case.

comment:2 Changed 6 years ago by mmckerns

  • Summary changed from add support for symbolic math to add a constraint function generator with support for symbolic math
  • Description modified (diff)
  • Milestone changed from mystic-dev to mystic-0.2a3

expanded slightly to cover ticket #122

comment:3 Changed 6 years ago by mmckerns

  • Milestone changed from mystic-0.2a3 to mystic-0.2a2

comment:4 Changed 5 years ago by mmckerns

in building a constraints function, one should be able to also import required functions to evaluate the constraints...

implementation options/decisions:

  • allow import statement in symbolic constraints string ?
  • allow passing of relevant imported objects ?
  • allow function generator to pull any imported function from globals() and locals() ?

comment:5 Changed 5 years ago by mmckerns

also look at diffpy.srfit's "equation" and "fitbase" at  http://danse.us/trac/diffraction/browser/diffraction/diffpy.srfit/trunk/diffpy/srfit

comment:6 Changed 4 years ago by mmckerns

  • Component changed from mystic.math to mystic.constraints
  • Milestone changed from mystic-0.2a2 to mystic-0.2a3

comment:7 Changed 3 years ago by mmckerns

improved and added basic "symbolic to constrains" capabilities in the "decorate" branch in r611. Does not require sympy; however, with a little more work, sympy can be used to speed up the existing generated constraints solvers.

comment:8 Changed 3 years ago by mmckerns

sympy seems pretty limited when it comes to solving with a 'math' function like "x1 = cos(x2)"... and also when there's an inequality, although solving for inequalities in sympy seems to be improving as of late. Punting on sympy for a while seems to be a good plan.

Sympy also seems to not care about backward compatibility too much... so the functions that use sympy should be checked against a few versions of sympy.

Then maybe check out srfit's "equation" and "fitbase"... (see above entry)

comment:9 Changed 3 years ago by mmckerns

  • Status changed from new to closed
  • Resolution set to worksforme
  • Milestone changed from mystic-0.3a to mystic-0.2a2

as of r620, the symbolic solver works pretty well for equalities, but not inequalities, using sympy.

splitting off a simplified symbolic inequality solver to ticket #198, closing the current ticket

Note: See TracTickets for help on using tickets.