OceanParcels / parcels

Main code for Parcels (Probably A Really Computationally Efficient Lagrangian Simulator)
http://www.oceanparcels.org
MIT License
287 stars 122 forks source link

numpy random randint #1594

Closed lucvandenbulcke closed 2 days ago

lucvandenbulcke commented 3 weeks ago

I'm trying to use MPI to speed up a simulation. I'm using Python 3.12 and Parcels 3.0

The simulations halts with the error: File ".../envs/parcels/lib/python3.12/site-packages/parcels/particledata.py", line 40, in partitionParticlesMPI_default mpiProcs = np.randint(0, mpi_size, size=coords.shape[0]) ^^^^^^^^^^ AttributeError: module 'numpy' has no attribute 'randint'. Did you mean: 'gradient'?

In particledata.py, I replaced np.randint(...) with np.random.randint(...), which made it work

erikvansebille commented 3 weeks ago

Thanks for bringing this up @lucvandenbulcke, this could be another issue with the new NumPy 2.0.0 release? Just like https://github.com/OceanParcels/parcels/pull/1589 which we patched in v3.0.4.

Would you want to create a PR with this change from np.randint(...) to np.random.randint(...)? And perhaps check if there are other instances of this old use too? Or would you prefer if I create this PR?

erikvansebille commented 3 weeks ago

And perhaps check if there are other instances of this old use too?

Actually I juist checked, and this seems to be the only place in the parcels code where a numpy-random function is not called as np.random.funcname(), so only this change needs to be done

lucvandenbulcke commented 3 weeks ago

I checked as well (before seeing your latest answer), and confirm it's the only place. I can try and create a branch and the PR.

lucvandenbulcke commented 3 weeks ago

I think that I can't create a branch : luc@thinkpad:/data/oceans/parcels$ git clone git@github.com:OceanParcels/parcels.git ... luc@thinkpad:/data/oceans/parcels$ cd parcels/ luc@thinkpad:/data/oceans/parcels/parcels$ git checkout -b lucvandenbulcke-numpy-bug Switched to a new branch 'lucvandenbulcke-numpy-bug' luc@thinkpad:/data/oceans/parcels/parcels$ git push origin lucvandenbulcke-numpy-bug ERROR: Permission to OceanParcels/parcels.git denied to lucvandenbulcke. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

I don't know how else I should create a pull request -- I guess it's not worth to create a fork just for this. Apart from this, I made scripts using parcels, that I could share on github if it's useful for anybody (but I don't know where exactly).

VeckoTheGecko commented 2 days ago

Hi @lucvandenbulcke. This bug has now been patched in #1604. If you'd like to use these changes, please follow the development installation instructions outlined in the "Installation for developers" section of our documentation.

These changes will be available through conda in the next release.