Skip to content

Commit

Permalink
Change ubuntu version in CI to 22.04 instead of latest. Miniscule loo…
Browse files Browse the repository at this point in the history
…sening of a few test tolerances
  • Loading branch information
landreman committed Jan 21, 2025
1 parent d6bea2b commit f6e66b3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/extensive_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

env:
OMPI_ALLOW_RUN_AS_ROOT: 1
Expand Down
2 changes: 1 addition & 1 deletion ci/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
max-parallel: 5
matrix:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_optimizable.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def sum(self):
return np.sum(self.local_full_x)

def product(self):
return np.product(self.local_full_x)
return np.prod(self.local_full_x)

return_fn_map = {'sum': sum, 'prod': product}

Expand Down
2 changes: 1 addition & 1 deletion tests/geo/test_curve_optimizable.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def subtest_curve_length_optimisation(self, rotated):
print(' Final curve length: ', obj.J())
print(' Expected final length: ', 2 * np.pi * x0[0])
print(' objective function: ', prob.objective())
assert abs(obj.J() - 2 * np.pi * x0[0]) < 1e-8
np.testing.assert_allclose(obj.J(), 2 * np.pi * x0[0], rtol=0, atol=1e-8)

def test_curve_first_derivative(self):
for rotated in [True, False]:
Expand Down
16 changes: 8 additions & 8 deletions tests/geo/test_pm_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,17 @@ def test_Bn(self):
Nnorms = np.ravel(np.sqrt(np.sum(s.normal() ** 2, axis=-1)))
Ngrid = nphi * ntheta
Bn_Am = (pm_opt.A_obj.dot(pm_opt.m) - pm_opt.b_obj) * np.sqrt(Ngrid / Nnorms)
assert np.allclose(Bn_Am.reshape(nphi, ntheta), np.sum((bs.B() + b_dipole.B()).reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2))
np.testing.assert_allclose(Bn_Am.reshape(nphi, ntheta), np.sum((bs.B() + b_dipole.B()).reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2), atol=1e-15)

# check <Bn>
B_opt = np.mean(np.abs(pm_opt.A_obj.dot(pm_opt.m) - pm_opt.b_obj) * np.sqrt(Ngrid / Nnorms))
B_dipole_field = np.mean(np.abs(np.sum((bs.B() + b_dipole.B()).reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)))
assert np.isclose(B_opt, B_dipole_field)
np.testing.assert_allclose(B_opt, B_dipole_field)

# check integral Bn^2
f_B_Am = 0.5 * np.linalg.norm(pm_opt.A_obj.dot(pm_opt.m) - pm_opt.b_obj, ord=2) ** 2
f_B = SquaredFlux(s, b_dipole, -Bn).J()
assert np.isclose(f_B, f_B_Am)
np.testing.assert_allclose(f_B, f_B_Am)

# Create PM class with cylindrical bricks
Bn = np.sum(bs.B().reshape(nphi, ntheta, 3) * s.unitnormal(), axis=-1)
Expand All @@ -235,11 +235,11 @@ def test_Bn(self):
mmax_new = pm_opt.m_maxima / 2.0
kwargs_geo = {"dr": 0.15, "coordinate_flag": "cylindrical", "m_maxima": mmax_new}
pm_opt = PermanentMagnetGrid.geo_setup_between_toroidal_surfaces(s, Bn, s1, s2, **kwargs_geo)
assert np.allclose(pm_opt.m_maxima, mmax_new)
np.testing.assert_allclose(pm_opt.m_maxima, mmax_new)
mmax_new = pm_opt.m_maxima[-1] / 2.0
kwargs_geo = {"dr": 0.15, "coordinate_flag": "cylindrical", "m_maxima": mmax_new}
pm_opt = PermanentMagnetGrid.geo_setup_between_toroidal_surfaces(s, Bn, s1, s2, **kwargs_geo)
assert np.allclose(pm_opt.m_maxima, mmax_new)
np.testing.assert_allclose(pm_opt.m_maxima, mmax_new)
pm_opt = PermanentMagnetGrid.geo_setup_between_toroidal_surfaces(s, Bn, s1, s2)
_, _, _, = relax_and_split(pm_opt)
b_dipole = DipoleField(pm_opt.dipole_grid_xyz, pm_opt.m_proxy, nfp=s.nfp,
Expand All @@ -250,17 +250,17 @@ def test_Bn(self):
Nnorms = np.ravel(np.sqrt(np.sum(s.normal() ** 2, axis=-1)))
Ngrid = nphi * ntheta
Bn_Am = (pm_opt.A_obj.dot(pm_opt.m) - pm_opt.b_obj) * np.sqrt(Ngrid / Nnorms)
assert np.allclose(Bn_Am.reshape(nphi, ntheta), np.sum((bs.B() + b_dipole.B()).reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2))
np.testing.assert_allclose(Bn_Am.reshape(nphi, ntheta), np.sum((bs.B() + b_dipole.B()).reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2), atol=1e-15)

# check <Bn>
B_opt = np.mean(np.abs(pm_opt.A_obj.dot(pm_opt.m) - pm_opt.b_obj) * np.sqrt(Ngrid / Nnorms))
B_dipole_field = np.mean(np.abs(np.sum((bs.B() + b_dipole.B()).reshape((nphi, ntheta, 3)) * s.unitnormal(), axis=2)))
assert np.isclose(B_opt, B_dipole_field)
np.testing.assert_allclose(B_opt, B_dipole_field)

# check integral Bn^2
f_B_Am = 0.5 * np.linalg.norm(pm_opt.A_obj.dot(pm_opt.m) - pm_opt.b_obj, ord=2) ** 2
f_B = SquaredFlux(s, b_dipole, -Bn).J()
assert np.isclose(f_B, f_B_Am)
np.testing.assert_allclose(f_B, f_B_Am)

def test_grid_chopping(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/geo/test_surface_objectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def taylor_test1(f, df, x, epsilons=None, direction=None):
dfest = (fpluseps-fminuseps)/(2*eps)
err = np.linalg.norm(dfest - dfx)
print("taylor test1: ", err, err/err_old)
assert err < 1e-9 or err < 0.3 * err_old
np.testing.assert_array_less(err, max(1e-9, 0.31 * err_old))
err_old = err
print("###################################################################")

Expand Down

0 comments on commit f6e66b3

Please sign in to comment.