pyrates-neuroscience / PyCoBi

Python package for automated bifurcation analysis and parameter continuations, based on Auto-07p.
https://pycobi.readthedocs.io/en/latest/
GNU General Public License v3.0
21 stars 2 forks source link

ModuleNotFoundError: No module named 'system_equations' #3

Open 2BeAsh opened 3 months ago

2BeAsh commented 3 months ago

Issue

When trying to run this example on the documentation I get the following error: ModuleNotFoundError: No module named 'system_equations'

This might be an issue of pathing, as the file "system_equations.f90 is correctly produced in the same folder as my script. I should note that I'm running auto and PyCoBi using WSL, which I have minimal experience with, and that might be the real issue. I can use auto without PyCOBi just fine.

What I tried

In the example, I changed the auto_dir line to: auto_dir = "~/auto/07p/", as that is where I have installed auto. Not sure if it matters, but the script running the PyCoBi example is located in a directory ~/test_files/. I also tried adding ~/auto/07p/ to PATH. Further, I tried playing with the 'fortran_backend.py' file in which the error occurs, such as adding folders to path using the sys library's path.append - I of course made to remove any of those edits afterwards.

The full script

from pycobi import ODESystem

# path to YAML model definition
model = "model_templates.neural_mass_models.qif.qif"

# installation directory of auto-07p
auto_dir = "~/auto/07p/"

# ODESystem initialization
ode, _ = ODESystem.from_yaml(model, auto_dir=auto_dir)

Thanks in advance. This is the first posting an issue on GitHub, so I hope I'm doing it right. If not, let me know and I'll make any necessary edits. Have a nice day.

Richert commented 3 months ago

Hi!

indeed I suspect this to be an issue related to the particular Python kernel that you are using and the way that PyRates updates path variables to register newly created files. Most importantly, this is not happening within the PyCoBi package itself, but during the code generation process of PyRates.

Unfortunately, I have no experience with WSL either. What kind of Python environment are you using to run the example within WSL? Personally, I have had quite some issues with calling Auto-07p from a Python environment on Windows.

In any case, since the file system_equations.f90 has been created, you can just run

ode = ODESystem(eq_file="system_equations", auto_dir=auto_dir)

instead. That should allow you to run parameter continuations etc. via the ODESystem instance afterwards, if the Python-to-Auto interface works for you within WSL.

Let me know how it goes!

2BeAsh commented 3 months ago

Sorry for the late response.

I'm a bit unsure what you mean by "Python environment" and "kernel"? Again, new to the whole WSL/Linux stuff 😅. I tried downloading PyCoBi first using the ´python setup.py install´ but had some issues and went with pip instead. Do you mean my Python version and/or where it's downloaded? In that case, here's an image of it: image

Now your fix doing ode = ODESystem(eq_file="system_equations", auto_dir=auto_dir) worked and I am able to get this output: image However, new issues were raised. Again from the simple example, when I try to run ode.plot_continuation("PAR(14)", "U(1)", cont=0) I get the following error:

IndexError                                Traceback (most recent call last)
/tmp/ipykernel_8587/2465527202.py in <module>
----> 1 ode.plot_continuation("PAR(14)", "U(1)", cont=0)
      2 plt.show()

/usr/local/lib/python3.10/dist-packages/pycobi-0.8.8-py3.10.egg/pycobi/pycobi.py in plot_continuation(self, x, y, cont, ax, force_axis_lim_update, bifurcation_legend, **kwargs)
    660         # plot main continuation
    661         x_data, y_data = results[x], results[y]
--> 662         line_col = self._get_line_collection(x=x_data.values, y=y_data.values, stability=results['stability'], **kwargs)
    663         ax.add_collection(line_col)
    664         ax.autoscale()

/usr/local/lib/python3.10/dist-packages/pycobi-0.8.8-py3.10.egg/pycobi/pycobi.py in _get_line_collection(x, y, stability, line_style_stable, line_style_unstable, line_color_stable, line_color_unstable, **kwargs)
   1171             add_min = True
   1172         else:
-> 1173             y = np.reshape(y, (y.squeeze().shape[0], 1))
   1174             add_min = False
   1175         y = np.append(x, y, axis=1)

IndexError: tuple index out of range

Or when trying to run ode.plot_continuation('PAR(4)', 'U(1)', cont='eta') after ode.run(...), I get:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/tmp/ipykernel_8587/2170331206.py in <module>
----> 1 ode.plot_continuation('PAR(4)', 'U(1)', cont='eta')
      2 plt.show()

/usr/local/lib/python3.10/dist-packages/pycobi-0.8.8-py3.10.egg/pycobi/pycobi.py in plot_continuation(self, x, y, cont, ax, force_axis_lim_update, bifurcation_legend, **kwargs)
    641             results['bifurcation'] = np.asarray(['RG'] * len(results[x]))
    642         else:
--> 643             results, vmap = self.extract([x, y, 'stability', 'bifurcation'], cont=cont)
    644         x, y = vmap[x], vmap[y]
    645 

/usr/local/lib/python3.10/dist-packages/pycobi-0.8.8-py3.10.egg/pycobi/pycobi.py in extract(self, keys, cont, point)
    594         summary = self.get_summary(cont, point=point)
    595         columns = [k for k, _ in list(summary.keys())]
--> 596         keys_new = [key if key in columns else self._var_map_inv[key] for key in keys]
    597         key_map = {key_old: key_new for key_old, key_new in zip(keys, keys_new)}
    598         if point:

/usr/local/lib/python3.10/dist-packages/pycobi-0.8.8-py3.10.egg/pycobi/pycobi.py in <listcomp>(.0)
    594         summary = self.get_summary(cont, point=point)
    595         columns = [k for k, _ in list(summary.keys())]
--> 596         keys_new = [key if key in columns else self._var_map_inv[key] for key in keys]
    597         key_map = {key_old: key_new for key_old, key_new in zip(keys, keys_new)}
    598         if point:

KeyError: 'PAR(4)'

Similar errors occurred when I tried to do the Hopf Bifurcation example.

Thanks again for your time and aid.

Richert commented 3 months ago

Hi @2BeAsh ,

yeah from your output I can see that you are running an iPython kernel (see the first Traceback line in the outputs that you posted). Those typically run into that issue where the system_equations.f90 file cannot be found, because the updates to the Python environment variables made by PyRates are not recognized.

Regarding the issues you posted, a couple of things:

So based on that you will see that the first, automatic continuation over the time parameter ("PAR(14)") immediately fails. I am not quite sure whether that is somehow connected to the error after the file generation that you opened this issue for. It might be because it uses the default parameters that are stored in the file c.ivp that PyRates generated for you and there might be an issue with those.

I suggest that you set init_cont=False, i.e. ode = ODESystem(eq_file="system_equations", init_cont=False, ...). This will only generate the instance and not run any continuations yet. You could then run the initial continuation over time manually, following the steps in this example: https://pyrates.readthedocs.io/en/latest/auto_analysis/continuation.html#sphx-glr-auto-analysis-continuation-py

Let me know if you run into the same issue. Make sure that you adjust the parameters NDIM and NPAR when you call ODESystem.run to match the number of state variables and maximum number of parameters that you find in the equation file system_equations.f90.