Skip to content
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

Mpi nightly build trials #917

Open
wants to merge 10 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()
47 changes: 21 additions & 26 deletions tests/functional/harris/harris_2d.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
#!/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
"""


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)

Comment on lines +22 to +26
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix unused variable warning.

The timestamps variable is assigned but never used. Consider either returning or removing it.

 def default_timestamps():
     dt = 10 * time_step
     nt = final_time / dt + 1
-    timestamps = dt * np.arange(nt)
+    return dt * np.arange(nt)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def default_timestamps():
dt = 10 * time_step
nt = final_time / dt + 1
timestamps = dt * np.arange(nt)
def default_timestamps():
dt = 10 * time_step
nt = final_time / dt + 1
return dt * np.arange(nt)
🧰 Tools
🪛 Ruff (0.8.2)

25-25: Local variable timestamps is assigned to but never used

Remove assignment to unused variable timestamps

(F841)


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 +47,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 +142,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 @@ -155,13 +156,7 @@ 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__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,46 @@
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", "True").lower() in ("true", "1", "t")
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)
time_step = 0.005
cells = (100, 100)
final_time = 50
time_step = 0.005
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,
Comment on lines +52 to +53
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Commented parameters are actively used in other Harris tests

The commented-out parameters are actively used in other test files:

  • harris_2d.py uses both parameters: refinement="tagging", max_nbr_levels=1
  • tdtagged/td1dtagged.py uses different values: max_nbr_levels=3

No evidence found of these parameters being moved to a base configuration. Removing them might affect test consistency with other Harris simulations.

🔗 Analysis chain

Verify impact of disabled refinement parameters.

The commented-out parameters might affect simulation accuracy:

# refinement="tagging"
# max_nbr_levels=1

Please clarify if disabling these parameters is intentional and how it affects the simulation results.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check usage of refinement parameters in other tests
echo "Checking refinement parameter usage..."
rg -l "refinement.*tagging" tests/functional/
rg -l "max_nbr_levels" tests/functional/

Length of output: 455


Script:

#!/bin/bash
# Look for base config file
echo "Searching for base config..."
fd "base.config"

# Check actual parameter usage
echo -e "\nChecking parameter usage in test files..."
rg "refinement.*=.*tagging" tests/functional/ -B2 -A2
rg "max_nbr_levels.*=.*\d+" tests/functional/ -B2 -A2

Length of output: 2761

nesting_buffer=1,
clustering="tile",
tag_buffer="1",
Expand All @@ -56,91 +60,16 @@ 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
sim = base.config(sim, timestamps)

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")

if LOAD_BALANCE:
ph.LoadBalancer(active=True, auto=True, mode="nppc", tol=0.05)
Expand Down Expand Up @@ -201,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

Expand Down
Loading
Loading