Skip to content

Commit

Permalink
Support numpy 2.0 (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
YigitElma authored Nov 15, 2024
2 parents cc45766 + d45f5d3 commit 35ec831
Show file tree
Hide file tree
Showing 74 changed files with 31 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
source .venv-${{ matrix.python-version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.9.2
- name: Benchmark with pytest-benchmark (PR)
if: env.has_changes == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cache_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
source .venv-${{ matrix.python-version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.7.2
pip install matplotlib==3.9.2
- name: Cache Python environment
id: cache-env
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/jax_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
sed -i '1i\jax[cpu] == ${{ matrix.jax-version }}' ./requirements.txt
cat ./requirements.txt
pip install -r ./devtools/dev-requirements.txt
pip install matplotlib==3.7.2
- name: Verify dependencies
run: |
python --version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/notebook_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
source .venv-${{ matrix.python-version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.7.2
pip install matplotlib==3.9.2
- name: Test notebooks with pytest and nbmake
if: env.has_changes == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/regression_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
source .venv-${{ matrix.python-version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.7.2
pip install matplotlib==3.9.2
- name: Set Swap Space
if: env.has_changes == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
source .venv-${{ matrix.combos.python_version }}/bin/activate
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.7.2
pip install matplotlib==3.9.2
- name: Set Swap Space
if: env.has_changes == 'true'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/weekly_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r devtools/dev-requirements.txt
pip install matplotlib==3.9.2
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
Expand Down
4 changes: 3 additions & 1 deletion desc/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,9 @@ def zernike_radial_coeffs(l, m, exact=True):
# hence they are all integers. So, we can use exact arithmetic with integer
# division instead of floating point division.
# [1]https://en.wikipedia.org/wiki/Zernike_polynomials#Other_representations
coeffs[ii, s] = ((-1) ** ((ll - s) // 2) * factorial((ll + s) // 2)) // (
coeffs[ii, s] = (
int((-1) ** ((ll - s) // 2)) * factorial((ll + s) // 2)
) // (
factorial((ll - s) // 2)
* factorial((s + mm) // 2)
* factorial((s - mm) // 2)
Expand Down
26 changes: 16 additions & 10 deletions desc/magnetic_fields/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1816,10 +1816,10 @@ def from_mgrid(cls, mgrid_file, extcur=None, method="cubic", extrap=False):
ir = int(mgrid["ir"][()]) # number of grid points in the R coordinate
jz = int(mgrid["jz"][()]) # number of grid points in the Z coordinate
kp = int(mgrid["kp"][()]) # number of grid points in the phi coordinate
Rmin = mgrid["rmin"][()] # Minimum R coordinate (m)
Rmax = mgrid["rmax"][()] # Maximum R coordinate (m)
Zmin = mgrid["zmin"][()] # Minimum Z coordinate (m)
Zmax = mgrid["zmax"][()] # Maximum Z coordinate (m)
Rmin = mgrid["rmin"][()].filled() # Minimum R coordinate (m)
Rmax = mgrid["rmax"][()].filled() # Maximum R coordinate (m)
Zmin = mgrid["zmin"][()].filled() # Minimum Z coordinate (m)
Zmax = mgrid["zmax"][()].filled() # Maximum Z coordinate (m)
nfp = int(mgrid["nfp"][()]) # Number of field periods
Rgrid = np.linspace(Rmin, Rmax, ir)
Zgrid = np.linspace(Zmin, Zmax, jz)
Expand All @@ -1831,9 +1831,15 @@ def from_mgrid(cls, mgrid_file, extcur=None, method="cubic", extrap=False):
bz = np.zeros([kp, jz, ir, nextcur])
for i in range(nextcur):
coil_id = "%03d" % (i + 1,)
br[:, :, :, i] += mgrid["br_" + coil_id][()] # B_R radial magnetic field
bp[:, :, :, i] += mgrid["bp_" + coil_id][()] # B_phi toroidal field (T)
bz[:, :, :, i] += mgrid["bz_" + coil_id][()] # B_Z vertical magnetic field
br[:, :, :, i] += mgrid["br_" + coil_id][
()
].filled() # B_R radial magnetic field
bp[:, :, :, i] += mgrid["bp_" + coil_id][
()
].filled() # B_phi toroidal field (T)
bz[:, :, :, i] += mgrid["bz_" + coil_id][
()
].filled() # B_Z vertical magnetic field

# shift axes to correct order
br = np.moveaxis(br, (0, 1, 2), (1, 2, 0))
Expand All @@ -1849,13 +1855,13 @@ def from_mgrid(cls, mgrid_file, extcur=None, method="cubic", extrap=False):
coil_id = "%03d" % (i + 1,)
ar[:, :, :, i] += mgrid["ar_" + coil_id][
()
] # A_R radial mag. vec. potential
].filled() # A_R radial mag. vec. potential
ap[:, :, :, i] += mgrid["ap_" + coil_id][
()
] # A_phi toroidal mag. vec. potential
].filled() # A_phi toroidal mag. vec. potential
az[:, :, :, i] += mgrid["az_" + coil_id][
()
] # A_Z vertical mag. vec. potential
].filled() # A_Z vertical mag. vec. potential

# shift axes to correct order
ar = np.moveaxis(ar, (0, 1, 2), (1, 2, 0))
Expand Down
2 changes: 1 addition & 1 deletion devtools/dev-requirements_conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- matplotlib >= 3.5.0, < 4.0.0
- mpmath >= 1.0.0, < 2.0
- netcdf4 >= 1.5.4, < 2.0
- numpy >= 1.20.0, < 2.0
- numpy >= 1.20.0
- psutil
- scipy >= 1.7.0, < 2.0
- termcolor
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ interpax >= 0.3.3
matplotlib >= 3.5.0, < 4.0.0
mpmath >= 1.0.0, < 2.0
netcdf4 >= 1.5.4, < 2.0
numpy >= 1.20.0, < 2.0.0
numpy >= 1.20.0
nvgpu
orthax
plotly >= 5.16, < 6.0
psutil
pylatexenc >= 2.0, < 3.0
scipy >= 1.7.0, < 2.0.0
scipy >= 1.7.0
termcolor
2 changes: 1 addition & 1 deletion requirements_conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- matplotlib >= 3.5.0, < 4.0.0
- mpmath >= 1.0.0, < 2.0
- netcdf4 >= 1.5.4, < 2.0
- numpy >= 1.20.0, < 2.0
- numpy >= 1.20.0
- psutil
- scipy >= 1.7.0, < 2.0
- termcolor
Expand Down
Binary file modified tests/baseline/test_1d_elongation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_1d_iota.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_1d_iota_radial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_1d_logpsi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_1d_p.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_2d_g_rz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_2d_g_tz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_2d_logF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_2d_plot_Bn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_Redl_figures_2_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_Redl_figures_4_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_Redl_sfincs_QA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_Redl_sfincs_QH.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_Redl_sfincs_tokamak_benchmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_binormal_drift_bounce1d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_bounce1d_checks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_fsa_F_normalized.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_fsa_I.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_plot_1d_curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_plot_1d_surface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_plot_2d_surface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_plot_b_mag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_plot_basis_doublefourierseries.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_plot_basis_fourierseries.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_plot_basis_fourierzernike.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_plot_basis_powerseries.png
Binary file modified tests/baseline/test_plot_boozer_modes.png
Binary file modified tests/baseline/test_plot_boozer_modes_breaking_only.png
Binary file modified tests/baseline/test_plot_boozer_modes_max.png
Binary file modified tests/baseline/test_plot_boozer_modes_no_norm.png
Binary file modified tests/baseline/test_plot_boozer_surface.png
Binary file modified tests/baseline/test_plot_boundaries.png
Binary file modified tests/baseline/test_plot_boundary.png
Binary file modified tests/baseline/test_plot_boundary_surface.png
Binary file modified tests/baseline/test_plot_coefficients.png
Binary file modified tests/baseline/test_plot_comparison.png
Binary file modified tests/baseline/test_plot_comparison_different_NFPs.png
Binary file modified tests/baseline/test_plot_comparison_no_theta.png
Binary file modified tests/baseline/test_plot_con_basis.png
Binary file modified tests/baseline/test_plot_cov_basis.png
Binary file modified tests/baseline/test_plot_grid_cheb1.png
Binary file modified tests/baseline/test_plot_grid_cheb2.png
Binary file modified tests/baseline/test_plot_grid_jacobi.png
Binary file modified tests/baseline/test_plot_grid_linear.png
Binary file modified tests/baseline/test_plot_grid_ocs.png
Binary file modified tests/baseline/test_plot_grid_quad.png
Binary file modified tests/baseline/test_plot_logo.png
Binary file modified tests/baseline/test_plot_normF_2d.png
Binary file modified tests/baseline/test_plot_normF_section.png
Binary file modified tests/baseline/test_plot_omnigenous_field.png
Binary file modified tests/baseline/test_plot_poincare.png
Binary file modified tests/baseline/test_plot_qs_error.png
Binary file modified tests/baseline/test_plot_surfaces.png
Binary file modified tests/baseline/test_plot_surfaces_HELIOTRON.png
Binary file modified tests/baseline/test_plot_surfaces_no_theta.png
Binary file modified tests/baseline/test_plot_vmec_comparison.png
Binary file removed tests/baseline/test_qh_optimization3.png
Diff not rendered.
Binary file modified tests/baseline/test_section_F.png
Binary file modified tests/baseline/test_section_J.png
Binary file modified tests/baseline/test_section_logF.png
Binary file modified tests/baseline/test_trapped_fraction_Kim.png
3 changes: 2 additions & 1 deletion tests/test_stability_funs.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def get_vmec_data(path, quantity):
"""
f = Dataset(path)
rho = np.sqrt(f.variables["phi"] / np.array(f.variables["phi"])[-1])
phi = np.array(f.variables["phi"])
rho = np.sqrt(phi / phi[-1])
q = np.array(f.variables[quantity])
f.close()
return rho, q
Expand Down

0 comments on commit 35ec831

Please sign in to comment.