Skip to content

Simulations with v1.0.3 not working due to multiprocessing & numpy.int deprecation #270

@dvbuka

Description

@dvbuka

I was hoping to use cayenne for a research project, but I ran into some issues. I ended up figuring out some workarounds that I detailed below.

  • cayenne version: 1.0.3
  • Python version: 3.10.12 (Colab) & 3.11.15 (macOS)
  • Operating System: Linux (Colab) & macOS Sonoma 14.5

Description

I installed cayenne using pip and ran the example code under usage. It did not work and to confirm it was not my environment, I also tried using Google Colab using !pip install cayenne, which also did not run.

What I Did

Without changes, the package has this error (this output is from Colab, but the rest are from my macOS device):

AttributeError                            Traceback (most recent call last)
<ipython-input-3-9921b515f7e5> in <cell line: 17>()
     15         C = 0;
     16     """
---> 17 sim = Simulation.load_model(model_str, "ModelString")
     18 # Run the simulation
     19 sim.simulate(max_t=40, max_iter=1000, n_rep=10)

4 frames
/usr/local/lib/python3.10/dist-packages/numpy/__init__.py in __getattr__(attr)
    317 
    318         if attr in __former_attrs__:
--> 319             raise AttributeError(__former_attrs__[attr])
    320 
    321         if attr == 'testing':

AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

As the package requirements specify a version of NumPy >1.20, this appears to be an issue with cayenne. After removing references to np.int() (output is truncated and I removed the full path of the files):

File "/cayenne-master/tests/cayenne/simulation.py", line 362, in simulate
    with mp.Pool(processes=n_procs) as pool:
...
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

        To fix this issue, refer to the "Safe importing of main module"
        section in https://docs.python.org/3/library/multiprocessing.html
...

After I had replaced the mp.Pool reference in simulation.py with results = map(algo_func, algo_args), I had the error:

Traceback (most recent call last):
  File "/cayenne-master/tests/test_example.py", line 17, in <module>
    sim.simulate(max_iter=51, n_rep=1)
  File "/cayenne-master/tests/cayenne/simulation.py", line 363, in simulate
    for t, X, status in results:
  File "/cayenne-master/tests/cayenne/simulation.py", line 22, in wrapper
    return func(*x)
           ^^^^^^^^
TypeError: Argument 'seed' has incorrect type (expected int, got numpy.int64)

To fix this, I just cast sim_seeds[index] to int(), and cayenne compiled and worked with the example.

Summarized, these were my temporary fixes to get the package working:

  • rewriting np.int references as int
  • replacing the mp.Pool reference in simulation.py with results = map(algo_func, algo_args)
  • wrapping sim_seeds[index] with int()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions