From 990e748d90b43fc2e0b08ecb4e147bf66052c43b Mon Sep 17 00:00:00 2001 From: deegan Date: Thu, 24 Oct 2024 14:56:18 +0200 Subject: [PATCH 01/10] key error if #896 --- pyphare/pyphare/pharein/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyphare/pyphare/pharein/simulation.py b/pyphare/pyphare/pharein/simulation.py index 97ed32615..ee15a0b77 100644 --- a/pyphare/pyphare/pharein/simulation.py +++ b/pyphare/pyphare/pharein/simulation.py @@ -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( From c736a9b1cfa5dc8c0ca1ac545cf97a12d8039070 Mon Sep 17 00:00:00 2001 From: deegan Date: Thu, 24 Oct 2024 14:56:31 +0200 Subject: [PATCH 02/10] disable test due to numpy shape mismatch --- tests/simulator/refinement/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/simulator/refinement/CMakeLists.txt b/tests/simulator/refinement/CMakeLists.txt index 178fc46e9..d411a11e0 100644 --- a/tests/simulator/refinement/CMakeLists.txt +++ b/tests/simulator/refinement/CMakeLists.txt @@ -10,7 +10,11 @@ endif() if(HighFive) ## These test use dump diagnostics so require HighFive! if(testMPI) - phare_mpi_python3_exec(9 2 simple_2d_refinement test_2d_2_core.py ${CMAKE_CURRENT_BINARY_DIR}) - phare_mpi_python3_exec(11 10 complex_2d_refinement test_2d_10_core.py ${CMAKE_CURRENT_BINARY_DIR}) + + + # phare_mpi_python3_exec(11 10 complex_2d_refinement test_2d_10_core.py ${CMAKE_CURRENT_BINARY_DIR}) endif(testMPI) + + phare_python3_exec(9 simple_2d_refinement test_2d_2_core.py ${CMAKE_CURRENT_BINARY_DIR}) + endif() From 3275fc7d53d265399a0fb3caae228c8dafc89dcb Mon Sep 17 00:00:00 2001 From: deegan Date: Thu, 24 Oct 2024 16:03:52 +0200 Subject: [PATCH 03/10] mpi functional tests --- tests/functional/harris/CMakeLists.txt | 7 ++++--- tests/functional/harris/harris_2d.py | 9 --------- tests/simulator/refinement/CMakeLists.txt | 3 ++- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/tests/functional/harris/CMakeLists.txt b/tests/functional/harris/CMakeLists.txt index afaf7b4d8..0c11d8b2b 100644 --- a/tests/functional/harris/CMakeLists.txt +++ b/tests/functional/harris/CMakeLists.txt @@ -8,10 +8,11 @@ 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 harris_2d.py ${CMAKE_CURRENT_BINARY_DIR}) endif(testMPI) + endif() diff --git a/tests/functional/harris/harris_2d.py b/tests/functional/harris/harris_2d.py index b9f06ced4..67725dabe 100644 --- a/tests/functional/harris/harris_2d.py +++ b/tests/functional/harris/harris_2d.py @@ -35,8 +35,6 @@ def config(): sim = ph.Simulation( - smallest_patch_size=15, - largest_patch_size=25, time_step_nbr=time_step_nbr, time_step=time_step, # boundary_types="periodic", @@ -155,13 +153,6 @@ def vthz(x, y): 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() if __name__ == "__main__": diff --git a/tests/simulator/refinement/CMakeLists.txt b/tests/simulator/refinement/CMakeLists.txt index d411a11e0..31772ce5d 100644 --- a/tests/simulator/refinement/CMakeLists.txt +++ b/tests/simulator/refinement/CMakeLists.txt @@ -11,8 +11,9 @@ if(HighFive) ## These test use dump diagnostics so require HighFive! if(testMPI) - + # disabled due to https://github.com/PHAREHUB/PHARE/issues/853 # phare_mpi_python3_exec(11 10 complex_2d_refinement test_2d_10_core.py ${CMAKE_CURRENT_BINARY_DIR}) + endif(testMPI) phare_python3_exec(9 simple_2d_refinement test_2d_2_core.py ${CMAKE_CURRENT_BINARY_DIR}) From a4040629ec9ec61ad6cc1d449596e9c5e8be9982 Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Thu, 24 Oct 2024 22:16:01 +0200 Subject: [PATCH 04/10] balancing harris by default --- tests/functional/harris/CMakeLists.txt | 2 +- tests/functional/harris/harris_2d_lb.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/harris/CMakeLists.txt b/tests/functional/harris/CMakeLists.txt index 0c11d8b2b..afe727b06 100644 --- a/tests/functional/harris/CMakeLists.txt +++ b/tests/functional/harris/CMakeLists.txt @@ -12,7 +12,7 @@ if(HighFive AND testMPI) ## These test use dump diagnostics so require HighFive! if(testMPI) - phare_mpi_python3_exec(11 4 harris_2d harris_2d.py ${CMAKE_CURRENT_BINARY_DIR}) + phare_mpi_python3_exec(11 6 harris_2d harris_2d_lb.py ${CMAKE_CURRENT_BINARY_DIR}) endif(testMPI) endif() diff --git a/tests/functional/harris/harris_2d_lb.py b/tests/functional/harris/harris_2d_lb.py index 1153b6e8b..26f791986 100644 --- a/tests/functional/harris/harris_2d_lb.py +++ b/tests/functional/harris/harris_2d_lb.py @@ -15,7 +15,7 @@ mpl.use("Agg") -SCOPE_TIMING = os.getenv("PHARE_SCOPE_TIMING", "True").lower() in ("true", "1", "t") +SCOPE_TIMING = os.getenv("PHARE_SCOPE_TIMING", "False").lower() in ("true", "1", "t") LOAD_BALANCE = os.getenv("LOAD_BALANCE", "True").lower() in ("true", "1", "t") cpp = cpp_lib() From 5288a5c685dee830debc292aeeb11aadf98b7dd8 Mon Sep 17 00:00:00 2001 From: deegan Date: Fri, 25 Oct 2024 11:15:28 +0200 Subject: [PATCH 05/10] allow import error --- tests/functional/harris/harris_2d_lb.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/functional/harris/harris_2d_lb.py b/tests/functional/harris/harris_2d_lb.py index 26f791986..465d51ea9 100644 --- a/tests/functional/harris/harris_2d_lb.py +++ b/tests/functional/harris/harris_2d_lb.py @@ -10,8 +10,8 @@ from pyphare.pharesee.run import Run from pyphare.simulator.simulator import Simulator, startMPI + from tests.simulator import SimulatorTest -from tools.python3 import plotting as m_plotting mpl.use("Agg") @@ -184,6 +184,15 @@ def plot(diag_dir): ) +def plot_runtimer(diag_dir, rank): + 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 - or phare src dir not in pythonpath") + + class HarrisTest(SimulatorTest): def __init__(self, *args, **kwargs): super(HarrisTest, self).__init__(*args, **kwargs) @@ -202,7 +211,7 @@ def test_run(self): if cpp.mpi_rank() == 0: plot(diag_dir) if SCOPE_TIMING: - m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank()) + plot_runtimer(diag_dir, cpp.mpi_rank()) cpp.mpi_barrier() return self From e41c5ef60526671bdfa115129ffe9af51ed01fbd Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Sun, 10 Nov 2024 15:57:51 +0100 Subject: [PATCH 06/10] more cores for harris --- tests/functional/harris/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/harris/CMakeLists.txt b/tests/functional/harris/CMakeLists.txt index afe727b06..7939ba208 100644 --- a/tests/functional/harris/CMakeLists.txt +++ b/tests/functional/harris/CMakeLists.txt @@ -12,7 +12,7 @@ if(HighFive AND testMPI) ## These test use dump diagnostics so require HighFive! if(testMPI) - phare_mpi_python3_exec(11 6 harris_2d harris_2d_lb.py ${CMAKE_CURRENT_BINARY_DIR}) + phare_mpi_python3_exec(11 10 harris_2d harris_2d_lb.py ${CMAKE_CURRENT_BINARY_DIR}) endif(testMPI) endif() From 45db18b726ff9a22354ae9c683772057054f8128 Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Sun, 10 Nov 2024 15:58:48 +0100 Subject: [PATCH 07/10] Update CMakeLists.txt --- tests/simulator/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/simulator/CMakeLists.txt b/tests/simulator/CMakeLists.txt index 86274d16f..edef7be5f 100644 --- a/tests/simulator/CMakeLists.txt +++ b/tests/simulator/CMakeLists.txt @@ -25,9 +25,12 @@ if(HighFive) # doesn't make sense in serial phare_mpi_python3_exec(9 3 load_balancing test_load_balancing.py ${CMAKE_CURRENT_BINARY_DIR}) - endif(testMPI) - phare_python3_exec(11, test_diagnostic_timestamps test_diagnostic_timestamps.py ${CMAKE_CURRENT_BINARY_DIR}) + else() + phare_python3_exec(11 test_diagnostic_timestamps test_diagnostic_timestamps.py ${CMAKE_CURRENT_BINARY_DIR}) + + endif(testMPI) + endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.py ${CMAKE_CURRENT_BINARY_DIR}/config.py @ONLY) From 175c4590299d00e6f224a50e5cab36fcf2f8bb47 Mon Sep 17 00:00:00 2001 From: dekken Date: Fri, 17 Jan 2025 20:24:57 +0100 Subject: [PATCH 08/10] smaller harris 1 level --- tests/functional/harris/CMakeLists.txt | 4 +- tests/functional/harris/harris_2d.py | 55 ++++---- ...harris_2d_lb.py => harris_2d_100_x_100.py} | 126 +++--------------- 3 files changed, 51 insertions(+), 134 deletions(-) rename tests/functional/harris/{harris_2d_lb.py => harris_2d_100_x_100.py} (51%) diff --git a/tests/functional/harris/CMakeLists.txt b/tests/functional/harris/CMakeLists.txt index 7939ba208..d6708cac0 100644 --- a/tests/functional/harris/CMakeLists.txt +++ b/tests/functional/harris/CMakeLists.txt @@ -12,7 +12,9 @@ if(HighFive AND testMPI) ## These test use dump diagnostics so require HighFive! if(testMPI) - phare_mpi_python3_exec(11 10 harris_2d harris_2d_lb.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}) + endif(testMPI) endif() diff --git a/tests/functional/harris/harris_2d.py b/tests/functional/harris/harris_2d.py index 67725dabe..8c824c96b 100644 --- a/tests/functional/harris/harris_2d.py +++ b/tests/functional/harris/harris_2d.py @@ -7,34 +7,25 @@ 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 -""" - - -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_setup(): + + 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) + + return ph.Simulation( + smallest_patch_size=15, + largest_patch_size=25, time_step_nbr=time_step_nbr, time_step=time_step, # boundary_types="periodic", @@ -51,6 +42,11 @@ def config(): strict=True, ) + +def config(sim = None, seed = 12334): + if not sim: + sim = default_setup() + def density(x, y): L = sim.simulation_domain()[1] return ( @@ -139,7 +135,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) @@ -155,5 +151,6 @@ def main(): Simulator(config()).run() + if __name__ == "__main__": main() diff --git a/tests/functional/harris/harris_2d_lb.py b/tests/functional/harris/harris_2d_100_x_100.py similarity index 51% rename from tests/functional/harris/harris_2d_lb.py rename to tests/functional/harris/harris_2d_100_x_100.py index 465d51ea9..0c638f525 100644 --- a/tests/functional/harris/harris_2d_lb.py +++ b/tests/functional/harris/harris_2d_100_x_100.py @@ -10,43 +10,52 @@ from pyphare.pharesee.run import Run from pyphare.simulator.simulator import Simulator, startMPI - from tests.simulator import SimulatorTest +from tools.python3 import plotting as m_plotting + +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 = (800, 800) +cells = (100, 100) +time_steps = 1000 time_step = 0.005 -final_time = 50 +final_time = time_step * time_steps timestamps = np.arange(0, final_time + time_step, final_time / 5) if cpp.mpi_rank() == 0: print(LOAD_BALANCE, "diag timestamps:", timestamps) -diag_dir = "phare_outputs/harris_lb" -if not LOAD_BALANCE: - diag_dir = "phare_outputs/harris" - +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(): - L = 0.5 - sim = ph.Simulation( time_step=time_step, final_time=final_time, cells=cells, dl=(0.40, 0.40), - refinement="tagging", - max_nbr_levels=2, + # refinement="tagging", + max_nbr_levels=1, nesting_buffer=1, clustering="tile", tag_buffer="1", @@ -56,91 +65,9 @@ def config(): "format": "phareh5", "options": {"dir": diag_dir, "mode": "overwrite"}, }, - restart_options={ - "dir": "checkpoints", - "mode": "overwrite", - "timestamps": timestamps, - # "restart_time": 0.0, - }, - ) - - def density(x, y): - Ly = sim.simulation_domain()[1] - return ( - 0.4 - + 1.0 / np.cosh((y - Ly * 0.3) / L) ** 2 - + 1.0 / np.cosh((y - Ly * 0.7) / L) ** 2 - ) - - def S(y, y0, l): - return 0.5 * (1.0 + np.tanh((y - y0) / l)) - - def by(x, y): - Lx = sim.simulation_domain()[0] - Ly = sim.simulation_domain()[1] - sigma = 1.0 - dB = 0.1 - - x0 = x - 0.5 * Lx - y1 = y - 0.3 * Ly - y2 = y - 0.7 * Ly - - dBy1 = 2 * dB * x0 * np.exp(-(x0**2 + y1**2) / (sigma) ** 2) - dBy2 = -2 * dB * x0 * np.exp(-(x0**2 + y2**2) / (sigma) ** 2) - - return dBy1 + dBy2 - - def bx(x, y): - Lx = sim.simulation_domain()[0] - Ly = sim.simulation_domain()[1] - sigma = 1.0 - dB = 0.1 - - x0 = x - 0.5 * Lx - y1 = y - 0.3 * Ly - y2 = y - 0.7 * Ly - - dBx1 = -2 * dB * y1 * np.exp(-(x0**2 + y1**2) / (sigma) ** 2) - dBx2 = 2 * dB * y2 * np.exp(-(x0**2 + y2**2) / (sigma) ** 2) - - v1 = -1 - v2 = 1.0 - return v1 + (v2 - v1) * (S(y, Ly * 0.3, L) - S(y, Ly * 0.7, L)) + dBx1 + dBx2 - - def bz(x, y): - return 0.0 - - def b2(x, y): - return bx(x, y) ** 2 + by(x, y) ** 2 + bz(x, y) ** 2 - - def T(x, y): - K = 0.7 - temp = 1.0 / density(x, y) * (K - b2(x, y) * 0.5) - assert np.all(temp > 0) - return temp - - def vxyz(x, y): - return 0.0 - - def vthxyz(x, y): - return np.sqrt(T(x, y)) - - vvv = {**{f"vbulk{c}": vxyz for c in "xyz"}, **{f"vth{c}": vthxyz for c in "xyz"}} - - ph.MaxwellianFluidModel( - bx=bx, by=by, bz=bz, protons={"charge": 1, "density": density, **vvv} ) - ph.ElectronModel(closure="isothermal", Te=0.0) - for quantity in ["E", "B"]: - ph.ElectromagDiagnostics(quantity=quantity, write_timestamps=timestamps) - for quantity in ["density", "bulkVelocity"]: - ph.FluidDiagnostics(quantity=quantity, write_timestamps=timestamps) - - ph.FluidDiagnostics( - quantity="density", write_timestamps=timestamps, population_name="protons" - ) - ph.InfoDiagnostics(quantity="particle_count") + sim = base.config(sim) if LOAD_BALANCE: ph.LoadBalancer(active=True, auto=True, mode="nppc", tol=0.05) @@ -184,15 +111,6 @@ def plot(diag_dir): ) -def plot_runtimer(diag_dir, rank): - 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 - or phare src dir not in pythonpath") - - class HarrisTest(SimulatorTest): def __init__(self, *args, **kwargs): super(HarrisTest, self).__init__(*args, **kwargs) @@ -211,7 +129,7 @@ def test_run(self): if cpp.mpi_rank() == 0: plot(diag_dir) if SCOPE_TIMING: - plot_runtimer(diag_dir, cpp.mpi_rank()) + m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank()) cpp.mpi_barrier() return self From 69bc76bb704f0d9af95110966047b88f9cd6ece0 Mon Sep 17 00:00:00 2001 From: dekken Date: Sat, 18 Jan 2025 17:32:50 +0100 Subject: [PATCH 09/10] ++ --- tests/functional/harris/CMakeLists.txt | 1 + tests/functional/harris/harris_2d.py | 29 ++-- .../functional/harris/harris_2d_100_x_100.py | 17 ++- .../harris/harris_2d_100_x_100_slow.py | 141 ++++++++++++++++++ 4 files changed, 170 insertions(+), 18 deletions(-) create mode 100644 tests/functional/harris/harris_2d_100_x_100_slow.py diff --git a/tests/functional/harris/CMakeLists.txt b/tests/functional/harris/CMakeLists.txt index d6708cac0..1cbb8723f 100644 --- a/tests/functional/harris/CMakeLists.txt +++ b/tests/functional/harris/CMakeLists.txt @@ -14,6 +14,7 @@ if(HighFive AND testMPI) if(testMPI) 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) diff --git a/tests/functional/harris/harris_2d.py b/tests/functional/harris/harris_2d.py index 8c824c96b..9ffd88576 100644 --- a/tests/functional/harris/harris_2d.py +++ b/tests/functional/harris/harris_2d.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -import os + import numpy as np import pyphare.pharein as ph @@ -8,21 +8,26 @@ from pyphare.simulator.simulator import startMPI -def default_setup(): +ph.NO_GUI() +cpp = cpp_lib() - 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 +diag_outputs = "phare_outputs/test/harris/2d" +time_step_nbr = 1000 +time_step = 0.001 +final_time = time_step * time_step_nbr + + +def default_timestamps(): dt = 10 * time_step nt = final_time / dt + 1 timestamps = dt * np.arange(nt) + +def default_setup(): + startMPI() + return ph.Simulation( smallest_patch_size=15, largest_patch_size=25, @@ -43,9 +48,11 @@ def default_setup(): ) -def config(sim = None, seed = 12334): - if not sim: +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] diff --git a/tests/functional/harris/harris_2d_100_x_100.py b/tests/functional/harris/harris_2d_100_x_100.py index 0c638f525..041155be8 100644 --- a/tests/functional/harris/harris_2d_100_x_100.py +++ b/tests/functional/harris/harris_2d_100_x_100.py @@ -35,14 +35,10 @@ startMPI() cells = (100, 100) -time_steps = 1000 +final_time = 50 time_step = 0.005 -final_time = time_step * time_steps timestamps = np.arange(0, final_time + time_step, final_time / 5) -if cpp.mpi_rank() == 0: - print(LOAD_BALANCE, "diag timestamps:", timestamps) - diag_dir = "phare_outputs/harris_2d_100_x_100" plot_dir = Path(f"{diag_dir}_plots") plot_dir.mkdir(parents=True, exist_ok=True) @@ -55,7 +51,7 @@ def config(): cells=cells, dl=(0.40, 0.40), # refinement="tagging", - max_nbr_levels=1, + # max_nbr_levels=1, nesting_buffer=1, clustering="tile", tag_buffer="1", @@ -67,7 +63,14 @@ def config(): }, ) - sim = base.config(sim) + 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) diff --git a/tests/functional/harris/harris_2d_100_x_100_slow.py b/tests/functional/harris/harris_2d_100_x_100_slow.py new file mode 100644 index 000000000..3da5869d3 --- /dev/null +++ b/tests/functional/harris/harris_2d_100_x_100_slow.py @@ -0,0 +1,141 @@ +#!/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.pharesee.run import Run +from pyphare.simulator.simulator import Simulator, startMPI + +from tests.simulator import SimulatorTest +from tools.python3 import plotting as m_plotting + +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), + # refinement="tagging", + # max_nbr_levels=1, + 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 + + +def plot_file_for_qty(qty, time): + return f"{plot_dir}/harris_{qty}_t{time}.png" + + +def plot(diag_dir): + run = Run(diag_dir) + for time in timestamps: + run.GetDivB(time).plot( + filename=plot_file_for_qty("divb", time), + plot_patches=True, + vmin=1e-11, + vmax=2e-10, + ) + run.GetRanks(time).plot( + filename=plot_file_for_qty("Ranks", time), + plot_patches=True, + ) + run.GetN(time, pop_name="protons").plot( + filename=plot_file_for_qty("N", time), + plot_patches=True, + ) + for c in ["x", "y", "z"]: + run.GetB(time).plot( + filename=plot_file_for_qty(f"b{c}", time), + qty=f"{c}", + plot_patches=True, + ) + run.GetJ(time).plot( + filename=plot_file_for_qty("jz", time), + qty="z", + plot_patches=True, + vmin=-2, + vmax=2, + ) + + +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): + self.register_diag_dir_for_cleanup(diag_dir) + Simulator(config()).run().reset() + if cpp.mpi_rank() == 0: + plot(diag_dir) + if SCOPE_TIMING: + m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank()) + cpp.mpi_barrier() + return self + + +if __name__ == "__main__": + HarrisTest().test_run().tearDown() From 0c503d33096e171a056f7a27af219ad07cf65eb2 Mon Sep 17 00:00:00 2001 From: dekken Date: Sat, 18 Jan 2025 18:36:27 +0100 Subject: [PATCH 10/10] ++ --- tests/functional/harris/harris_2d_100_x_100.py | 10 ++++++++-- tests/functional/harris/harris_2d_100_x_100_slow.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/functional/harris/harris_2d_100_x_100.py b/tests/functional/harris/harris_2d_100_x_100.py index 041155be8..ecc6cdbb1 100644 --- a/tests/functional/harris/harris_2d_100_x_100.py +++ b/tests/functional/harris/harris_2d_100_x_100.py @@ -11,7 +11,6 @@ from pyphare.simulator.simulator import Simulator, startMPI from tests.simulator import SimulatorTest -from tools.python3 import plotting as m_plotting import harris_2d as base @@ -131,8 +130,15 @@ def test_run(self): Simulator(config()).run().reset() if cpp.mpi_rank() == 0: plot(diag_dir) + if SCOPE_TIMING: - m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank()) + 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`") + cpp.mpi_barrier() return self diff --git a/tests/functional/harris/harris_2d_100_x_100_slow.py b/tests/functional/harris/harris_2d_100_x_100_slow.py index 3da5869d3..cb744940c 100644 --- a/tests/functional/harris/harris_2d_100_x_100_slow.py +++ b/tests/functional/harris/harris_2d_100_x_100_slow.py @@ -11,7 +11,6 @@ from pyphare.simulator.simulator import Simulator, startMPI from tests.simulator import SimulatorTest -from tools.python3 import plotting as m_plotting import harris_2d as base @@ -131,8 +130,15 @@ def test_run(self): Simulator(config()).run().reset() if cpp.mpi_rank() == 0: plot(diag_dir) + if SCOPE_TIMING: - m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank()) + 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`") + cpp.mpi_barrier() return self