PyCoBi icon indicating copy to clipboard operation
PyCoBi copied to clipboard

ModuleNotFoundError: No module named 'system_equations'

Open 2BeAsh opened this issue 2 years ago • 9 comments

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.

2BeAsh avatar Aug 22 '24 08:08 2BeAsh

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!

Richert avatar Aug 22 '24 16:08 Richert

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.

2BeAsh avatar Aug 27 '24 05:08 2BeAsh

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:

  • the output MX in the TY column of the terminal output that Auto-07p generates indicates a failure to find a solution.
  • any parameter continuation that has only two points, one starting point (EP) and an end point (EP, UZ, or MX), cannot be plotted.
  • you can only plot parameter continuations that you have run previously. If you called ODESystem.run with the argument ICP=14 and name="cont_1", for example, and that was the only call of ODESystem.run that you did, then the only valid values for the arguments x and cont of ODEsystem.plot_continuation are x="PAR(14)" and cont="cont_1"

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.

Richert avatar Aug 28 '24 03:08 Richert

Hello there,

I am having the same problems.

When running from yaml : ModuleNotFoundError: No module named 'system_equations'. But it generates the f90 and ivp files.

So it works using ode = ODESystem(eq_file="system_equations", auto_dir=auto_dir).

But I have also only 2 points in the continuation, and an MX at the end.

It could be usefull to display in the example the correct output that we should obtain.

amrtn30 avatar Apr 16 '25 09:04 amrtn30

Hi,

I updated the version requirements for PyCoBi with respect to Python and NumPy. Can you confirm that the problem continues to exist for Python >= 3.9 and Numpy >= 2.0?

On my setup, running the example at https://github.com/pyrates-neuroscience/PyCoBi/blob/master/documentation/use_examples/qif_sfa.py works for Python = 3.11 and NumPy 2.2.

Richert avatar Apr 16 '25 23:04 Richert

With python 3.10.8 and numpy 2.2.4, the continuation seems to go further (10000 points). But there is still an error in ode, _ = ODESystem.from_yaml(model, auto_dir=auto_dir).

The complete log file : log.txt

amrtn30 avatar Apr 17 '25 06:04 amrtn30

Hi @amrtn30

what you are running there is a time integration and Auto-07p is not exactly build for that. While its functions are fine for finding an initial condition from which you can run parameter continuations, it does not allow time continuations that run for too long. Your system converged to a fixed point after like 1000 continuations steps. So you can savely choose NMX=2000 or something like that, which should prevent that error. That is, you wanna pass the keyword argument init_kwargs={"NMX": 2000} to the ODESystem.from_yaml method.

I will check what the default value is that PyRates sets for this parameter upon generation of the "c.ivp" meta parameter file and update it.

And - again - I recommend working with the use example at https://github.com/pyrates-neuroscience/PyCoBi/blob/master/documentation/use_examples/qif_sfa.py, since it comes with a downloadable Python script that I have run on my local setup and that works without any problems on my end.

Hope that helps!

Richert avatar Apr 17 '25 17:04 Richert

Hi @Richert,

thank you for your answer !

I will check that.

I tried the use example qif_sfa.py and it works.

amrtn30 avatar Apr 18 '25 09:04 amrtn30

Hi @2BeAsh,

I actually fixed this by installing meson using pip: pip install meson

and also installing ninja-build system package: sudo apt install ninja-build

Now you should not anymore get the error.

rknetemann avatar Apr 24 '25 15:04 rknetemann