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

Error: `invalid literal for int() with base 10` #1

Closed Dherse closed 3 months ago

Dherse commented 7 months ago

Hello,

I am currently trying to use PyCoBi to simulate non-linear effects in microring resonators for photonic neuromorphic computing and I am exploring continuation analysis of some of our (potential) neuron structures. I have rate equations obtained from the literature but I encounter the following errors in various scenarios:

My operator for my use case is the following:


# A simple MRR without graphene.
mrr_si_no_gr:
  base: OperatorTemplate
  equations:
    - "d/dt * a = Pin^0.5"
    - "d/dt * n = - n / tau + abs(a)^4."
  variables:
    a: output(0.0 + 0.0j)
    n: variable(1000000000000.0)
    Pin: input(0.0)
    tau: 0.0
    n_kerr: 0.0
    theta_fcd: 0.0
    gamma_fca: 0.0
    alpha_tpa: 0.0
    i: 0.0+1.0j

# A simple node with a single MRR.
MRRNODE:
  base: NodeTemplate
  operators:
    - mrr_si_no_gr

# Example circuit for Aashu's paper.
AASHU:
  base: CircuitTemplate
  nodes:
    mrr: MRRNODE
  edges:

And my current Python code is the following:

from pycobi import ODESystem
import numpy as np
import matplotlib.pyplot as plt

ode = ODESystem.from_yaml(
    "aashu/AASHU",
    working_dir="target/",
    auto_dir="~/auto-07p",
    node_vars={
        "mrr/mrr_si_no_gr/Pin": 19.54,
    }
)

Note that Aashu is a reference to the file name I gave to my YAML file since I am trying to recreate a paper from Aashu Jha, et al. I should also mention that this is a somewhat minimal reproduction example because the actual rate equations are much longer and more complicated.

As far as I know, I am using the latest version of the library, of auto-07b, and Python 3.10.14.

Richert commented 7 months ago

Hi!

Thank you for bringing this to my attention.

Here is a piece of code that I created based on what you provided above that runs without error using the most recent versions of PyCoBi and PyRates:

from pyrates import OperatorTemplate, NodeTemplate, CircuitTemplate
from pycobi import ODESystem

# create operator template
mrr_op = OperatorTemplate(name="mrr_op",
                          equations=["d/dt * a = p_in^(0.5)",
                                     "d/dt * n = - n / tau + abs(a)^4."],
                          variables={"a": "output(0.0 + 0.0j)",
                                     "n": "variable(1000000000000.0)",
                                     "p_in": "input(19.54)",
                                     "tau": 1.0,
                                     })

# create node template
mrr_node = NodeTemplate(name="mrr_node", operators=[mrr_op])

# create circuit template
mrr_net = CircuitTemplate(name="mrr", nodes={"p": mrr_node})

# create pycobi instance
ode = ODESystem.from_template(mrr_net, auto_dir="~/PycharmProjects/auto-07p", init_cont=False,
                              float_precision="complex64", working_dir="tmp")

Here, I used "tmp" as my working directory, so that would have to be altered for your setup. Hope that helps!

Best, Richard

tt386 commented 3 months ago

Hello,

I am executing the Use Examples for Parameter Continuations via PyCoBi example python file, qif_sfa.py found here in my linux terminal. The first figure is shown readily enough, but before the second can be generated I get the following error:

Traceback (most recent call last):
  File "/home/thomas/qif_sfa.py", line 75, in <module>
    eta_sols, eta_cont = ode.run(
  File "/home/thomas/anaconda3/lib/python3.10/site-packages/pycobi/pycobi.py", line 351, in run
    solution = self._call_auto(starting_point, origin, **auto_kwargs)
  File "/home/thomas/anaconda3/lib/python3.10/site-packages/pycobi/pycobi.py", line 1049, in _call_auto
    s, solution_name, _ = self.get_solution(point=starting_point, cont=origin)
  File "/home/thomas/anaconda3/lib/python3.10/site-packages/pycobi/pycobi.py", line 543, in get_solution
    solution_idx = int(solution_idx)
ValueError: invalid literal for int() with base 10: ''

Could this have occurred for a similar reason as above?

This is my first time ever raising an issue in GitHub, so please tell me if I've breached any etiquette.

Richert commented 3 months ago

Hi Thomas,

thank you for bringing this to my attention. Could you let me know which version of PyCoBi and PyRates you are running this with? When I run qif_sfa.py with the versions available on the master branches, I am not able to replicate that error.

PS: I pushed some changes to the master branches relatively recently that have not made it into an official release yet. Please let me know if that error appears with the most recent releases of PyCoBi and/or PyRates and I will make sure to release a new version with the fix ASAP.

PS2: To install from the master branch, you have to clone the repository from github and run python setup.py install from the directory in which you cloned the repository.

Let me know if that solves your problem!

Best, Richard

tt386 commented 3 months ago

Hi Richard,

The PyCoBi version is 0.8.7 The PyRates version is 1.0.6 I installed Auto and PyCoBi in the way suggested in the readme today.

I tried the method you suggested of cloning the master branch and running python setup.py install inside . I return to my qif_sfa.py and get the same error - even when I redo his in a fresh conda environment.

Cheers, Thomas

Richert commented 3 months ago

Hi Thomas,

Are you sure you are running things with the proper conda environment being activated? Because the error that you are receiving should not be possible to occur in isolation for the most recent version of the code on the master branch. If you look at line 543 of https://github.com/pyrates-neuroscience/PyCoBi/blob/master/pycobi/pycobi.py you will see that the ValueError that you are receiving is caught be an except ValueError statement in line 574.

So at the very least there should be another error that occurs somewhere between lines 577-579 that qif_sfa.py ran into after running into the ValueError in line 543.

Best, Richard

tt386 commented 3 months ago

Hi Richard,

You are absolutely correct - in order to sidestep debugging issues previously I had created a conda environment with a similar name previously, and entered the wrong one. Everything works now! Thank you very much.

Richert commented 3 months ago

Glad to hear it and happy to help!