Davide-sd / sympy-plot-backends

An improved plotting module for SymPy
https://sympy-plot-backends.readthedocs.io
BSD 3-Clause "New" or "Revised" License
45 stars 10 forks source link

Missing dependency "control" #46

Open JanB1 opened 4 weeks ago

JanB1 commented 4 weeks ago

I just got an exception when I tried to do a nyquist plot.

`RuntimeError Traceback (most recent call last) Cell In[4], line 1 ----> 1 spb.plot_nyquist(tfG)

File c:\Python312\Lib\site-packages\spb\plot_functions\control.py:1197, in plot_nyquist(*systems, kwargs) 1195 series = [] 1196 for s, l in systems: -> 1197 series.extend(nyquist(s, label=l, kwargs.copy())) 1198 kwargs.setdefault("xlabel", "Real axis") 1199 kwargs.setdefault("ylabel", "Imaginary axis")

File c:\Python312\Lib\site-packages\spb\graphics\control.py:1909, in nyquist(system, omega_limits, input, output, label, rendering_kw, m_circles, kwargs) 1744 def nyquist(system, omega_limits=None, input=None, output=None, 1745 label=None, rendering_kw=None, m_circles=False, kwargs): 1746 """Plots a Nyquist plot for the system over a (optional) frequency range. 1747 The curve is computed by evaluating the Nyquist segment along the positive 1748 imaginary axis, with a mirror image generated to reflect the negative (...) 1907 1908 """ -> 1909 control = _check_if_control_is_installed(force_stop=True) 1910 systems = _unpack_mimo_systems( 1911 system, 1912 "" if label is None else label, ... 63 "the evaluation." 64 ) 65 return use_control

RuntimeError: The control module is not installed. Can't proceed with the evaluation.`

Steps to reproduce:

  1. Install spb without installing Python Control Systems Library
  2. Follow steps in documentation to plot a Nyquist-Plot (https://sympy-plot-backends.readthedocs.io/en/latest/modules/plot_functions/control.html#spb.plot_functions.control.plot_nyquist)
  3. Error above occurs

If instead you install the Python Control Systems Library (https://python-control.readthedocs.io/en/0.10.1/intro.html#installation) and then try to plot again, the plot gets produced as expected.

Note: I would do a pull request myself, but I don't know exactly which version of control you at least need.

Davide-sd commented 3 weeks ago

Hello @JanB1 , thanks for reporting this.

I made a conscious decision to leave control out of the basic installation, which only installs the minimal libraries needed to get plotting of symbolic expressions:

https://github.com/Davide-sd/sympy-plot-backends/blob/9b9f7f6e42d8cb7d572f5b7da9827850f386e711/setup.py#L62-L69

However, you can choose to install all dependencies with pip install sympy_plot_backends[all], which includes control:

https://github.com/Davide-sd/sympy-plot-backends/blob/9b9f7f6e42d8cb7d572f5b7da9827850f386e711/setup.py#L13-L29

The main reason behind this choice is that I want to provide lightweight minimum installation option.

JanB1 commented 3 weeks ago

Okay, it was just a little bit unexpected, especially as the documentation for the control plots doesn't mention it, but only when you got further to the control module documentation does it mention it in the text.

But I didn't click that far as on the control plots page it said "Refer to Control for a general explanation about the underlying working principles, or if you are interested in a finer customization of what is shown on the plot." and frankly I wasn't really interested in the general explanation about the underlying working principles, it just referred to the doc of the specific plot directly.

Might have been an oversight on my end, or maybe you'd want to put a disclaimer directly on the control plots page that you need an additional package that isn't included?