Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions tests/python/test_benchmark_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


@pytest.fixture(scope="function")
def sim():
def sim(request):
class SimContextManager:
def __enter__(self):
self.sim = ImpactX()
Expand All @@ -45,6 +45,11 @@ def __enter__(self):
self.sim.diagnostics = False # benchmarking
self.sim.slice_step_diagnostics = False

spin = getattr(
request, "param", False
) # default to False if not parametrized
self.sim.spin = spin

self.sim.init_grids()

beam = self.sim.particle_container()
Expand Down Expand Up @@ -75,7 +80,15 @@ def __enter__(self):
alpha_t=0.0,
)
)
self.sim.add_particles(bunch_charge_C, distr, npart)
if spin:
spin_vectors = distribution.SpinvMF(
0.4,
0.9,
0.1,
)
self.sim.add_particles(bunch_charge_C, distr, npart, spin_vectors)
else:
self.sim.add_particles(bunch_charge_C, distr, npart)
assert self.sim.particle_container().total_number_of_particles() == npart

self.sim.backup_beam = self.sim.particle_container().make_alike()
Expand Down Expand Up @@ -129,6 +142,7 @@ def test_CFbend(benchmark, sim):
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)


@pytest.mark.parametrize("sim", [True, False], indirect=True, ids=["spin", "nospin"])
def test_ChrDrift(benchmark, sim):
chrdrift = elements.ChrDrift(name="drift1", ds=0.25, nslice=nslice)
benchmark.pedantic(chrdrift.push, setup=partial(pc_setup, sim), rounds=rounds)
Expand All @@ -141,6 +155,7 @@ def test_ChrPlasmaLens(benchmark, sim):
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)


@pytest.mark.parametrize("sim", [True, False], indirect=True, ids=["spin", "nospin"])
def test_ChrQuad(benchmark, sim):
el = elements.ChrQuad(name="quad1", ds=1.0, k=1.0, nslice=nslice)
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)
Expand All @@ -165,6 +180,7 @@ def test_DipEdge(benchmark, sim):
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)


@pytest.mark.parametrize("sim", [True, False], indirect=True, ids=["spin", "nospin"])
def test_Drift(benchmark, sim):
el = elements.Drift(name="drift1", ds=0.25, nslice=nslice)
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)
Expand All @@ -175,6 +191,7 @@ def test_Drift(benchmark, sim):
# benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)


@pytest.mark.parametrize("sim", [True, False], indirect=True, ids=["spin", "nospin"])
def test_ExactDrift(benchmark, sim):
el = elements.ExactDrift(name="drift1", ds=0.25, nslice=nslice)
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)
Expand Down Expand Up @@ -258,6 +275,7 @@ def test_PRot(benchmark, sim):
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)


@pytest.mark.parametrize("sim", [True, False], indirect=True, ids=["spin", "nospin"])
def test_Quad(benchmark, sim):
el = elements.Quad(name="quad1", ds=1.0, k=1.0, nslice=nslice)
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)
Expand Down Expand Up @@ -338,6 +356,7 @@ def test_RFCavity(benchmark, sim):
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)


@pytest.mark.parametrize("sim", [True, False], indirect=True, ids=["spin", "nospin"])
def test_Sbend(benchmark, sim):
el = elements.Sbend(name="sbend1", ds=0.5, rc=-10.346, nslice=nslice)
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)
Expand Down Expand Up @@ -446,6 +465,7 @@ def test_SoftSolenoid(benchmark, sim):
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)


@pytest.mark.parametrize("sim", [True, False], indirect=True, ids=["spin", "nospin"])
def test_Sol(benchmark, sim):
el = elements.Sol(name="sol1", ds=3.820395, ks=0.8223219329893234)
benchmark.pedantic(el.push, setup=partial(pc_setup, sim), rounds=rounds)
Expand Down
Loading