m-squared96 / PyPLANE

An open source replacement to the traditional DFIELD and PPLANE applications for solving systems of ODEs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issues using some uppercase symbols like "C"

mjancen opened this issue · comments

When I tried to enter the system of equations [Ax + By, Cx + Dy], with the required parameters filled out, an exception is raised. This exception seems to be related to symbols that are used internally in Sympy, and it seems to only occur with some uppercase symbol names.

I've just started looking into this issue. It seems to work if multiplication is specified explicitly, ie. C*x instead of Cx.

Imgur

If multiplication is not implicit, PyPLANE will crash with the following tracelog.

/home/waljt/Desktop/PyPLANE/env/lib/python3.6/site-packages/sympy/deprecated/class_registry.py:38: SymPyDeprecationWarning: 

C, including its class ClassRegistry, has been deprecated since SymPy
1.0. It will be last supported in SymPy version 1.0. Use direct
imports from the defining module instead. See
https://github.com/sympy/sympy/issues/9371 for more info.

  deprecated_since_version='1.0').warn(stacklevel=2)
Traceback (most recent call last):
  File "/home/waljt/Desktop/PyPLANE/PyPLANE/ui_main_window.py", line 310, in plot_button_clicked
    if self.required_fields_full(phase_coords, passed_params):
  File "/home/waljt/Desktop/PyPLANE/PyPLANE/ui_main_window.py", line 358, in required_fields_full
    if self.params_undefined(var, phase_coords, eqn, passed_params):
  File "/home/waljt/Desktop/PyPLANE/PyPLANE/ui_main_window.py", line 388, in params_undefined
    ode = DifferentialEquation(dep_var, phase_coords, ode_str)
  File "/home/waljt/Desktop/PyPLANE/PyPLANE/equations.py", line 47, in __init__
    for s in self.expr.free_symbols
  File "/home/waljt/Desktop/PyPLANE/env/lib/python3.6/site-packages/sympy/core/basic.py", line 528, in free_symbols
    return set().union(*[a.free_symbols for a in self.args])
TypeError: 'bool' object is not iterable
Aborted (core dumped)

The problem seems to be that C is, or at least was, a module or method defined somewhere in the SymPy package. I'm not sure why this is happening though, because there's no from sympy import * in any file, which I thought could cause such an issue. Could be something to do with how the parameters are being processed.

From the Sympy docs:
"Lastly, it is recommended that you not use I, E, S, N, C, O, or Q for variable or symbol names, as those are used for the imaginary unit (ii), the base of the natural logarithm (ee), the sympify() function (see Symbolic Expressions below), numeric evaluation (N() is equivalent to evalf() ), the big O order symbol (as in O(nlogn)O(nlog⁡n)), and the assumptions object that holds a list of supported ask keys (such as Q.real), respectively. You can use the mnemonic OSINEQ to remember what Symbols are defined by default in SymPy. Or better yet, always use lowercase letters for Symbol names. Python will not prevent you from overriding default SymPy names or functions, so be careful."
https://docs.sympy.org/latest/gotchas.html

Simple solution to this could be to comb through input and check if forbidden symbols exist in the input strings.

If they exist, slap up a pop-up warning each time plot button pressed until the offending symbols are removed

Merged simple fix to dev