Skip to content

Commit 88a4652

Browse files
authored
Pytest: SP Tolerances (BLAST-ImpactX#1215)
* Pytest: SP Tolerances * Update tests/python/test_impactx.py
1 parent 2697925 commit 88a4652

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

tests/python/test_impactx.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pytest
1212
from conftest import basepath
1313

14-
from impactx import ImpactX, distribution, elements
14+
from impactx import Config, ImpactX, distribution, elements
1515

1616
# FIXME in AMReX via https://github.com/AMReX-Codes/amrex/pull/3727
1717
# def test_impactx_module():
@@ -26,8 +26,16 @@ def validate_fodo(beam):
2626
"""see examples/fodo/analysis_fodo.py"""
2727
num_particles = beam.total_number_of_particles()
2828
assert num_particles == 10000
29-
atol = 0.0 # ignored
30-
rtol = 2.2 * num_particles**-0.5 # from random sampling of a smooth distribution
29+
if Config.precision == "SINGLE":
30+
atol = 0.0 # ignored
31+
rtol = (
32+
2.5 * num_particles**-0.5
33+
) # from random sampling of a smooth distribution
34+
else:
35+
atol = 0.0 # ignored
36+
rtol = (
37+
2.2 * num_particles**-0.5
38+
) # from random sampling of a smooth distribution
3139

3240
# in situ calculate the reduced beam characteristics
3341
rbc = beam.beam_moments()
@@ -160,7 +168,7 @@ def test_impactx_nofile():
160168

161169
# simulate full lattice but keep beam global position
162170
sim.track_particles()
163-
assert np.allclose([ref.s], [7.0])
171+
assert ref.s == pytest.approx(7.0)
164172

165173
# finalize simulation
166174
sim.finalize()

tests/python/test_lattice_select.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,9 @@ def test_complex_scenarios():
521521
quad.k *= 1.1 # Increase strength by 10%
522522

523523
# Verify modifications affected original elements
524-
assert lattice[1].k == 1.1 # qf1
525-
assert lattice[5].k == -1.1 # qd1
526-
assert lattice[7].k == 1.1 # qf2
524+
assert lattice[1].k == pytest.approx(1.1) # qf1
525+
assert lattice[5].k == pytest.approx(-1.1) # qd1
526+
assert lattice[7].k == pytest.approx(1.1) # qf2
527527

528528
# Scenario 3b: Find all quadrupoles and modify their strength (type-based)
529529
all_quads_type = lattice.select(kind=elements.Quad)
@@ -546,8 +546,8 @@ def test_complex_scenarios():
546546
bend.ds *= 0.9 # Decrease length by 10%
547547

548548
# Verify modifications
549-
assert lattice[3].ds == 0.9 # bend1
550-
assert lattice[9].ds == 0.9 # bend2
549+
assert lattice[3].ds == pytest.approx(0.9) # bend1
550+
assert lattice[9].ds == pytest.approx(0.9) # bend2
551551

552552
# Scenario 4b: Find all bends and modify their length (type-based)
553553
all_bends_type = lattice.select(kind=elements.Sbend)

0 commit comments

Comments
 (0)