ECP-WarpX / WarpX

WarpX is an advanced electromagnetic & electrostatic Particle-In-Cell code.
https://ecp-warpx.github.io
Other
303 stars 191 forks source link

NumPy 2.0 Compatibility #5071

Closed ax3l closed 3 months ago

ax3l commented 3 months ago

With the latest NumPy 2.0 release, we need to make sure all our examples and Python scripts still work.

Seeing some tests fail in Conda-Forge https://github.com/conda-forge/warpx-feedstock/pull/86

e.g., running the laser_acceleration/PICMI_inputs_3d.py test:

+ /home/conda/feedstock_root/build_artifacts/warpx_1721445803976/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/bin/python Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py
Initializing AMReX (24.07)...
OMP initialized with 2 OMP threads
AMReX (24.07) initialized
Traceback (most recent call last):
  File "/home/conda/feedstock_root/build_artifacts/warpx_1721445803976/test_tmp/Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py", line 162, in <module>
    sim.initialize_warpx()
  File "/home/conda/feedstock_root/build_artifacts/warpx_1721445803976/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.10/site-packages/pywarpx/picmi.py", line 2213, in initialize_warpx
    pywarpx.warpx.init(mpi_comm, max_step=self.max_steps, stop_time=self.max_time)
  File "/home/conda/feedstock_root/build_artifacts/warpx_1721445803976/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.10/site-packages/pywarpx/WarpX.py", line 98, in init
    libwarpx.initialize(argv, mpi_comm=mpi_comm)
  File "/home/conda/feedstock_root/build_artifacts/warpx_1721445803976/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.10/site-packages/pywarpx/_libwarpx.py", line 131, in initialize
    self.warpx = self.libwarpx_so.get_instance()
RuntimeError: Unknown character . in Parser expression "np.float64(3e-14)"
ax3l commented 3 months ago

attn @dpgrote @RemiLehe @roelof-groenewald @EZoni @WeiqunZhang

I do not yet understand where the error exactly comes from :sweat_smile: Is this a np.float64 that is injected in an AMReX parser expression by accident? If someone sees it feel free to post here so we can address it.

ax3l commented 3 months ago

@dpgrote @WeiqunZhang I think this comes from the CLI arguments we pass from PICMI into AMReX, but cannot find where it comes from yet...

dpgrote commented 3 months ago

Testing numpy2, with repr, it returns "np.float64(3e-14)" instead of "3e-14" as was done in numpy1. The solution may be to use "str" instead of "repr" in the several places in Python/pywarpx/Bucket.py.

ax3l commented 3 months ago

Thanks @dpgrote, good catch! Shall I post a PR or do you want to?

ax3l commented 3 months ago

I assume the challenge is how to properly round numbers with many user-specified digits (float or exponential style) to strings without cropping them... I cannot see that repr does that better than str btw, which the inline comment suggests in Bucket.py)