Skip to content

Mpi nightly build trials #917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyphare/pyphare/pharein/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def check_diag_options(**kwargs):
diag_options["options"]["dir"], "diagnostics"
)
valid_modes = ["overwrite"]
if "mode" in diag_options["options"]:
if "options" in diag_options and "mode" in diag_options["options"]:
mode = diag_options["options"]["mode"]
if mode not in valid_modes:
raise ValueError(
Expand Down
10 changes: 7 additions & 3 deletions tests/functional/harris/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ if(NOT ${PHARE_PROJECT_DIR} STREQUAL ${CMAKE_BINARY_DIR})
endif()

if(HighFive AND testMPI)

## These test use dump diagnostics so require HighFive!
# exec level 11
# mpirun -n 10

if(testMPI)
phare_mpi_python3_exec(11 10 harris_2d harris_2d.py ${CMAKE_CURRENT_BINARY_DIR})

phare_mpi_python3_exec(11 4 harris_2d_100_x_100 harris_2d_100_x_100.py ${CMAKE_CURRENT_BINARY_DIR})
phare_mpi_python3_exec(11 4 harris_2d_100_x_100_slow harris_2d_100_x_100_slow.py ${CMAKE_CURRENT_BINARY_DIR})

endif(testMPI)

endif()
115 changes: 86 additions & 29 deletions tests/functional/harris/harris_2d.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
#!/usr/bin/env python3
import os

import numpy as np

import pyphare.pharein as ph
from pyphare.cpp import cpp_lib
from pyphare.simulator.simulator import Simulator
from pyphare.simulator.simulator import startMPI

os.environ["PHARE_SCOPE_TIMING"] = "1" # turn on scope timing
"""
For scope timings to work
The env var PHARE_SCOPE_TIMING must be == "1" (or "true")
See src/phare/phare.hpp
CMake must be configured with: -DwithPhlop=ON
And a LOG_LEVEL must be defined via compile args: -DPHARE_LOG_LEVEL=1
Or change the default value in src/core/logger.hpp
And phlop must be available on PYTHONPATH either from subprojects
or install phlop via pip
"""
from tests.simulator import SimulatorTest


ph.NO_GUI()
cpp = cpp_lib()
startMPI()


diag_outputs = "phare_outputs/test/harris/2d"
time_step_nbr = 1000
time_step = 0.001
final_time = time_step * time_step_nbr
dt = 10 * time_step
nt = final_time / dt + 1
timestamps = dt * np.arange(nt)


def config():
sim = ph.Simulation(
def default_timestamps():
dt = 10 * time_step
nt = final_time / dt + 1
timestamps = dt * np.arange(nt)
return timestamps


def default_setup():
startMPI()

return ph.Simulation(
smallest_patch_size=15,
largest_patch_size=25,
time_step_nbr=time_step_nbr,
Expand All @@ -53,6 +49,13 @@ def config():
strict=True,
)


def config(sim=None, timestamps=None, seed=12334):
if sim is None:
sim = default_setup()
if timestamps is None:
timestamps = default_timestamps()

def density(x, y):
L = sim.simulation_domain()[1]
return (
Expand Down Expand Up @@ -141,7 +144,7 @@ def vthz(x, y):
bx=bx,
by=by,
bz=bz,
protons={"charge": 1, "density": density, **vvv, "init": {"seed": 12334}},
protons={"charge": 1, "density": density, **vvv, "init": {"seed": seed}},
)

ph.ElectronModel(closure="isothermal", Te=0.0)
Expand All @@ -153,16 +156,70 @@ def vthz(x, y):
return sim


def main():
Simulator(config()).run()
try:
from tools.python3 import plotting as m_plotting

m_plotting.plot_run_timer_data(diag_outputs, cpp.mpi_rank())
except ImportError:
print("Phlop not found - install with: `pip install phlop`")
cpp.mpi_barrier()
def plot_file_for_qty(plot_dir, qty, time):
return f"{plot_dir}/harris_{qty}_t{time}.png"


class HarrisTest(SimulatorTest):
def __init__(self, *args, **kwargs):
super(HarrisTest, self).__init__(*args, **kwargs)
self.simulator = None

def tearDown(self):
super(HarrisTest, self).tearDown()
if self.simulator is not None:
self.simulator.reset()
self.simulator = None
ph.global_vars.sim = None

def test_run(self, diag_dir=None, sim=None):
diag_dir = diag_dir if diag_dir else diag_outputs
sim = sim if sim else config()
self.register_diag_dir_for_cleanup(diag_dir)
Simulator(sim).run().reset()
return self

def plot(self, timestamps, diag_dir, plot_dir):
run = self.getRun(diag_dir)
for time in timestamps:
run.GetDivB(time).plot(
filename=plot_file_for_qty(plot_dir, "divb", time),
plot_patches=True,
vmin=1e-11,
vmax=2e-10,
)
run.GetRanks(time).plot(
filename=plot_file_for_qty(plot_dir, "Ranks", time),
plot_patches=True,
)
run.GetN(time, pop_name="protons").plot(
filename=plot_file_for_qty(plot_dir, "N", time),
plot_patches=True,
)
for c in ["x", "y", "z"]:
run.GetB(time).plot(
filename=plot_file_for_qty(plot_dir, f"b{c}", time),
qty=f"{c}",
plot_patches=True,
)
run.GetJ(time).plot(
filename=plot_file_for_qty(plot_dir, "jz", time),
qty="z",
plot_patches=True,
vmin=-2,
vmax=2,
)

def scope_timing(self, diag_dir):
try:
from tools.python3 import plotting as m_plotting

m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank())
except ImportError:
print("Phlop not found - install with: `pip install phlop`")
except FileNotFoundError:
print("Phlop installed but not active")


if __name__ == "__main__":
main()
HarrisTest().test_run().tearDown()
90 changes: 90 additions & 0 deletions tests/functional/harris/harris_2d_100_x_100.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python3

import os
import numpy as np
import matplotlib as mpl
from pathlib import Path

import pyphare.pharein as ph
from pyphare.cpp import cpp_lib
from pyphare.simulator.simulator import startMPI

import harris_2d as base

mpl.use("Agg")

SCOPE_TIMING = os.getenv("PHARE_SCOPE_TIMING", "False").lower() in ("true", "1", "t")
"""
For scope timings to work
The env var PHARE_SCOPE_TIMING must be == "1" (or "true")
See src/phare/phare.hpp
CMake must be configured with: -DwithPhlop=ON
And a LOG_LEVEL must be defined via compile args: -DPHARE_LOG_LEVEL=1
Or change the default value in src/core/logger.hpp
And phlop must be available on PYTHONPATH either from subprojects
or install phlop via pip
"""

LOAD_BALANCE = os.getenv("LOAD_BALANCE", "True").lower() in ("true", "1", "t")

cpp = cpp_lib()
startMPI()

cells = (100, 100)
final_time = 50
time_step = 0.005
timestamps = np.arange(0, final_time + time_step, final_time / 5)

diag_dir = "phare_outputs/harris_2d_100_x_100"
plot_dir = Path(f"{diag_dir}_plots")
plot_dir.mkdir(parents=True, exist_ok=True)


def config():
sim = ph.Simulation(
time_step=time_step,
final_time=final_time,
cells=cells,
dl=(0.40, 0.40),
nesting_buffer=1,
clustering="tile",
tag_buffer="1",
hyper_resistivity=0.002,
resistivity=0.001,
diag_options={
"format": "phareh5",
"options": {"dir": diag_dir, "mode": "overwrite"},
},
)

sim = base.config(sim, timestamps)

for quantity in ["density", "bulkVelocity"]:
ph.FluidDiagnostics(quantity=quantity, write_timestamps=timestamps)

ph.FluidDiagnostics(
quantity="density", write_timestamps=timestamps, population_name="protons"
)

if LOAD_BALANCE:
ph.LoadBalancer(active=True, auto=True, mode="nppc", tol=0.05)

return sim


class HarrisTest(base.HarrisTest):
def __init__(self, *args, **kwargs):
super(HarrisTest, self).__init__(*args, **kwargs)

def test_run(self):
super(HarrisTest, self).test_run(diag_dir, config())
if cpp.mpi_rank() == 0:
self.plot(timestamps, diag_dir, plot_dir)

if SCOPE_TIMING:
self.scope_timing(diag_dir)
return self


if __name__ == "__main__":
HarrisTest().test_run().tearDown()
91 changes: 91 additions & 0 deletions tests/functional/harris/harris_2d_100_x_100_slow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env python3

import os
import numpy as np
import matplotlib as mpl
from pathlib import Path

import pyphare.pharein as ph

from pyphare.cpp import cpp_lib
from pyphare.simulator.simulator import startMPI

import harris_2d as base

mpl.use("Agg")

SCOPE_TIMING = os.getenv("PHARE_SCOPE_TIMING", "False").lower() in ("true", "1", "t")
"""
For scope timings to work
The env var PHARE_SCOPE_TIMING must be == "1" (or "true")
See src/phare/phare.hpp
CMake must be configured with: -DwithPhlop=ON
And a LOG_LEVEL must be defined via compile args: -DPHARE_LOG_LEVEL=1
Or change the default value in src/core/logger.hpp
And phlop must be available on PYTHONPATH either from subprojects
or install phlop via pip
"""

LOAD_BALANCE = os.getenv("LOAD_BALANCE", "True").lower() in ("true", "1", "t")

cpp = cpp_lib()
startMPI()

cells = (100, 100)
final_time = 50
time_step = 0.001
timestamps = np.arange(0, final_time + time_step, final_time / 5)

diag_dir = "phare_outputs/harris_2d_100_x_100_slow"
plot_dir = Path(f"{diag_dir}_plots")
plot_dir.mkdir(parents=True, exist_ok=True)


def config():
sim = ph.Simulation(
time_step=time_step,
final_time=final_time,
cells=cells,
dl=(0.40, 0.40),
nesting_buffer=1,
clustering="tile",
tag_buffer="1",
hyper_resistivity=0.002,
resistivity=0.001,
diag_options={
"format": "phareh5",
"options": {"dir": diag_dir, "mode": "overwrite"},
},
)

sim = base.config(sim, timestamps)

for quantity in ["density", "bulkVelocity"]:
ph.FluidDiagnostics(quantity=quantity, write_timestamps=timestamps)

ph.FluidDiagnostics(
quantity="density", write_timestamps=timestamps, population_name="protons"
)

if LOAD_BALANCE:
ph.LoadBalancer(active=True, auto=True, mode="nppc", tol=0.05)

return sim


class HarrisTest(base.HarrisTest):
def __init__(self, *args, **kwargs):
super(HarrisTest, self).__init__(*args, **kwargs)

def test_run(self):
super(HarrisTest, self).test_run(diag_dir, config())
if cpp.mpi_rank() == 0:
self.plot(timestamps, diag_dir, plot_dir)

if SCOPE_TIMING:
self.scope_timing(diag_dir)
return self


if __name__ == "__main__":
HarrisTest().test_run().tearDown()
Loading