Skip to content

Roadmap to version 2

Davide Sandonà edited this page Feb 28, 2023 · 3 revisions

The following page provides a list of improvements that would lead to version 2, and hopefully to the merging of this module into SymPy.

1 – Refactoring of *Series classes

Let’s consider the LineOver1DRangeSeries class, which represents a univariate function f(x). It can be evaluated using two strategies:

  1. adaptive algorithm, which searches for the best location where to evaluate function in order to create a smooth plot.
  2. uniform meshing, which discretizes the domain with N points and evaluates the function.

The LineInteractiveSeries class represents a univariate function f(x, a, b, …) where a, b, … are numerical parameters provided by widgets. For performance considerations, it evaluates the function using a uniform meshing strategy.

Realizing that f(x) is just a special case of f(x, a, b, …), code repetition introduced by interactive series classes can be reduced, maybe eliminated completely. Not only this would make the code easier to read, it also reduces the chances of introducing errors during bug fixes, because the same bug won’t be repeated over multiple classes.

The same is true for other classes, for example: Parametric2DLineSeries, Parametric2DLineInteractiveSeries and so on.

Let’s consider again a univariate parametric function, f(x, a, b, …). Currently, the evaluation range is given by x1 <= x <= x2, where x1, x2 are real numbers. Improvements can be made to make it fully parametric, such that x1=f(a, b, …) and x2=g(a, b, …): when a user changes the state of a widgets, the discretization range can change as well. This is particularly useful for physics and engineering problems, as it might give a way to further excluded non-physical solutions from a plot.

2 – Improve numerical evaluation

By default, numerical evaluation is performed with NumPy (which is very fast compared to mpmath or SymPy), though the user has the ability to chose the evaluation module.

Regardless of the module, the evaluation points are of type complex. If this was not the case, some NumPy functions might return NaN, which is unacceptable for a plotting module, for example f = lambda x: np.imag(np.sqrt(x)) with negative x. However, other NumPy functions like floor, ceil, … raise TypeError when receiving inputs of type complex. Whenever NumPy is unable to compute the task, the evaluation falls back to SymPy, which is very slow.

One way to improve it is to detect if the symbolic expression contains functions that require real arguments. If that’s the case, arguments should be casted to float.

Also, the adaptive evaluation and uniform meshing strategy could potentially be refactored in order to reduce code repetition.

3 – Interactive module

With this module we can create interactive plots with widgets. Currently, it leverages Holoviz’s Panel:

  • Pros:
    • Cross-platform as the interactive application runs on a browser.
    • The interactive application can use the full available space of the browser window.
    • It also runs in Jupyter Notebook.
  • Cons:
    • Launching simultaneously two or more interactive applications that share parameters on the same kernel is going to make the applications “collide”, as parameters are class attributes (this comes from Holoviz’s Panel and Param architecture). This problem affects mostly Jupyter Notebook, where users might study different expressions (hence different applications) using the same parameters.
    • Currently, when an interactive application is launched on a new browser window, it will use the entire available horizontal space, which might not be ideal.

Areas of improvements:

  1. Implement custom theming for the Panel application so that user can better use the amount of horizontal space in the browser window.
  2. See if it’s possible to solve the “collision” problem mentioned above.
  3. (Optional) Implement an ipywidgets-only version that would work solely on Jupyter Notebook. This would potentially solve the “collision” problem mentioned above.

4 – New functionalities

  • 2D and 3D linear operators (the effect of a matrix on a plane/3D space)
  • Phase portrait for Ordinary Differential Equations.
  • Improve plot_parametric_region to better visualize complex maps.
  • Animations: the backends are already capable to deal with interactive widgets (hence parameters). It shouldn’t be difficult to implement animation functionalities, in which a parameters changes from an initial value to a final value.

5 – Packaging

While the main plotting functionalities work just with sympy, numpy and matplotlib, the full plotting module relies on several other packages: panel, adaptive, bokeh, plotly, k3d, vtk… It has been observed that building a conda package with the full dependencies is difficult: most of the time the build succeed but the installation fails. Need to debug what’s wrong and improve it.

Clone this wiki locally