uqfoundation / mystic

constrained nonlinear optimization for scientific machine learning, UQ, and AI
http://mystic.rtfd.io
Other
465 stars 50 forks source link

symbolic solve and simplify don't work with python 3.12 #213

Closed mmckerns closed 11 months ago

mmckerns commented 11 months ago

simplify and solve should isolate a single variable on the left-hand side. It doesn't with python 3.12.0rc3.

Python 3.12.0rc3 (main, Sep 23 2023, 00:48:47) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mystic.symbolic as ms
>>> eqn = """x0 - 2*x1 > 0
...          x3 - 3*x2 < 0"""
>>> print(ms.simplify(eqn))
x0 - 2*x1 > 0
x3 - 3*x2 < 0
>>> eqs = """x0 - 2*x1 == 0
...          x3 - 3*x2 == 0"""
>>> print(ms.solve(eqs))
x0 - 2*x1 == 0
         x3 - 3*x2 == 0
>>> eqs = """x0 - 2*x1 = 0
...          x3 - 3*x2 = 0"""
>>> print(ms.solve(eqs))
x0 - 2*x1 = 0
         x3 - 3*x2 = 0
>>> 
mmckerns commented 11 months ago

Expected behavior:

Python 3.11.5 (main, Aug 25 2023, 01:35:05) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mystic.symbolic as ms
>>> eqn = """x0 - 2*x1 > 0
...          x3 - 3*x2 < 0"""
>>> print(ms.simplify(eqn))
x3 < 3*x2
x0 > 2*x1
>>> eqs = """x0 - 2*x1 == 0
...          x3 - 3*x2 == 0"""
>>> print(ms.solve(eqs))
x0 = 2*x1
x2 = x3/3
>>> eqs = """x0 - 2*x1 = 0
...          x3 - 3*x2 = 0"""
>>> print(ms.solve(eqs))
x0 = 2*x1
x2 = x3/3
>>> 
mmckerns commented 11 months ago

more details...

>>> eqn = """x0 - 2*x1 = 0"""
>>> ms.solve(eqn, verbose=True, warn=True)
Warning: sympy not installed.
'x0 - 2*x1 = 0'
>>> 
>>> import sympy
>>> sympy.__version__
'1.12'
>>>
mmckerns commented 11 months ago

it appears this is due to use of imp.find_module, which needs to be replaced with importlib