From d2ec78900beae5e3ce79c25c9a1453aa6da9c41b Mon Sep 17 00:00:00 2001 From: deegan Date: Tue, 13 Jan 2026 12:57:52 +0100 Subject: [PATCH 1/6] lib per sim permutation --- .github/workflows/cmake_macos.yml | 90 ------------ CMakeLists.txt | 2 +- pyphare/pyphare/cpp/__init__.py | 45 ++++-- pyphare/pyphare/cpp/validate.py | 8 +- pyphare/pyphare/data/wrangler.py | 17 +-- pyphare/pyphare/pharesee/hierarchy/fromh5.py | 3 +- pyphare/pyphare/pharesee/particles.py | 6 +- pyphare/pyphare/simulator/simulator.py | 58 +++----- res/__tc/clang/0_config.sh | 6 + res/__tc/clang/1_build.sh | 20 +++ res/__tc/clang/2_test.sh | 27 ++++ res/__tc/clang/3_test_mpi.sh | 31 ++++ res/__tc/clang_samraisub/0_config.sh | 6 + res/__tc/clang_samraisub/1_build.sh | 15 ++ res/__tc/clang_samraisub/2_test.sh | 19 +++ res/__tc/gcc/0_config.sh | 6 + res/__tc/gcc/1_build.sh | 17 +++ res/__tc/gcc/2_test.sh | 19 +++ res/__tc/gcc/3_test_mpi.sh | 23 +++ res/__tc/gcc_samraisub/0_config.sh | 6 + res/__tc/gcc_samraisub/1_build.sh | 14 ++ res/__tc/gcc_samraisub/2_test.sh | 19 +++ res/__tc/nightly/0_config.sh | 6 + res/__tc/nightly/1_build.sh | 14 ++ res/__tc/nightly/2_test.sh | 19 +++ res/__tc/nightly/3_test_mpi.sh | 24 +++ res/cmake/bench.cmake | 1 - res/cmake/dep/samrai.cmake | 72 ++++----- res/cmake/options.cmake | 8 + res/sim/all.txt | 23 +++ src/amr/CMakeLists.txt | 13 +- src/amr/data/particles/particles_data.hpp | 9 +- .../load_balancing/load_balancer_manager.hpp | 16 +- src/amr/multiphysics_integrator.hpp | 3 +- .../resources_manager/resources_manager.hpp | 23 ++- src/amr/samrai.cpp | 60 ++++++++ src/amr/samrai.hpp | 53 +++++++ src/amr/wrappers/hierarchy.hpp | 60 ++++++-- src/amr/wrappers/integrator.hpp | 3 + src/core/data/grid/gridlayout.hpp | 1 - src/core/utilities/meta/meta_utilities.hpp | 24 ++- src/diagnostic/CMakeLists.txt | 3 +- src/phare/CMakeLists.txt | 21 +-- src/phare/phare.cpp | 2 +- src/phare/phare.hpp | 72 --------- src/python3/CMakeLists.txt | 34 +++-- src/python3/cpp_etc.cpp | 65 ++++++++- src/python3/cpp_simulator.cpp | 22 ++- src/python3/cpp_simulator.hpp | 137 +++++------------- src/python3/patch_level.hpp | 2 + src/simulator/simulator.hpp | 20 +-- .../amr/data/field/coarsening/CMakeLists.txt | 1 + tests/amr/data/field/copy_pack/CMakeLists.txt | 1 + tests/amr/data/field/geometry/CMakeLists.txt | 1 + tests/amr/data/field/refine/CMakeLists.txt | 6 +- .../field/time_interpolate/CMakeLists.txt | 1 + tests/amr/data/field/variable/CMakeLists.txt | 1 + tests/amr/data/particles/copy/CMakeLists.txt | 1 + .../particles/copy_overlap/CMakeLists.txt | 2 + .../data/particles/stream_pack/CMakeLists.txt | 1 + tests/amr/messengers/CMakeLists.txt | 3 +- tests/amr/messengers/test_messengers.cpp | 5 +- .../multiphysics_integrator/CMakeLists.txt | 3 +- tests/amr/tagging/CMakeLists.txt | 2 + tests/amr/tagging/test_tagging.cpp | 17 +-- tests/core/data/field/test_field.hpp | 9 +- tests/functional/alfven_wave/alfven_wave1d.py | 5 +- tests/functional/harris/harris_2d.py | 10 +- tests/functional/ionIonBeam/ion_ion_beam1d.py | 8 +- tests/functional/shock/shock.py | 17 ++- tests/functional/tdtagged/td1dtagged.py | 4 +- tests/simulator/__init__.py | 14 +- tests/simulator/data_wrangler.py | 8 - .../initialize/test_particles_init_1d.py | 3 +- tests/simulator/per_test.hpp | 4 +- tests/simulator/refined_particle_nbr.py | 18 +-- tests/simulator/refinement/test_2d_10_core.py | 9 +- tests/simulator/refinement/test_2d_2_core.py | 3 +- tests/simulator/test_advance.py | 8 +- tests/simulator/test_diagnostic_timestamps.py | 6 +- tests/simulator/test_diagnostics.py | 11 +- tests/simulator/test_initialization.py | 5 +- tests/simulator/test_load_balancing.py | 14 +- tests/simulator/test_restarts.py | 9 +- tests/simulator/test_run.py | 7 +- tests/simulator/test_tagging.py.off | 5 +- tests/simulator/test_validation.py | 3 - tools/bench/amr/data/particles/copy_data.cpp | 2 +- tools/bench/hi5/write_particles.cpp | 3 +- tools/bench/real/CMakeLists.txt | 14 -- tools/bench/real/bench_harris.py | 131 ----------------- tools/bench/real/sim/sim_2_1_4.cpp | 16 -- 92 files changed, 906 insertions(+), 752 deletions(-) delete mode 100644 .github/workflows/cmake_macos.yml create mode 100644 res/__tc/clang/0_config.sh create mode 100644 res/__tc/clang/1_build.sh create mode 100644 res/__tc/clang/2_test.sh create mode 100644 res/__tc/clang/3_test_mpi.sh create mode 100644 res/__tc/clang_samraisub/0_config.sh create mode 100644 res/__tc/clang_samraisub/1_build.sh create mode 100644 res/__tc/clang_samraisub/2_test.sh create mode 100644 res/__tc/gcc/0_config.sh create mode 100644 res/__tc/gcc/1_build.sh create mode 100644 res/__tc/gcc/2_test.sh create mode 100644 res/__tc/gcc/3_test_mpi.sh create mode 100644 res/__tc/gcc_samraisub/0_config.sh create mode 100644 res/__tc/gcc_samraisub/1_build.sh create mode 100644 res/__tc/gcc_samraisub/2_test.sh create mode 100644 res/__tc/nightly/0_config.sh create mode 100644 res/__tc/nightly/1_build.sh create mode 100644 res/__tc/nightly/2_test.sh create mode 100644 res/__tc/nightly/3_test_mpi.sh create mode 100644 res/sim/all.txt create mode 100644 src/amr/samrai.cpp create mode 100644 src/amr/samrai.hpp delete mode 100644 src/phare/phare.hpp delete mode 100644 tools/bench/real/CMakeLists.txt delete mode 100644 tools/bench/real/bench_harris.py delete mode 100644 tools/bench/real/sim/sim_2_1_4.cpp diff --git a/.github/workflows/cmake_macos.yml b/.github/workflows/cmake_macos.yml deleted file mode 100644 index 06332b4b9..000000000 --- a/.github/workflows/cmake_macos.yml +++ /dev/null @@ -1,90 +0,0 @@ -name: CMake MacOS - -# if issues with libquadmath appear again, see previous version: -# https://github.com/PHAREHUB/PHARE/blob/61ad57b285e875b396ecf8957e0579427ad6be30/.github/workflows/cmake_macos.yml - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -on: - pull_request: - workflow_dispatch: - -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ macos-14, macos-latest] - - steps: - - name: Build Info - run: | - uname -a - gcc -v - clang -v - - - name: CCache - id: cache - uses: actions/cache@v4 - with: - path: ~/.ccache - key: ${{ runner.os }}-ccache-${{ hashFiles('hashFile.txt') }} - restore-keys: ${{ runner.os }}-ccache- - - - name: Cache PIP (OSX) - uses: actions/cache@v4 - with: - path: ~/Library/Caches/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - - name: Clone PHARE - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - - uses: actions/setup-python@v4 - with: - python-version: '3.12.3' - - - name: Install system deps (openmpi, hdf5, ccache,...) - run: | - brew reinstall gcc - brew install open-mpi hdf5-mpi ccache - echo "/usr/local/opt/ccache/libexec" >> $GITHUB_PATH - - - name: Ensure ccache uses ~/.ccache - run: | - mkdir -p ~/.ccache - ccache --set-config=cache_dir=~/.ccache - ccache --get-config=cache_dir - - - name: Install python deps - run: | - python -m pip install --upgrade pip - python -m pip install -r requirements.txt - - - name: Create Build Environment - run: cmake -E make_directory ${{github.workspace}}/build - - - name: Configure CMake - working-directory: ${{github.workspace}}/build - run: | - cmake $GITHUB_WORKSPACE -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DENABLE_SAMRAI_TESTS=OFF -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DlowResourceTests=ON \ - -DCMAKE_CXX_FLAGS="-DPHARE_DIAG_DOUBLES=1 " - - - name: Build - working-directory: ${{github.workspace}}/build - run: cmake --build . -j 2 - - - name: Test - working-directory: ${{github.workspace}}/build - run: ctest -j 2 --output-on-failure - diff --git a/CMakeLists.txt b/CMakeLists.txt index 13281ee69..9b7636dde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON) include(CheckCXXCompilerFlag) -find_program(Git git) +find_program(Git git REQUIRED) find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED) set(PHARE_PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/pyphare/pyphare/cpp/__init__.py b/pyphare/pyphare/cpp/__init__.py index e654bef75..d9710f419 100644 --- a/pyphare/pyphare/cpp/__init__.py +++ b/pyphare/pyphare/cpp/__init__.py @@ -2,16 +2,29 @@ # # +import json +import importlib +from . import validate -def cpp_lib(override=None): - import importlib +__all__ = ["validate"] - return importlib.import_module("pybindlibs.cpp") +_libs = {} -def cpp_etc_lib(): - import importlib +def simulator_id(sim): + return f"{sim.ndim}_{sim.interp_order}_{sim.refined_particle_nbr}" + + +def cpp_lib(sim): + global _libs + mod_str = f"pybindlibs.cpp_{simulator_id(sim)}" + if mod_str not in _libs: + _libs[mod_str] = importlib.import_module(mod_str) + return _libs[mod_str] + + +def cpp_etc_lib(): return importlib.import_module("pybindlibs.cpp_etc") @@ -20,18 +33,24 @@ def build_config(): def build_config_as_json(): - import json - return json.dumps(build_config()) -def splitter_type(dim, interp, n_particles): - return getattr(cpp_lib(), f"Splitter_{dim}_{interp}_{n_particles}") +def splitter_type(sim): + return getattr(cpp_lib(sim), "Splitter") + + +def split_pyarrays_fn(sim): + return getattr(cpp_lib(sim), "split_pyarray_particles") + + +def mpi_rank(): + return getattr(cpp_etc_lib(), "mpi_rank")() -def create_splitter(dim, interp, n_particles): - return splitter_type(dim, interp, n_particles)() +def mpi_size(): + return getattr(cpp_etc_lib(), "mpi_size")() -def split_pyarrays_fn(dim, interp, n_particles): - return getattr(cpp_lib(), f"split_pyarray_particles_{dim}_{interp}_{n_particles}") +def mpi_barrier(): + return getattr(cpp_etc_lib(), "mpi_barrier")() diff --git a/pyphare/pyphare/cpp/validate.py b/pyphare/pyphare/cpp/validate.py index c80ba4c84..fad8825b3 100644 --- a/pyphare/pyphare/cpp/validate.py +++ b/pyphare/pyphare/cpp/validate.py @@ -99,8 +99,6 @@ def try_system_binaries(log_dir): def log_runtime_config(): - cpp_lib = cpp.cpp_lib() - settings = RuntimeSettings( python_binary=sys.executable, python_version=python_version_from(sys.executable), @@ -108,11 +106,11 @@ def log_runtime_config(): ) rank_info_dir = DOT_PHARE_DIR / "rank_info" - if cpp_lib.mpi_rank() == 0: + if cpp.mpi_rank() == 0: rank_info_dir.mkdir(exist_ok=True, parents=True) - cpp_lib.mpi_barrier() + cpp.mpi_barrier() - rank_dir = rank_info_dir / f"{cpp_lib.mpi_rank()}" + rank_dir = rank_info_dir / f"{cpp.mpi_rank()}" rank_dir.mkdir(exist_ok=True) with open(rank_dir / "runtime_config.json", "w") as f: diff --git a/pyphare/pyphare/data/wrangler.py b/pyphare/pyphare/data/wrangler.py index 2f9527781..cf362e186 100644 --- a/pyphare/pyphare/data/wrangler.py +++ b/pyphare/pyphare/data/wrangler.py @@ -3,16 +3,15 @@ class DataWrangler: def __init__(self, simulator): - from .. import pharein as ph - from pyphare.cpp import cpp_lib + from pyphare import cpp - self.dim = ph.global_vars.sim.ndim - self.interp = ph.global_vars.sim.interp_order - self.refined_particle_nbr = ph.global_vars.sim.refined_particle_nbr - self.cpp = getattr( - cpp_lib(), - f"DataWrangler_{self.dim}_{self.interp}_{self.refined_particle_nbr}", - )(simulator.cpp_sim, simulator.cpp_hier) + sim = simulator.simulation + self.dim = sim.ndim + self.interp = sim.interp_order + self.refined_particle_nbr = sim.refined_particle_nbr + self.cpp = getattr(cpp.cpp_lib(sim), "DataWrangler")( + simulator.cpp_sim, simulator.cpp_hier + ) def kill(self): del self.cpp diff --git a/pyphare/pyphare/pharesee/hierarchy/fromh5.py b/pyphare/pyphare/pharesee/hierarchy/fromh5.py index 369ac2379..83a807221 100644 --- a/pyphare/pyphare/pharesee/hierarchy/fromh5.py +++ b/pyphare/pyphare/pharesee/hierarchy/fromh5.py @@ -1,5 +1,6 @@ import os import numpy as np +from pathlib import Path from .patch import Patch from .patchlevel import PatchLevel @@ -15,8 +16,6 @@ ) from ...core.gridlayout import GridLayout from .hierarchy_utils import field_qties - -from pathlib import Path from pyphare.core.phare_utilities import listify diff --git a/pyphare/pyphare/pharesee/particles.py b/pyphare/pyphare/pharesee/particles.py index 3d6fb58b4..c3f1cc118 100644 --- a/pyphare/pyphare/pharesee/particles.py +++ b/pyphare/pyphare/pharesee/particles.py @@ -160,9 +160,9 @@ def pop(self, idx): def split(self, sim): # REQUIRES C++ PYBIND PHARE LIB from pyphare.cpp import split_pyarrays_fn - split_pyarrays = split_pyarrays_fn( - sim.ndim, sim.interp_order, sim.refined_particle_nbr - )((self.iCells, self.deltas, self.weights, self.charges, self.v)) + split_pyarrays = split_pyarrays_fn(sim)( + (self.iCells, self.deltas, self.weights, self.charges, self.v) + ) return Particles( icells=split_pyarrays[0].reshape( int(len(split_pyarrays[0]) / self.ndim), self.ndim diff --git a/pyphare/pyphare/simulator/simulator.py b/pyphare/pyphare/simulator/simulator.py index 8254c5187..ada192774 100644 --- a/pyphare/pyphare/simulator/simulator.py +++ b/pyphare/pyphare/simulator/simulator.py @@ -12,6 +12,7 @@ from pathlib import Path from . import monitoring as mon +from pyphare import cpp import pyphare.pharein.restarts as restarts @@ -30,34 +31,27 @@ def simulator_shutdown(): life_cycles.clear() -def make_cpp_simulator(dim, interp, nbrRefinedPart, hier): - from pyphare.cpp import cpp_lib - +def make_cpp_simulator(cpp_lib, hier): if SCOPE_TIMING: - mon.timing_setup(cpp_lib()) + mon.timing_setup(cpp_lib) - make_sim = f"make_simulator_{dim}_{interp}_{nbrRefinedPart}" - return getattr(cpp_lib(), make_sim)(hier) + make_sim = "make_simulator" + assert hasattr(cpp_lib, make_sim) + return getattr(cpp_lib, make_sim)(hier) def startMPI(): if "samrai" not in life_cycles: - from pyphare.cpp import cpp_lib - - life_cycles["samrai"] = cpp_lib().SamraiLifeCycle() + life_cycles["samrai"] = cpp.cpp_etc_lib().SamraiLifeCycle() def print_rank0(*args, **kwargs): - from pyphare.cpp import cpp_lib - - if cpp_lib().mpi_rank() == 0: + if cpp.mpi_rank() == 0: print(*args, **kwargs) def plot_timestep_time(timestep_times): - from pyphare.cpp import cpp_lib - - if cpp_lib().mpi_rank() == 0: + if cpp.mpi_rank() == 0: import matplotlib.pyplot as plt fig, ax = plt.subplots() @@ -66,7 +60,7 @@ def plot_timestep_time(timestep_times): plt.xlabel("timestep") fig.savefig("timestep_times.png") - cpp_lib().mpi_barrier() + cpp.mpi_barrier() class Simulator: @@ -113,33 +107,27 @@ def __del__(self): def setup(self): # mostly to detach C++ class construction/dict parsing from C++ Simulator::init try: - from pyphare.cpp import cpp_lib - import pyphare.cpp.validate as validate_cpp - startMPI() if all([not self.simulation.dry_run, self.simulation.write_reports]): # not necessary during testing - validate_cpp.log_runtime_config() - validate_cpp.check_build_config_is_runtime_compatible() + cpp.validate.log_runtime_config() + cpp.validate.check_build_config_is_runtime_compatible() if self.log_to_file: self._log_to_file() ph.populateDict() - self.cpp_hier = cpp_lib().make_hierarchy() - self.cpp_sim = make_cpp_simulator( - self.simulation.ndim, - self.simulation.interp_order, - self.simulation.refined_particle_nbr, - self.cpp_hier, - ) + self.cpp_lib = cpp.cpp_lib(self.simulation) + self.cpp_hier = cpp.cpp_etc_lib().make_hierarchy() + self.cpp_sim = make_cpp_simulator(self.cpp_lib, self.cpp_hier) + return self except Exception: import traceback print('Exception caught in "Simulator.setup()": {}'.format(sys.exc_info())) - print(traceback.extract_stack()) + print(traceback.format_exc()) raise ValueError("Error in Simulator.setup(), see previous error") def initialize(self): @@ -202,7 +190,6 @@ def run(self, plot_times=False, monitoring=None): Run the simulation until the end time monitoring requires phlop """ - from pyphare.cpp import cpp_lib self._check_init() @@ -212,7 +199,7 @@ def run(self, plot_times=False, monitoring=None): if self.simulation.dry_run: return self if monitoring: - mon.setup_monitoring(cpp_lib()) + mon.setup_monitoring(self.cpp_lib) perf = [] end_time = self.cpp_sim.endTime() t = self.cpp_sim.currentTime() @@ -224,7 +211,7 @@ def run(self, plot_times=False, monitoring=None): ticktock = tock - tick perf.append(ticktock) t = self.cpp_sim.currentTime() - if cpp_lib().mpi_rank() == 0: + if cpp.mpi_rank() == 0: out = f"t = {t:8.5f} - {ticktock:6.5f}sec - total {np.sum(perf):7.4}sec" print(out, end=self.print_eol) @@ -234,7 +221,7 @@ def run(self, plot_times=False, monitoring=None): if plot_times: plot_timestep_time(perf) - mon.monitoring_shutdown(cpp_lib()) + mon.monitoring_shutdown(self.cpp_lib) return self.reset() def _auto_dump(self): @@ -304,10 +291,9 @@ def _log_to_file(self): CLI - no logging files, display to cout NULL - no logging files, no cout """ - from pyphare.cpp import cpp_lib logging = os.environ["PHARE_LOG"] = os.environ.get("PHARE_LOG", "RANK_FILES") need_log_dir = logging != "CLI" and logging != "NULL" - if need_log_dir and cpp_lib().mpi_rank() == 0: + if need_log_dir and cpp.mpi_rank() == 0: Path(".log").mkdir(exist_ok=True) - cpp_lib().mpi_barrier() + cpp.mpi_barrier() diff --git a/res/__tc/clang/0_config.sh b/res/__tc/clang/0_config.sh new file mode 100644 index 000000000..89dc08ae0 --- /dev/null +++ b/res/__tc/clang/0_config.sh @@ -0,0 +1,6 @@ +pwd +set -ex +ulimit -a +clang -v +ldd --version +ld -v diff --git a/res/__tc/clang/1_build.sh b/res/__tc/clang/1_build.sh new file mode 100644 index 000000000..ceb6eea19 --- /dev/null +++ b/res/__tc/clang/1_build.sh @@ -0,0 +1,20 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +export CC=clang +export CXX=clang++ +export ASAN_OPTIONS=detect_leaks=0 + +( + mkdir build && cd build + cmake .. -G Ninja -Dasan=ON \ + -DdevMode=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + -Dphare_configurator=ON -DSAMRAI_ROOT=/usr/local \ + -DCMAKE_CXX_FLAGS="-g3 -O3 -march=native -mtune=native -DPHARE_DIAG_DOUBLES=1" + + # NO SUBPROJECT SAMRAI EXPECTED! + [ -d ../subprojects/samrai ] && exit 1 + ninja -j$N_CORES -v +) diff --git a/res/__tc/clang/2_test.sh b/res/__tc/clang/2_test.sh new file mode 100644 index 000000000..3039378ec --- /dev/null +++ b/res/__tc/clang/2_test.sh @@ -0,0 +1,27 @@ +set -ex +pwd +ulimit -a + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +export TMPDIR=/tmp +export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles +export GTEST_OUTPUT=xml:gtest_out.xml + +# prevent blas_thread_server from spawning a bajillion threads +export OMP_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 +export MKL_NUM_THREADS=1 +export VECLIB_MAXIMUM_THREADS=1 +export NUMEXPR_NUM_THREADS=1 + + +export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer +export ASAN_OPTIONS=detect_leaks=0 +GCC_ASAN_PRELOAD=$(gcc -print-file-name=libasan.so) +CLANG_ASAN_PRELOAD=$(clang -print-file-name=libclang_rt.asan.so) + +( + cd build + LD_PRELOAD=$CLANG_ASAN_PRELOAD ctest -j$N_CORES --output-on-failure +) diff --git a/res/__tc/clang/3_test_mpi.sh b/res/__tc/clang/3_test_mpi.sh new file mode 100644 index 000000000..18f169402 --- /dev/null +++ b/res/__tc/clang/3_test_mpi.sh @@ -0,0 +1,31 @@ +set -ex +pwd +ulimit -a + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +export TMPDIR=/tmp +export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles +export GTEST_OUTPUT=xml:gtest_out.xml + +# prevent blas_thread_server from spawning a bajillion threads +export OMP_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 +export MKL_NUM_THREADS=1 +export VECLIB_MAXIMUM_THREADS=1 +export NUMEXPR_NUM_THREADS=1 + + +export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer +export ASAN_OPTIONS=detect_leaks=0 +GCC_ASAN_PRELOAD=$(gcc -print-file-name=libasan.so) +CLANG_ASAN_PRELOAD=$(clang -print-file-name=libclang_rt.asan.so) + +( + cd build + cmake .. -G Ninja -Dasan=ON -DtestMPI=ON \ + -DdevMode=ON -Dcppcheck=ON \ + -DCMAKE_CXX_FLAGS="-O3 -g3" -Dphare_configurator=ON + ninja -j$N_CORES -v + LD_PRELOAD=$CLANG_ASAN_PRELOAD ctest -j$N_CORES --output-on-failure +) diff --git a/res/__tc/clang_samraisub/0_config.sh b/res/__tc/clang_samraisub/0_config.sh new file mode 100644 index 000000000..89dc08ae0 --- /dev/null +++ b/res/__tc/clang_samraisub/0_config.sh @@ -0,0 +1,6 @@ +pwd +set -ex +ulimit -a +clang -v +ldd --version +ld -v diff --git a/res/__tc/clang_samraisub/1_build.sh b/res/__tc/clang_samraisub/1_build.sh new file mode 100644 index 000000000..2c13d6f0c --- /dev/null +++ b/res/__tc/clang_samraisub/1_build.sh @@ -0,0 +1,15 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +( + mkdir build && cd build + cmake .. -G Ninja \ + -DdevMode=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + -Dphare_configurator=ON \ + -DCMAKE_CXX_FLAGS="-g3 -O3 -march=native -mtune=native -DPHARE_DIAG_DOUBLES=1" + + [ -d ../subprojects/samrai ] && exit 1 + ninja -j$N_CORES -v +) diff --git a/res/__tc/clang_samraisub/2_test.sh b/res/__tc/clang_samraisub/2_test.sh new file mode 100644 index 000000000..1679c8f7d --- /dev/null +++ b/res/__tc/clang_samraisub/2_test.sh @@ -0,0 +1,19 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +export TMPDIR=/tmp +export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles +export GTEST_OUTPUT=xml:gtest_out.xml + +# prevent blas_thread_server from spawning a bajillion threads +export OMP_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 +export MKL_NUM_THREADS=1 +export VECLIB_MAXIMUM_THREADS=1 +export NUMEXPR_NUM_THREADS=1 + +( + cd build + ctest -j$N_CORES --output-on-failure +) diff --git a/res/__tc/gcc/0_config.sh b/res/__tc/gcc/0_config.sh new file mode 100644 index 000000000..702fe6519 --- /dev/null +++ b/res/__tc/gcc/0_config.sh @@ -0,0 +1,6 @@ +pwd +set -ex +ulimit -a +gcc -v +ldd --version +ld -v diff --git a/res/__tc/gcc/1_build.sh b/res/__tc/gcc/1_build.sh new file mode 100644 index 000000000..e6882fbcc --- /dev/null +++ b/res/__tc/gcc/1_build.sh @@ -0,0 +1,17 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +( + mkdir build && cd build + cmake .. -G Ninja -Dasan=ON \ + -DdevMode=ON -Dcppcheck=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + -Dphare_configurator=ON -DSAMRAI_ROOT=/usr/local \ + -DCMAKE_CXX_FLAGS="-g3 -O3 -march=native -mtune=native -DPHARE_DIAG_DOUBLES=1" + + + # NO SUBPROJECT SAMRAI EXPECTED! + [ -d ../subprojects/samrai ] && exit 1 + ninja -j$N_CORES -v +) diff --git a/res/__tc/gcc/2_test.sh b/res/__tc/gcc/2_test.sh new file mode 100644 index 000000000..1679c8f7d --- /dev/null +++ b/res/__tc/gcc/2_test.sh @@ -0,0 +1,19 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +export TMPDIR=/tmp +export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles +export GTEST_OUTPUT=xml:gtest_out.xml + +# prevent blas_thread_server from spawning a bajillion threads +export OMP_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 +export MKL_NUM_THREADS=1 +export VECLIB_MAXIMUM_THREADS=1 +export NUMEXPR_NUM_THREADS=1 + +( + cd build + ctest -j$N_CORES --output-on-failure +) diff --git a/res/__tc/gcc/3_test_mpi.sh b/res/__tc/gcc/3_test_mpi.sh new file mode 100644 index 000000000..1a90db6f0 --- /dev/null +++ b/res/__tc/gcc/3_test_mpi.sh @@ -0,0 +1,23 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +export TMPDIR=/tmp +export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles +export GTEST_OUTPUT=xml:gtest_out.xml + +# prevent blas_thread_server from spawning a bajillion threads +export OMP_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 +export MKL_NUM_THREADS=1 +export VECLIB_MAXIMUM_THREADS=1 +export NUMEXPR_NUM_THREADS=1 + +( + cd build + cmake .. -G Ninja -DtestMPI=ON \ + -DdevMode=ON -Dcppcheck=ON \ + -DCMAKE_CXX_FLAGS="-O3 -g3" -Dphare_configurator=ON + ninja -j$N_CORES -v + ctest -j$N_CORES --output-on-failure +) diff --git a/res/__tc/gcc_samraisub/0_config.sh b/res/__tc/gcc_samraisub/0_config.sh new file mode 100644 index 000000000..702fe6519 --- /dev/null +++ b/res/__tc/gcc_samraisub/0_config.sh @@ -0,0 +1,6 @@ +pwd +set -ex +ulimit -a +gcc -v +ldd --version +ld -v diff --git a/res/__tc/gcc_samraisub/1_build.sh b/res/__tc/gcc_samraisub/1_build.sh new file mode 100644 index 000000000..c49082803 --- /dev/null +++ b/res/__tc/gcc_samraisub/1_build.sh @@ -0,0 +1,14 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +( + mkdir build && cd build + cmake .. -G Ninja \ + -DdevMode=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + -Dphare_configurator=ON \ + -DCMAKE_CXX_FLAGS="-g3 -O3 -march=native -mtune=native -DPHARE_DIAG_DOUBLES=1" + + ninja -j$N_CORES -v +) diff --git a/res/__tc/gcc_samraisub/2_test.sh b/res/__tc/gcc_samraisub/2_test.sh new file mode 100644 index 000000000..1679c8f7d --- /dev/null +++ b/res/__tc/gcc_samraisub/2_test.sh @@ -0,0 +1,19 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +export TMPDIR=/tmp +export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles +export GTEST_OUTPUT=xml:gtest_out.xml + +# prevent blas_thread_server from spawning a bajillion threads +export OMP_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 +export MKL_NUM_THREADS=1 +export VECLIB_MAXIMUM_THREADS=1 +export NUMEXPR_NUM_THREADS=1 + +( + cd build + ctest -j$N_CORES --output-on-failure +) diff --git a/res/__tc/nightly/0_config.sh b/res/__tc/nightly/0_config.sh new file mode 100644 index 000000000..702fe6519 --- /dev/null +++ b/res/__tc/nightly/0_config.sh @@ -0,0 +1,6 @@ +pwd +set -ex +ulimit -a +gcc -v +ldd --version +ld -v diff --git a/res/__tc/nightly/1_build.sh b/res/__tc/nightly/1_build.sh new file mode 100644 index 000000000..65db93349 --- /dev/null +++ b/res/__tc/nightly/1_build.sh @@ -0,0 +1,14 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +( + mkdir build && cd build + cmake .. -G Ninja \ + -DdevMode=ON -Dcppcheck=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + -Dphare_configurator=ON \ + -DCMAKE_CXX_FLAGS="-g3 -O3 -march=native -mtune=native -DPHARE_DIAG_DOUBLES=1" + + ninja -j$N_CORES -v +) diff --git a/res/__tc/nightly/2_test.sh b/res/__tc/nightly/2_test.sh new file mode 100644 index 000000000..1679c8f7d --- /dev/null +++ b/res/__tc/nightly/2_test.sh @@ -0,0 +1,19 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +export TMPDIR=/tmp +export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles +export GTEST_OUTPUT=xml:gtest_out.xml + +# prevent blas_thread_server from spawning a bajillion threads +export OMP_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 +export MKL_NUM_THREADS=1 +export VECLIB_MAXIMUM_THREADS=1 +export NUMEXPR_NUM_THREADS=1 + +( + cd build + ctest -j$N_CORES --output-on-failure +) diff --git a/res/__tc/nightly/3_test_mpi.sh b/res/__tc/nightly/3_test_mpi.sh new file mode 100644 index 000000000..2c208ed94 --- /dev/null +++ b/res/__tc/nightly/3_test_mpi.sh @@ -0,0 +1,24 @@ +set -ex + +[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 + +export TMPDIR=/tmp +export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles +export GTEST_OUTPUT=xml:gtest_out.xml + +# prevent blas_thread_server from spawning a bajillion threads +export OMP_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 +export MKL_NUM_THREADS=1 +export VECLIB_MAXIMUM_THREADS=1 +export NUMEXPR_NUM_THREADS=1 + + +( + cd build + cmake .. -G Ninja -DtestMPI=ON \ + -DdevMode=ON -Dcppcheck=ON \ + -DCMAKE_CXX_FLAGS="-O3 -g3" -Dphare_configurator=ON + ninja -j$N_CORES -v + ctest -j$N_CORES --output-on-failure +) diff --git a/res/cmake/bench.cmake b/res/cmake/bench.cmake index 016016cb3..bc3a71f91 100644 --- a/res/cmake/bench.cmake +++ b/res/cmake/bench.cmake @@ -54,6 +54,5 @@ if (bench) add_subdirectory(tools/bench/core/numerics/interpolator) add_subdirectory(tools/bench/hi5) - add_subdirectory(tools/bench/real) endif() diff --git a/res/cmake/dep/samrai.cmake b/res/cmake/dep/samrai.cmake index d90f2a86b..5c940d492 100644 --- a/res/cmake/dep/samrai.cmake +++ b/res/cmake/dep/samrai.cmake @@ -4,39 +4,43 @@ find_package(MPI REQUIRED COMPONENTS C) get_filename_component(MPI_LIBRARY_PATH ${MPI_LIBRARY} DIRECTORY) -find_package(SAMRAI CONFIG QUIET) -if (NOT SAMRAI_FOUND) - message("SAMRAI NOT FOUND") - if(DEFINED SAMRAI_ROOT) - find_package(SAMRAI PATHS ${SAMRAI_ROOT} REQUIRED) - else() - - if(NOT DEFINED PHARE_SAMRAI_VERSION) - SET(PHARE_SAMRAI_VERSION "develop") - endif() - - set(SAMRAI_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/samrai) - set(SAMRAI_BIN ${CMAKE_CURRENT_BINARY_DIR}/subprojects/samrai) - - phare_github_get_or_update(SAMRAI ${SAMRAI_SRCDIR} LLNL/SAMRAI ${PHARE_SAMRAI_VERSION}) - - if (NOT CMAKE_BUILD_TYPE STREQUAL "Release") - # enable samrai assertions if not in release mode - set (DEBUG_INITIALIZE_UNDEFINED On) - set (DEBUG_CHECK_ASSERTIONS On) - set (DEBUG_CHECK_DIM_ASSERTIONS On) - endif() - - option(ENABLE_TESTS "Enable Samrai Test" OFF ) # disable SAMRAI Test so that we can use the googletest pulled after - option(ENABLE_SAMRAI_TESTS "Enable Samrai Test" OFF ) # disable SAMRAI Test so that we can use the googletest pulled after - - add_subdirectory(${SAMRAI_SRCDIR}) - unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY CACHE) # undoes what samrai does, so ctest can continue to work - include_directories(${CMAKE_BINARY_DIR}/include) # this is needed to find build-dir/include/SAMRAI/SAMRAI_config.h - endif() +if(DEFINED SAMRAI_ROOT) + find_package(SAMRAI PATHS ${SAMRAI_ROOT} REQUIRED) else() - include_directories(${SAMRAI_INCLUDE_DIRS}) # this is needed to find build-dir/include/SAMRAI/SAMRAI_config.h - message("SAMRAI HAS BEEN FOUND") - message(${SAMRAI_INCLUDE_DIRS}) -endif() + if(NOT DEFINED PHARE_SAMRAI_VERSION) + SET(PHARE_SAMRAI_VERSION "develop") + endif() + + set(SAMRAI_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/samrai) + set(SAMRAI_BIN ${CMAKE_CURRENT_BINARY_DIR}/subprojects/samrai) + + phare_github_get_or_update(SAMRAI ${SAMRAI_SRCDIR} LLNL/SAMRAI ${PHARE_SAMRAI_VERSION}) + + if (NOT CMAKE_BUILD_TYPE STREQUAL "Release") + # enable samrai assertions if not in release mode + set (DEBUG_INITIALIZE_UNDEFINED On) + set (DEBUG_CHECK_ASSERTIONS On) + set (DEBUG_CHECK_DIM_ASSERTIONS On) + endif() + + if(SAMRAI_BUILD_SHARED_LIBS) + option(BUILD_SHARED_LIBS "Make shared libs" ON ) # default as of 15/JUL/2025 is static libs + endif(SAMRAI_BUILD_SHARED_LIBS) + + option(ENABLE_TESTS "Enable Samrai Test" OFF ) # disable SAMRAI Test so that we can use the googletest pulled after + option(ENABLE_SAMRAI_TESTS "Enable Samrai Test" OFF ) # disable SAMRAI Test so that we can use the googletest pulled after + + add_subdirectory(${SAMRAI_SRCDIR}) + unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY CACHE) # undoes what samrai does, so ctest can continue to work + include_directories(${CMAKE_BINARY_DIR}/include) # this is needed to find build-dir/include/SAMRAI/SAMRAI_config.h + + + # REMOVE AFTER MERGED https://github.com/LLNL/SAMRAI/pull/294 + target_link_libraries(SAMRAI_algs PUBLIC SAMRAI_mesh) + target_link_libraries(SAMRAI_appu PUBLIC SAMRAI_geom) + target_link_libraries(SAMRAI_mesh PUBLIC SAMRAI_pdat) + target_link_libraries(SAMRAI_solv PUBLIC SAMRAI_geom) + + +endif(DEFINED SAMRAI_ROOT) diff --git a/res/cmake/options.cmake b/res/cmake/options.cmake index 20a243405..8e7c2e1f0 100644 --- a/res/cmake/options.cmake +++ b/res/cmake/options.cmake @@ -100,6 +100,14 @@ option(bench "Compile PHARE Benchmarks" OFF) option(phare_configurator "Best guess setup for compile" OFF) +# -DSAMRAI_BUILD_SHARED_LIBS=OFF +option(SAMRAI_BUILD_SHARED_LIBS "Build SAMRAI shared libraries" ON) + + +#-DPHARE_EXE=OFF +option(PHARE_EXE "Build PHARE EXE" OFF) + + # print options function(print_phare_options) diff --git a/res/sim/all.txt b/res/sim/all.txt new file mode 100644 index 000000000..011cdcae5 --- /dev/null +++ b/res/sim/all.txt @@ -0,0 +1,23 @@ +1,1,2 +1,1,3 +1,2,2 +1,2,3 +1,2,4 +1,3,2 +1,3,3 +1,3,4 +1,3,5 +2,1,4 +2,1,5 +2,1,8 +2,1,9 +2,2,4 +2,2,5 +2,2,8 +2,2,9 +2,2,16 +2,3,4 +2,3,5 +2,3,8 +2,3,9 +2,3,25 diff --git a/src/amr/CMakeLists.txt b/src/amr/CMakeLists.txt index be0d61a60..2535cd0bd 100644 --- a/src/amr/CMakeLists.txt +++ b/src/amr/CMakeLists.txt @@ -73,21 +73,25 @@ set( SOURCES_INC load_balancing/load_balancer_hybrid_strategy.hpp load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp + samrai.hpp ) set( SOURCES_CPP data/field/refine/linear_weighter.cpp resources_manager/amr_utils.cpp data/field/coarsening/field_coarsen.cpp messengers/messenger_factory.cpp + samrai.cpp ) -add_library(${PROJECT_NAME} ${SOURCES_INC} ${SOURCES_CPP}) +# single source of entry for static SAMRAI things +add_library(${PROJECT_NAME} SHARED ${SOURCES_INC} ${SOURCES_CPP}) target_compile_options(${PROJECT_NAME} PRIVATE ${PHARE_WERROR_FLAGS}) set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION ${PHARE_INTERPROCEDURAL_OPTIMIZATION}) target_link_directories(${PROJECT_NAME} PUBLIC ${MPI_LIBRARY_PATH}) target_link_libraries(${PROJECT_NAME} PUBLIC phare_core + phare_initializer SAMRAI_algs SAMRAI_appu SAMRAI_geom @@ -101,5 +105,10 @@ target_link_libraries(${PROJECT_NAME} PUBLIC MPI::MPI_C cppdict ) -set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") +) + +if (HighFive) # SAMRAI USES HDF5 so we need this here + target_link_libraries(${PROJECT_NAME} PUBLIC HDF5::HDF5) +endif() +set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") diff --git a/src/amr/data/particles/particles_data.hpp b/src/amr/data/particles/particles_data.hpp index d07b79072..437dc6ca6 100644 --- a/src/amr/data/particles/particles_data.hpp +++ b/src/amr/data/particles/particles_data.hpp @@ -1,15 +1,14 @@ #ifndef PHARE_SRC_AMR_DATA_PARTICLES_PARTICLES_DATA_HPP #define PHARE_SRC_AMR_DATA_PARTICLES_PARTICLES_DATA_HPP -#include "core/def/phare_mpi.hpp" // IWYU pragma: keep - - -#include "core/def.hpp" -#include "core/data/ions/ion_population/particle_pack.hpp" +#include "core/def.hpp" // IWYU pragma: keep +#include "core/def/phare_mpi.hpp" // IWYU pragma: keep #include "core/data/particles/particle_array.hpp" #include "core/data/particles/particle_packer.hpp" +#include "core/data/ions/ion_population/particle_pack.hpp" +#include "amr/samrai.hpp" // IWYU pragma: keep #include "amr/utilities/box/amr_box.hpp" #include "amr/resources_manager/amr_utils.hpp" #include diff --git a/src/amr/load_balancing/load_balancer_manager.hpp b/src/amr/load_balancing/load_balancer_manager.hpp index c9a021789..5da71ff73 100644 --- a/src/amr/load_balancing/load_balancer_manager.hpp +++ b/src/amr/load_balancing/load_balancer_manager.hpp @@ -1,16 +1,16 @@ #ifndef PHARE_LOAD_BALANCER_MANAGER_HPP #define PHARE_LOAD_BALANCER_MANAGER_HPP -#include -#include -#include +#include "initializer/data_provider.hpp" +#include "load_balancer_estimator.hpp" + +#include "amr/samrai.hpp" #include #include -#include "initializer/data_provider.hpp" -#include "load_balancer_estimator.hpp" - +#include +#include namespace PHARE::amr { @@ -24,12 +24,12 @@ class LoadBalancerManager : dim_{SAMRAI::tbox::Dimension{dim}} , loadBalancerVar_{std::make_shared>( dim_, "LoadBalancerVariable")} - , variableDatabase_{SAMRAI::hier::VariableDatabase::getDatabase()} + , variableDatabase_{SamraiLifeCycle::getDatabase()} , context_{variableDatabase_->getContext("default")} , id_{variableDatabase_->registerVariableAndContext(loadBalancerVar_, context_, SAMRAI::hier::IntVector::getZero(dim_))} , maxLevelNumber_{dict["simulation"]["AMR"]["max_nbr_levels"].template to()} - , loadBalancerEstimators_(maxLevelNumber_){}; + , loadBalancerEstimators_(maxLevelNumber_) {}; ~LoadBalancerManager() { variableDatabase_->removeVariable("LoadBalancerVariable"); }; diff --git a/src/amr/multiphysics_integrator.hpp b/src/amr/multiphysics_integrator.hpp index fa057de63..9c99bd3d5 100644 --- a/src/amr/multiphysics_integrator.hpp +++ b/src/amr/multiphysics_integrator.hpp @@ -384,8 +384,7 @@ namespace solver // handle samrai restarts / schedule creation // allocation of patch datas which may not want to be saved to restart files will // likely need to go here somehow https://github.com/PHAREHUB/PHARE/issues/664 - if (!restartInitialized_ - and SAMRAI::tbox::RestartManager::getManager()->isFromRestart()) + if (!restartInitialized_ and SamraiLifeCycle::getRestartManager()->isFromRestart()) { auto& messenger = getMessengerWithCoarser_(coarsestLevel); for (auto ilvl = coarsestLevel; ilvl <= finestLevel; ++ilvl) diff --git a/src/amr/resources_manager/resources_manager.hpp b/src/amr/resources_manager/resources_manager.hpp index bbc8361af..12dfb8b2e 100644 --- a/src/amr/resources_manager/resources_manager.hpp +++ b/src/amr/resources_manager/resources_manager.hpp @@ -1,12 +1,13 @@ #ifndef PHARE_AMR_TOOLS_RESOURCES_MANAGER_HPP #define PHARE_AMR_TOOLS_RESOURCES_MANAGER_HPP -#include "core/def/phare_mpi.hpp" // IWYU pragma: keep #include "core/def.hpp" -#include "core/logger.hpp" +#include "core/def/phare_mpi.hpp" // IWYU pragma: keep #include "core/hybrid/hybrid_quantities.hpp" +#include "amr/samrai.hpp" + #include "field_resource.hpp" #include "resources_guards.hpp" #include "particle_resource.hpp" @@ -21,6 +22,7 @@ #include + namespace PHARE { namespace amr @@ -101,7 +103,7 @@ namespace amr ResourcesManager() - : variableDatabase_{SAMRAI::hier::VariableDatabase::getDatabase()} + : variableDatabase_{SamraiLifeCycle::getDatabase()} , context_{variableDatabase_->getContext(contextName_)} , dimension_{SAMRAI::tbox::Dimension{dimension}} { @@ -296,29 +298,22 @@ namespace amr void registerForRestarts() const { - auto pdrm = SAMRAI::hier::PatchDataRestartManager::getManager(); + auto pdrm = SamraiLifeCycle::getPatchDataRestartManager(); for (auto const& id : restart_patch_data_ids()) pdrm->registerPatchDataForRestart(id); } + NO_DISCARD auto restart_patch_data_ids() const - { // see https://github.com/PHAREHUB/PHARE/issues/664 + { + // see https://github.com/PHAREHUB/PHARE/issues/664 std::vector ids; for (auto const& [key, info] : nameToResourceInfo_) ids.emplace_back(info.id); return ids; } - template // this function is never called - NO_DISCARD auto restart_patch_data_ids(ResourcesView const& view) const - { - std::vector ids; - getIDs_(view, ids); - return ids; - } - - auto getIDsList(auto&&... keys) const { auto const Fn = [&](auto& key) { diff --git a/src/amr/samrai.cpp b/src/amr/samrai.cpp new file mode 100644 index 000000000..c78b52441 --- /dev/null +++ b/src/amr/samrai.cpp @@ -0,0 +1,60 @@ +#include "samrai.hpp" + + +namespace PHARE +{ + +SamraiLifeCycle::SamraiLifeCycle(int argc, char** argv) +{ + SAMRAI::tbox::SAMRAI_MPI::init(&argc, &argv); + SAMRAI::tbox::SAMRAIManager::initialize(); + SAMRAI::tbox::SAMRAIManager::startup(); + // uncomment next line for debugging samrai issues + // SAMRAI::tbox::SAMRAI_MPI::setCallAbortInParallelInsteadOfMPIAbort(); + std::shared_ptr appender + = std::make_shared(StreamAppender{&std::cout}); + SAMRAI::tbox::Logger::getInstance()->setWarningAppender(appender); + PHARE_WITH_PHLOP( // + if (auto e = core::get_env("PHARE_SCOPE_TIMING", "false"); e == "1" || e == "true") + phlop::ScopeTimerMan::INSTANCE() + .file_name(".phare/timings/rank." + std::to_string(core::mpi::rank()) + ".txt") + .init(); // + ) +} + +SamraiLifeCycle::~SamraiLifeCycle() +{ + PHARE_WITH_PHLOP(phlop::ScopeTimerMan::reset()); + SAMRAI::tbox::SAMRAIManager::shutdown(); + SAMRAI::tbox::SAMRAIManager::finalize(); + SAMRAI::tbox::SAMRAI_MPI::finalize(); +} + +void SamraiLifeCycle::reset() +{ + PHARE_WITH_PHLOP(phlop::ScopeTimerMan::reset()); + PHARE::initializer::PHAREDictHandler::INSTANCE().stop(); + SAMRAI::tbox::SAMRAIManager::shutdown(); + SAMRAI::tbox::SAMRAIManager::startup(); + getRestartManager()->clearRestartItems(); +} + + +SAMRAI::hier::VariableDatabase* SamraiLifeCycle::getDatabase() +{ + return SAMRAI::hier::VariableDatabase::getDatabase(); +} + +SAMRAI::hier::PatchDataRestartManager* SamraiLifeCycle::getPatchDataRestartManager() +{ + return SAMRAI::hier::PatchDataRestartManager::getManager(); +} + + +SAMRAI::tbox::RestartManager* SamraiLifeCycle::getRestartManager() +{ + return SAMRAI::tbox::RestartManager::getManager(); +} + + +} // namespace PHARE diff --git a/src/amr/samrai.hpp b/src/amr/samrai.hpp new file mode 100644 index 000000000..b771ddb70 --- /dev/null +++ b/src/amr/samrai.hpp @@ -0,0 +1,53 @@ + +#ifndef PHARE_AMR_SAMRAI_HPP +#define PHARE_AMR_SAMRAI_HPP + +#include "core/def/phlop.hpp" // scope timing + +#include "amr/wrappers/integrator.hpp" +#include "core/utilities/mpi_utils.hpp" + +#include +#include +#include + +#include +#include + +namespace PHARE +{ +class StreamAppender : public SAMRAI::tbox::Logger::Appender +{ +public: + StreamAppender(std::ostream* stream) { d_stream = stream; } + void logMessage(std::string const& message, std::string const& filename, int const line) + { + (*d_stream) << "At :" << filename << " line :" << line << " message: " << message + << std::endl; + } + +private: + std::ostream* d_stream; +}; + +class SamraiLifeCycle // +{ +public: + SamraiLifeCycle(int argc = 0, char** argv = nullptr); + + ~SamraiLifeCycle(); + + static void reset(); + + static SAMRAI::hier::VariableDatabase* getDatabase(); + + static SAMRAI::hier::PatchDataRestartManager* getPatchDataRestartManager(); + + static SAMRAI::tbox::RestartManager* getRestartManager(); +}; + + +} // namespace PHARE + + +#endif /*PHARE_AMR_SAMRAI_HPP*/ diff --git a/src/amr/wrappers/hierarchy.hpp b/src/amr/wrappers/hierarchy.hpp index aec20254b..83953ca28 100644 --- a/src/amr/wrappers/hierarchy.hpp +++ b/src/amr/wrappers/hierarchy.hpp @@ -1,9 +1,18 @@ #ifndef PHARE_AMR_HIERARCHY_HPP #define PHARE_AMR_HIERARCHY_HPP -#include + +#include "core/def.hpp" +#include "core/logger.hpp" #include "core/def/phare_mpi.hpp" // IWYU pragma: keep +#include "core/utilities/mpi_utils.hpp" +#include "core/utilities/meta/meta_utilities.hpp" + +#include "initializer/data_provider.hpp" + +#include "amr/samrai.hpp" + #include #include @@ -18,15 +27,10 @@ #include #include #include -#include -#include "SAMRAI/hier/PatchDataRestartManager.h" -#include "core/def.hpp" -#include "core/utilities/mpi_utils.hpp" -#include "initializer/data_provider.hpp" -#include "core/utilities/meta/meta_utilities.hpp" +#include namespace PHARE::amr @@ -40,7 +44,8 @@ namespace PHARE::amr class HierarchyRestarter { public: - HierarchyRestarter(initializer::PHAREDict const& sim_dict) + HierarchyRestarter(initializer::PHAREDict const& _sim_dict) + : sim_dict{_sim_dict} { if (sim_dict["simulation"].contains("restarts")) { @@ -48,8 +53,8 @@ class HierarchyRestarter if (dict.contains("loadPath")) { - auto restart_manager = SAMRAI::tbox::RestartManager::getManager(); - auto pdrm = SAMRAI::hier::PatchDataRestartManager::getManager(); + auto restart_manager = SamraiLifeCycle::getRestartManager(); + auto pdrm = SamraiLifeCycle::getPatchDataRestartManager(); for (auto& id : dict["restart_ids"].template to>()) pdrm->registerPatchDataForRestart(id); @@ -61,6 +66,22 @@ class HierarchyRestarter } } + ~HierarchyRestarter() + { + if (sim_dict["simulation"].contains("restarts")) + { + auto& dict = sim_dict["simulation"]["restarts"]; + + if (dict.contains("loadPath")) + { + auto pdrm = SamraiLifeCycle::getPatchDataRestartManager(); + + for (auto& id : dict["restart_ids"].template to>()) + pdrm->unregisterPatchDataForRestart(id); + } + } + } + NO_DISCARD auto static getRestartFileFullPath(std::string path, int idx = 0) { // https://github.com/LLNL/SAMRAI/pull/198 @@ -73,12 +94,15 @@ class HierarchyRestarter + "/proc." + SAMRAI::tbox::Utilities::processorToString(core::mpi::rank()); } - void closeRestartFile() { SAMRAI::tbox::RestartManager::getManager()->closeRestartFile(); } + void closeRestartFile() { SamraiLifeCycle::getRestartManager()->closeRestartFile(); } NO_DISCARD bool isFromRestart() const { - return SAMRAI::tbox::RestartManager::getManager()->isFromRestart(); + return SamraiLifeCycle::getRestartManager()->isFromRestart(); } + +private: + initializer::PHAREDict sim_dict; }; @@ -192,8 +216,14 @@ inline auto Hierarchy::make() { PHARE::initializer::PHAREDict const& theDict = PHARE::initializer::PHAREDictHandler::INSTANCE().dict(); - auto dim = theDict["simulation"]["dimension"].template to(); - return core::makeAtRuntime(dim, HierarchyMaker{theDict}); + auto dim = theDict["simulation"]["dimension"].template to(); + auto hier = core::makeAtRuntime(dim, HierarchyMaker{theDict}); + if (hier) + return hier; + PHARE_LOG_LINE_SS("hierarchy not found for params:\n" + << dim << " " << theDict["simulation"]["interp_order"].template to() + << " " << theDict["simulation"]["refined_particle_nbr"].template to()); + throw std::runtime_error("Likely unsupported template parameters"); } @@ -217,7 +247,7 @@ Hierarchy::Hierarchy(initializer::PHAREDict const& dict, inline auto Hierarchy::writeRestartFile(std::string directory) const { - auto* restart_manager = SAMRAI::tbox::RestartManager::getManager(); + auto* restart_manager = SamraiLifeCycle::getRestartManager(); int timeStepIdx = 0; // samrai needs this restart_manager->writeRestartFile(directory, timeStepIdx); diff --git a/src/amr/wrappers/integrator.hpp b/src/amr/wrappers/integrator.hpp index c460b7944..ea41b9995 100644 --- a/src/amr/wrappers/integrator.hpp +++ b/src/amr/wrappers/integrator.hpp @@ -2,7 +2,10 @@ #define INTEGRATOR_HPP #include "core/logger.hpp" + #include "core/def/phare_mpi.hpp" // IWYU pragma: keep +#include "core/utilities/mpi_utils.hpp" + #include #include diff --git a/src/core/data/grid/gridlayout.hpp b/src/core/data/grid/gridlayout.hpp index 0aee24142..56df86052 100644 --- a/src/core/data/grid/gridlayout.hpp +++ b/src/core/data/grid/gridlayout.hpp @@ -14,7 +14,6 @@ #include "core/def.hpp" #include -#include #include #include #include diff --git a/src/core/utilities/meta/meta_utilities.hpp b/src/core/utilities/meta/meta_utilities.hpp index 50a4a265a..12e42acf8 100644 --- a/src/core/utilities/meta/meta_utilities.hpp +++ b/src/core/utilities/meta/meta_utilities.hpp @@ -112,13 +112,33 @@ namespace core } + + constexpr decltype(auto) phare_exe_default_simulators() + { + // feel free to change as you wish + return std::tuple, InterpConst<1>, 2>, + SimulatorOption, InterpConst<2>, 2>, + SimulatorOption, InterpConst<3>, 2>, + + SimulatorOption, InterpConst<1>, 4>, + SimulatorOption, InterpConst<2>, 4>, + SimulatorOption, InterpConst<3>, 4>, + + SimulatorOption, InterpConst<1>, 6>, + SimulatorOption, InterpConst<2>, 6>, + SimulatorOption, InterpConst<3>, 6> + + >{}; + } + + template // used from PHARE::amr::Hierarchy auto makeAtRuntime(std::size_t dim, Maker&& maker) { using Ptr_t = decltype(maker(dim, 1)); Ptr_t p{}; - core::apply(possibleSimulators(), [&](auto const& simType) { + core::apply(phare_exe_default_simulators(), [&](auto const& simType) { using SimuType = std::decay_t; using _dim = typename std::tuple_element<0, SimuType>::type; @@ -150,7 +170,7 @@ namespace core using Ptr_t = decltype(maker(dim, interpOrder, nbRefinedPart, 1, 1, 1)); Ptr_t p = nullptr; - core::apply(possibleSimulators(), [&](auto const& simType) { + core::apply(phare_exe_default_simulators(), [&](auto const& simType) { using SimuType = std::decay_t; // TORM on 3D PR using _dim = typename std::tuple_element<0, SimuType>::type; // TORM on 3D PR if constexpr (_dim{}() < 3) // TORM on 3D PR diff --git a/src/diagnostic/CMakeLists.txt b/src/diagnostic/CMakeLists.txt index 5a97d1d60..b1c5f5e79 100644 --- a/src/diagnostic/CMakeLists.txt +++ b/src/diagnostic/CMakeLists.txt @@ -21,8 +21,9 @@ if (HighFive) endif() add_library(${PROJECT_NAME} INTERFACE) + target_link_libraries(${PROJECT_NAME} INTERFACE phare_amr) if (HighFive) target_link_libraries(${PROJECT_NAME} INTERFACE HighFive) -endif() +endif (HighFive) diff --git a/src/phare/CMakeLists.txt b/src/phare/CMakeLists.txt index 0dd7d5bd3..f034996a0 100644 --- a/src/phare/CMakeLists.txt +++ b/src/phare/CMakeLists.txt @@ -2,13 +2,16 @@ cmake_minimum_required (VERSION 3.20.1) project(phare-exe) -add_executable(phare-exe ${SOURCES_INC} phare.cpp) -target_compile_options(phare-exe PRIVATE ${PHARE_WERROR_FLAGS} -DPHARE_HAS_HIGHFIVE=${PHARE_HAS_HIGHFIVE}) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/phare_init.py ${CMAKE_CURRENT_BINARY_DIR}/phare_init.py @ONLY) -target_link_libraries(phare-exe PUBLIC - ${PHARE_BASE_LIBS} - phare_simulator - pybind11::embed -) -set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") +if(PHARE_EXE) + add_executable(phare-exe ${SOURCES_INC} phare.cpp) + target_compile_options(phare-exe PRIVATE ${PHARE_WERROR_FLAGS} -DPHARE_HAS_HIGHFIVE=${PHARE_HAS_HIGHFIVE}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/phare_init.py ${CMAKE_CURRENT_BINARY_DIR}/phare_init.py @ONLY) + target_link_libraries(phare-exe PUBLIC + ${PHARE_BASE_LIBS} + phare_simulator + pybind11::embed + ) + set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") + +endif(PHARE_EXE) diff --git a/src/phare/phare.cpp b/src/phare/phare.cpp index d346987a5..785217590 100644 --- a/src/phare/phare.cpp +++ b/src/phare/phare.cpp @@ -1,6 +1,6 @@ -#include "phare/phare.hpp" +#include "amr/samrai.hpp" #include "simulator/simulator.hpp" #include "amr/wrappers/hierarchy.hpp" #include "initializer/python_data_provider.hpp" diff --git a/src/phare/phare.hpp b/src/phare/phare.hpp deleted file mode 100644 index 666f3de8e..000000000 --- a/src/phare/phare.hpp +++ /dev/null @@ -1,72 +0,0 @@ - -#ifndef PHARE_PHARE_INCLUDE_HPP -#define PHARE_PHARE_INCLUDE_HPP - -#include "core/def/phlop.hpp" // scope timing - -#include "simulator/simulator.hpp" -#include "core/utilities/algorithm.hpp" -#include "core/utilities/mpi_utils.hpp" - -#include -#include - -namespace PHARE -{ -class StreamAppender : public SAMRAI::tbox::Logger::Appender -{ -public: - StreamAppender(std::ostream* stream) { d_stream = stream; } - void logMessage(std::string const& message, std::string const& filename, const int line) - { - (*d_stream) << "At :" << filename << " line :" << line << " message: " << message - << std::endl; - } - -private: - std::ostream* d_stream; -}; - -class SamraiLifeCycle -{ -public: - SamraiLifeCycle(int argc = 0, char** argv = nullptr) - { - SAMRAI::tbox::SAMRAI_MPI::init(&argc, &argv); - SAMRAI::tbox::SAMRAIManager::initialize(); - SAMRAI::tbox::SAMRAIManager::startup(); - // uncomment next line for debugging samrai issues - // SAMRAI::tbox::SAMRAI_MPI::setCallAbortInParallelInsteadOfMPIAbort(); - std::shared_ptr appender - = std::make_shared(StreamAppender{&std::cout}); - SAMRAI::tbox::Logger::getInstance()->setWarningAppender(appender); - PHARE_WITH_PHLOP( // - if (auto e = core::get_env("PHARE_SCOPE_TIMING", "false"); e == "1" || e == "true") - phlop::ScopeTimerMan::INSTANCE() - .file_name(".phare/timings/rank." + std::to_string(core::mpi::rank()) + ".txt") - .init(); // - ) - } - - ~SamraiLifeCycle() - { - PHARE_WITH_PHLOP(phlop::ScopeTimerMan::reset()); - SAMRAI::tbox::SAMRAIManager::shutdown(); - SAMRAI::tbox::SAMRAIManager::finalize(); - SAMRAI::tbox::SAMRAI_MPI::finalize(); - } - - static void reset() - { - PHARE_WITH_PHLOP(phlop::ScopeTimerMan::reset()); - PHARE::initializer::PHAREDictHandler::INSTANCE().stop(); - SAMRAI::tbox::SAMRAIManager::shutdown(); - SAMRAI::tbox::SAMRAIManager::startup(); - } -}; - - -} // namespace PHARE - - -#endif /*PHARE_PHARE_INCLUDE_H*/ diff --git a/src/python3/CMakeLists.txt b/src/python3/CMakeLists.txt index a05c0574c..f2e35da11 100644 --- a/src/python3/CMakeLists.txt +++ b/src/python3/CMakeLists.txt @@ -2,18 +2,32 @@ cmake_minimum_required (VERSION 3.20.1) project(phare_python3) -pybind11_add_module(cpp cpp_simulator.cpp) -target_link_libraries(cpp PUBLIC phare_simulator) -target_compile_options(cpp PRIVATE ${PHARE_WERROR_FLAGS} -DPHARE_HAS_HIGHFIVE=${PHARE_HAS_HIGHFIVE}) -set_target_properties(cpp - PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/pybindlibs" -) -# this is on by default "pybind11_add_module" but can interfere with coverage so we disable it if coverage is enabled -set_property(TARGET cpp PROPERTY INTERPROCEDURAL_OPTIMIZATION ${PHARE_INTERPROCEDURAL_OPTIMIZATION}) -set_property(TARGET cpp APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") +if(NOT PHARE_PERMUTATIONS) + set(PHARE_PERMUTATIONS "${PHARE_PROJECT_DIR}/res/sim/all.txt") +endif() + +file(STRINGS ${PHARE_PERMUTATIONS} THIS_FILE) +while(THIS_FILE) + list(POP_FRONT THIS_FILE LINE) + string(REPLACE "," "_" OUT ${LINE}) + SET(MOD_STR "cpp_${OUT}") + pybind11_add_module(${MOD_STR} cpp_simulator.cpp) + target_link_libraries(${MOD_STR} PUBLIC phare_simulator ) + target_compile_options(${MOD_STR} PRIVATE + ${PHARE_WERROR_FLAGS} -DPHARE_HAS_HIGHFIVE=${PHARE_HAS_HIGHFIVE} -DPHARE_SIM_ID=${OUT} -DPHARE_SIM_STR=${LINE} + ) + set_target_properties(${MOD_STR} + PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/pybindlibs" + ) + # this is on by default "pybind11_add_module" but can interfere with coverage so we disable it if coverage is enabled + set_property(TARGET ${MOD_STR} PROPERTY INTERPROCEDURAL_OPTIMIZATION ${PHARE_INTERPROCEDURAL_OPTIMIZATION}) + set_property(TARGET ${MOD_STR} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") + +endwhile() +# cpp_etc == everything not simulator related! pybind11_add_module(cpp_etc cpp_etc.cpp) target_compile_options(cpp_etc PRIVATE ${PHARE_WERROR_FLAGS} -DPHARE_HAS_HIGHFIVE=${PHARE_HAS_HIGHFIVE}) target_link_libraries(cpp_etc PUBLIC phare_amr phare_diagnostic) diff --git a/src/python3/cpp_etc.cpp b/src/python3/cpp_etc.cpp index 409acb097..6c13439aa 100644 --- a/src/python3/cpp_etc.cpp +++ b/src/python3/cpp_etc.cpp @@ -1,8 +1,15 @@ +// This file is for the python module for everything besides C++ Simulators. + #include "core/def.hpp" #include "core/def/phare_config.hpp" +#include "core/data/particles/particle_array.hpp" + +#include "amr/samrai.hpp" // SamraiLifeCycle without simulators +#include "amr/wrappers/hierarchy.hpp" // for HierarchyRestarter::getRestartFileFullPath #include "python3/pybind_def.hpp" +#include "python3/patch_data.hpp" #include "hdf5/phare_hdf5.hpp" @@ -10,14 +17,42 @@ #include "hdf5/detail/h5/h5_file.hpp" #endif -#include "amr/wrappers/hierarchy.hpp" // for HierarchyRestarter::getRestartFileFullPath - - - namespace py = pybind11; namespace PHARE::pydata { + +template +void declarePatchData(py::module& m, std::string key) +{ + using PatchDataType = PatchData; + py::class_(m, key.c_str()) + .def_readonly("patchID", &PatchDataType::patchID) + .def_readonly("origin", &PatchDataType::origin) + .def_readonly("lower", &PatchDataType::lower) + .def_readonly("upper", &PatchDataType::upper) + .def_readonly("nGhosts", &PatchDataType::nGhosts) + .def_readonly("data", &PatchDataType::data); +} + +template +void declareDim(py::module& m) +{ + using CP = core::ContiguousParticles; + std::string name = "ContiguousParticles_" + std::to_string(dim); + py::class_>(m, name.c_str()) + .def(py::init()) + .def_readwrite("iCell", &CP::iCell) + .def_readwrite("delta", &CP::delta) + .def_readwrite("weight", &CP::weight) + .def_readwrite("charge", &CP::charge) + .def_readwrite("v", &CP::v) + .def("size", &CP::size); + + name = "PatchData" + name; + declarePatchData(m, name.c_str()); +} + auto pybind_version() { std::stringstream ss; @@ -44,6 +79,18 @@ PYBIND11_MODULE(cpp_etc, m) py::class_, py::smart_holder>(m, "Span"); py::class_, py::smart_holder, core::Span>(m, "PyWrapper"); + + m.def("mpi_size", []() { return core::mpi::size(); }); + m.def("mpi_rank", []() { return core::mpi::rank(); }); + m.def("mpi_barrier", []() { core::mpi::barrier(); }); + + py::class_>(m, "SamraiLifeCycle") + .def(py::init<>()) + .def("reset", &SamraiLifeCycle::reset); + + py::class_>(m, "AMRHierarchy"); + m.def("make_hierarchy", []() { return PHARE::amr::Hierarchy::make(); }); + m.def("makePyArrayWrapper", makePyArrayWrapper); m.def("phare_deps", []() { @@ -81,5 +128,15 @@ PYBIND11_MODULE(cpp_etc, m) throw std::runtime_error("PHARE not built with highfive support"); }); + + + declareDim<1>(m); + declareDim<2>(m); + declareDim<3>(m); + + declarePatchData, 1>(m, "PatchDataVectorDouble_1D"); + declarePatchData, 2>(m, "PatchDataVectorDouble_2D"); + declarePatchData, 3>(m, "PatchDataVectorDouble_3D"); } + } // namespace PHARE::pydata diff --git a/src/python3/cpp_simulator.cpp b/src/python3/cpp_simulator.cpp index cf20c4666..5fe026986 100644 --- a/src/python3/cpp_simulator.cpp +++ b/src/python3/cpp_simulator.cpp @@ -1,28 +1,24 @@ +// PHARE_SIM_STR == template string, between <> +// PHARE_SIM_ID == string representing templates + +#if !defined(PHARE_SIM_STR) || !defined(PHARE_SIM_ID) +#error // needs PHARE_SIM_STR! like "1, 1, 1" +#endif // PHARE_SIM_STR + #include "python3/cpp_simulator.hpp" #if !defined(PHARE_CPP_MOD_NAME) -#define PHARE_CPP_MOD_NAME cpp +#define PHARE_CPP_MOD_NAME PHARE_STR_CAT(cpp_, PHARE_SIM_ID) #endif -namespace py = pybind11; namespace PHARE::pydata { PYBIND11_MODULE(PHARE_CPP_MOD_NAME, m) { - declarePatchData, 1>(m, "PatchDataVectorDouble_1D"); - declarePatchData, 2>(m, "PatchDataVectorDouble_2D"); - declarePatchData, 3>(m, "PatchDataVectorDouble_3D"); - - declare_essential(m); - - declareDim<1>(m); - declareDim<2>(m); - declareDim<3>(m); - - core::apply(core::possibleSimulators(), [&](auto const& simType) { declare_all(m, simType); }); + declare_macro_sim(m); } } // namespace PHARE::pydata diff --git a/src/python3/cpp_simulator.hpp b/src/python3/cpp_simulator.hpp index fc259bfc5..fff92aa11 100644 --- a/src/python3/cpp_simulator.hpp +++ b/src/python3/cpp_simulator.hpp @@ -1,63 +1,35 @@ #ifndef PHARE_PYTHON_CPP_SIMULATOR_HPP #define PHARE_PYTHON_CPP_SIMULATOR_HPP -#include "phare/phare.hpp" + +#ifndef PHARE_SIM_STR +#define PHARE_SIM_STR 1, 1, 2 // mostly for clangformat - errors in cpp file if define is missing +#endif #include "core/def/phare_mpi.hpp" // IWYU pragma: keep -#include "core/utilities/mpi_utils.hpp" +#include "amr/samrai.hpp" // IWYU pragma: keep #include "amr/wrappers/hierarchy.hpp" -#include "simulator/simulator.hpp" - -#include "pybind11/stl.h" // IWYU pragma: keep -#include "pybind11/numpy.h" // IWYU pragma: keep -#include "pybind11/chrono.h" // IWYU pragma: keep -#include "pybind11/complex.h" // IWYU pragma: keep -#include "pybind11/functional.h" // IWYU pragma: keep +#include "simulator/simulator.hpp" // IWYU pragma: keep -#include "python3/particles.hpp" -#include "python3/patch_data.hpp" -#include "python3/patch_level.hpp" -#include "python3/data_wrangler.hpp" +#include "python3/pybind_def.hpp" // IWYU pragma: keep +#include "pybind11/stl.h" // IWYU pragma: keep +#include "pybind11/numpy.h" // IWYU pragma: keep +#include "pybind11/chrono.h" // IWYU pragma: keep +#include "pybind11/complex.h" // IWYU pragma: keep +#include "pybind11/functional.h" // IWYU pragma: keep -#include +#include "python3/particles.hpp" // IWYU pragma: keep +#include "python3/patch_level.hpp" // IWYU pragma: keep +#include "python3/data_wrangler.hpp" // IWYU pragma: keep namespace py = pybind11; namespace PHARE::pydata { -template -void declarePatchData(py::module& m, std::string key) -{ - using PatchDataType = PatchData; - py::class_(m, key.c_str()) - .def_readonly("patchID", &PatchDataType::patchID) - .def_readonly("origin", &PatchDataType::origin) - .def_readonly("lower", &PatchDataType::lower) - .def_readonly("upper", &PatchDataType::upper) - .def_readonly("nGhosts", &PatchDataType::nGhosts) - .def_readonly("data", &PatchDataType::data); -} -template -void declareDim(py::module& m) -{ - using CP = core::ContiguousParticles; - std::string name = "ContiguousParticles_" + std::to_string(dim); - py::class_(m, name.c_str()) - .def(py::init()) - .def_readwrite("iCell", &CP::iCell) - .def_readwrite("delta", &CP::delta) - .def_readwrite("weight", &CP::weight) - .def_readwrite("charge", &CP::charge) - .def_readwrite("v", &CP::v) - .def("size", &CP::size); - - name = "PatchData" + name; - declarePatchData(m, name.c_str()); -} template void declareSimulator(PyClass&& sim) @@ -76,20 +48,14 @@ void declareSimulator(PyClass&& sim) .def("dump_restarts", &Simulator::dump_restarts, py::arg("timestamp"), py::arg("timestep")); } -template -void declare_etc(py::module& m) +template +void inline declare_etc(py::module& m) { - constexpr auto dim = _dim{}(); - constexpr auto interp = _interp{}(); - constexpr auto nbRefinedPart = _nbRefinedPart{}(); - constexpr auto opts = SimOpts{dim, interp, nbRefinedPart}; + constexpr auto opts = SimOpts{PHARE_SIM_STR}; - std::string const type_string = "_" + std::to_string(dim) + "_" + std::to_string(interp) + "_" - + std::to_string(nbRefinedPart); - - using Sim = Simulator; using DW = DataWrangler; - std::string name = "DataWrangler" + type_string; + std::string name = "DataWrangler"; + py::class_(m, name.c_str()) .def(py::init const&, std::shared_ptr const&>()) .def(py::init const&, std::shared_ptr const&>()) @@ -98,7 +64,7 @@ void declare_etc(py::module& m) .def("getNumberOfLevels", &DW::getNumberOfLevels); using PL = PatchLevel; - name = "PatchLevel_" + type_string; + name = "PatchLevel"; py::class_(m, name.c_str()) .def("getEM", &PL::getEM) .def("getE", &PL::getE) @@ -122,30 +88,25 @@ void declare_etc(py::module& m) .def("getParticles", &PL::getParticles, py::arg("userPopName") = "all"); using _Splitter - = PHARE::amr::Splitter<_dim, _interp, core::RefinedParticlesConst>; - name = "Splitter" + type_string; + = PHARE::amr::Splitter, core::InterpConst, + core::RefinedParticlesConst>; + name = "Splitter"; + py::class_<_Splitter, py::smart_holder>(m, name.c_str()) .def(py::init<>()) .def_property_readonly_static("weight", [](py::object) { return _Splitter::weight; }) .def_property_readonly_static("delta", [](py::object) { return _Splitter::delta; }); - name = "split_pyarray_particles" + type_string; + name = "split_pyarray_particles"; m.def(name.c_str(), splitPyArrayParticles<_Splitter>); } -template -void declare_sim(py::module& m) -{ - constexpr auto dim = _dim{}(); - constexpr auto interp = _interp{}(); - constexpr auto nbRefinedPart = _nbRefinedPart{}(); - constexpr auto opts = SimOpts{dim, interp, nbRefinedPart}; - std::string const type_string = "_" + std::to_string(dim) + "_" + std::to_string(interp) + "_" - + std::to_string(nbRefinedPart); +void inline declare_macro_sim(py::module& m) +{ + using Sim = Simulator; - using Sim = Simulator; - std::string name = "Simulator" + type_string; + std::string name = "Simulator"; declareSimulator( py::class_(m, name.c_str()) .def_property_readonly_static("dims", [](py::object) { return Sim::dimension; }) @@ -154,45 +115,13 @@ void declare_sim(py::module& m) .def_property_readonly_static("refined_particle_nbr", [](py::object) { return Sim::nbRefinedPart; })); - name = "make_simulator" + type_string; + name = "make_simulator"; m.def(name.c_str(), [](std::shared_ptr const& hier) { - return std::shared_ptr{std::move(makeSimulator(hier))}; + return makeSimulator(hier); }); -} - -template // possibly TORM on 3d PR -constexpr bool valid_simulator() -{ - return dim{}() < 3; -} - -template -void declare_all(py::module& m, std::tuple const&) -{ - core::apply(std::tuple{}, [&](auto& nbRefinedPart) { - using NbRefinedPart_t = std::decay_t; - - if constexpr (valid_simulator()) - { - declare_sim(m); - declare_etc(m); - } - }); -} - - -void inline declare_essential(py::module& m) -{ - py::class_(m, "SamraiLifeCycle") - .def(py::init<>()) - .def("reset", &SamraiLifeCycle::reset); - py::class_(m, "AMRHierarchy"); - m.def("make_hierarchy", []() { return PHARE::amr::Hierarchy::make(); }); - m.def("mpi_size", []() { return core::mpi::size(); }); - m.def("mpi_rank", []() { return core::mpi::rank(); }); - m.def("mpi_barrier", []() { core::mpi::barrier(); }); + declare_etc(m); } diff --git a/src/python3/patch_level.hpp b/src/python3/patch_level.hpp index 45076a0fb..1eb0f4156 100644 --- a/src/python3/patch_level.hpp +++ b/src/python3/patch_level.hpp @@ -8,6 +8,8 @@ #include #include +#include "python3/patch_data.hpp" + namespace PHARE::pydata { diff --git a/src/simulator/simulator.hpp b/src/simulator/simulator.hpp index b5c23faa8..ae92bc2c5 100644 --- a/src/simulator/simulator.hpp +++ b/src/simulator/simulator.hpp @@ -83,6 +83,16 @@ class Simulator : public ISimulator static_assert(std::is_same_v); + Simulator(PHARE::initializer::PHAREDict const& dict, + std::shared_ptr const& hierarchy); + + ~Simulator() + { + if (coutbuf != nullptr) + std::cout.rdbuf(coutbuf); + } + + NO_DISCARD double startTime() override { return startTime_; } NO_DISCARD double endTime() override { return finalTime_; } NO_DISCARD double timeStep() override { return dt_; } @@ -114,15 +124,6 @@ class Simulator : public ISimulator return false; } - Simulator(PHARE::initializer::PHAREDict const& dict, - std::shared_ptr const& hierarchy); - ~Simulator() - { - if (coutbuf != nullptr) - std::cout.rdbuf(coutbuf); - } - - protected: // provided to force flush for diags @@ -542,6 +543,7 @@ struct SimulatorMaker }; + template std::unique_ptr makeSimulator(std::shared_ptr const& hierarchy) { diff --git a/tests/amr/data/field/coarsening/CMakeLists.txt b/tests/amr/data/field/coarsening/CMakeLists.txt index f40d58001..b3a23864f 100644 --- a/tests/amr/data/field/coarsening/CMakeLists.txt +++ b/tests/amr/data/field/coarsening/CMakeLists.txt @@ -20,6 +20,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE phare_amr + phare_initializer ${GTEST_LIBS}) diff --git a/tests/amr/data/field/copy_pack/CMakeLists.txt b/tests/amr/data/field/copy_pack/CMakeLists.txt index 741362df4..b0f56924e 100644 --- a/tests/amr/data/field/copy_pack/CMakeLists.txt +++ b/tests/amr/data/field/copy_pack/CMakeLists.txt @@ -19,6 +19,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC target_link_libraries(${PROJECT_NAME} PUBLIC phare_amr + phare_initializer ${GTEST_LIBS}) add_subdirectory(copy) diff --git a/tests/amr/data/field/geometry/CMakeLists.txt b/tests/amr/data/field/geometry/CMakeLists.txt index 9897ec7d3..a3a0c4a5f 100644 --- a/tests/amr/data/field/geometry/CMakeLists.txt +++ b/tests/amr/data/field/geometry/CMakeLists.txt @@ -18,6 +18,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE phare_amr + phare_initializer ${GTEST_LIBS}) diff --git a/tests/amr/data/field/refine/CMakeLists.txt b/tests/amr/data/field/refine/CMakeLists.txt index 0ae782ae6..886482f35 100644 --- a/tests/amr/data/field/refine/CMakeLists.txt +++ b/tests/amr/data/field/refine/CMakeLists.txt @@ -23,7 +23,11 @@ function(_setup_amr_field_refine_test src_name) ${GTEST_INCLUDE_DIRS} ) - target_link_libraries(${src_name} PRIVATE phare_amr ${GTEST_LIBS}) + target_link_libraries(${src_name} PRIVATE + phare_amr + phare_initializer + ${GTEST_LIBS} + ) target_include_directories(${src_name} PRIVATE $) diff --git a/tests/amr/data/field/time_interpolate/CMakeLists.txt b/tests/amr/data/field/time_interpolate/CMakeLists.txt index ccad8b9af..4e8f9a83f 100644 --- a/tests/amr/data/field/time_interpolate/CMakeLists.txt +++ b/tests/amr/data/field/time_interpolate/CMakeLists.txt @@ -15,6 +15,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE phare_amr + phare_initializer ${GTEST_LIBS}) diff --git a/tests/amr/data/field/variable/CMakeLists.txt b/tests/amr/data/field/variable/CMakeLists.txt index d4549778c..c2ca4a5d0 100644 --- a/tests/amr/data/field/variable/CMakeLists.txt +++ b/tests/amr/data/field/variable/CMakeLists.txt @@ -15,6 +15,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE phare_amr + phare_initializer ${GTEST_LIBS}) diff --git a/tests/amr/data/particles/copy/CMakeLists.txt b/tests/amr/data/particles/copy/CMakeLists.txt index ef7fa06dd..f18ff3b3d 100644 --- a/tests/amr/data/particles/copy/CMakeLists.txt +++ b/tests/amr/data/particles/copy/CMakeLists.txt @@ -21,6 +21,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE phare_amr + phare_initializer ${GTEST_LIBS}) diff --git a/tests/amr/data/particles/copy_overlap/CMakeLists.txt b/tests/amr/data/particles/copy_overlap/CMakeLists.txt index 5f2d2acf3..cf30abf54 100644 --- a/tests/amr/data/particles/copy_overlap/CMakeLists.txt +++ b/tests/amr/data/particles/copy_overlap/CMakeLists.txt @@ -19,8 +19,10 @@ target_include_directories(${PROJECT_NAME} PRIVATE $ ) + target_link_libraries(${PROJECT_NAME} PRIVATE phare_amr + phare_initializer ${GTEST_LIBS}) diff --git a/tests/amr/data/particles/stream_pack/CMakeLists.txt b/tests/amr/data/particles/stream_pack/CMakeLists.txt index d09898458..ac69c825c 100644 --- a/tests/amr/data/particles/stream_pack/CMakeLists.txt +++ b/tests/amr/data/particles/stream_pack/CMakeLists.txt @@ -21,6 +21,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE phare_amr + phare_initializer ${GTEST_LIBS}) diff --git a/tests/amr/messengers/CMakeLists.txt b/tests/amr/messengers/CMakeLists.txt index 8d3afc5c4..6b4f86298 100644 --- a/tests/amr/messengers/CMakeLists.txt +++ b/tests/amr/messengers/CMakeLists.txt @@ -27,7 +27,8 @@ target_include_directories(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE phare_simulator pybind11::embed - ${GTEST_LIBS}) + ${GTEST_LIBS} +) add_phare_test(${PROJECT_NAME} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/amr/messengers/test_messengers.cpp b/tests/amr/messengers/test_messengers.cpp index e4aed31d7..6fc83dbf7 100644 --- a/tests/amr/messengers/test_messengers.cpp +++ b/tests/amr/messengers/test_messengers.cpp @@ -1,8 +1,7 @@ -#include "src/simulator/simulator.hpp" -#include "src/simulator/phare_types.hpp" -#include "src/phare/phare.hpp" +#include "amr/samrai.hpp" +#include "simulator/simulator.hpp" #include "test_messenger_basichierarchy.hpp" #include "test_integrator_strat.hpp" diff --git a/tests/amr/multiphysics_integrator/CMakeLists.txt b/tests/amr/multiphysics_integrator/CMakeLists.txt index 5154ef070..94ef510c1 100644 --- a/tests/amr/multiphysics_integrator/CMakeLists.txt +++ b/tests/amr/multiphysics_integrator/CMakeLists.txt @@ -22,7 +22,8 @@ target_include_directories(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE phare_simulator pybind11::embed - ${GTEST_LIBS}) + ${GTEST_LIBS} +) add_phare_test(${PROJECT_NAME} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/amr/tagging/CMakeLists.txt b/tests/amr/tagging/CMakeLists.txt index 33e42cc9e..4ee346732 100644 --- a/tests/amr/tagging/CMakeLists.txt +++ b/tests/amr/tagging/CMakeLists.txt @@ -19,6 +19,8 @@ target_include_directories(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE phare_amr + phare_diagnostic + phare_initializer ${GTEST_LIBS}) diff --git a/tests/amr/tagging/test_tagging.cpp b/tests/amr/tagging/test_tagging.cpp index e5b280f51..eb31994c8 100644 --- a/tests/amr/tagging/test_tagging.cpp +++ b/tests/amr/tagging/test_tagging.cpp @@ -1,21 +1,16 @@ -#include -#include -#include "phare_solver.hpp" -#include "amr/tagging/tagger.hpp" -#include "amr/tagging/tagger_factory.hpp" -#include "amr/resources_manager/resources_manager.hpp" -#include "core/data/ndarray/ndarray_vector.hpp" -#include "core/models/hybrid_state.hpp" -#include "core/utilities/span.hpp" +#include "simulator/simulator.hpp" + +#include "tests/core/data/gridlayout/gridlayout_test.hpp" +#include "tests/core/data/vecfield/test_vecfield_fixtures.hpp" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "tests/core/data/gridlayout/gridlayout_test.hpp" -#include "tests/core/data/vecfield/test_vecfield_fixtures.hpp" +#include +#include using namespace PHARE::amr; diff --git a/tests/core/data/field/test_field.hpp b/tests/core/data/field/test_field.hpp index f95fe5121..6f8322537 100644 --- a/tests/core/data/field/test_field.hpp +++ b/tests/core/data/field/test_field.hpp @@ -1,13 +1,14 @@ #ifndef PHARE_TEST_CORE_FIELD_TEST_HPP #define PHARE_TEST_CORE_FIELD_TEST_HPP -#include -#include #include "core/data/ndarray/ndarray_vector.hpp" -#include "gmock/gmock.h" -#include "gtest/gtest.h" +#include "gtest/gtest.h" // EXPECT_FLOAT_EQ + + +#include + namespace PHARE::core diff --git a/tests/functional/alfven_wave/alfven_wave1d.py b/tests/functional/alfven_wave/alfven_wave1d.py index a43b61293..7cbb3cd6b 100644 --- a/tests/functional/alfven_wave/alfven_wave1d.py +++ b/tests/functional/alfven_wave/alfven_wave1d.py @@ -133,10 +133,7 @@ def phase_speed(run_path, ampl, xmax): def main(): - from pyphare.cpp import cpp_lib - from pyphare.pharesee.run import Run - - cpp = cpp_lib() + from pyphare import cpp Simulator(config()).run() diff --git a/tests/functional/harris/harris_2d.py b/tests/functional/harris/harris_2d.py index 311c3d25e..9862381d6 100644 --- a/tests/functional/harris/harris_2d.py +++ b/tests/functional/harris/harris_2d.py @@ -5,15 +5,17 @@ from pathlib import Path import pyphare.pharein as ph -from pyphare.cpp import cpp_lib + +from pyphare import cpp + from pyphare.pharesee.run import Run -from pyphare.simulator.simulator import Simulator, startMPI +from pyphare.simulator.simulator import Simulator +from pyphare.simulator.simulator import startMPI from tests.simulator import SimulatorTest -ph.NO_GUI() -cpp = cpp_lib() +ph.NO_GUI() cells = (200, 100) diff --git a/tests/functional/ionIonBeam/ion_ion_beam1d.py b/tests/functional/ionIonBeam/ion_ion_beam1d.py index 43cb3b9f2..3a9512845 100644 --- a/tests/functional/ionIonBeam/ion_ion_beam1d.py +++ b/tests/functional/ionIonBeam/ion_ion_beam1d.py @@ -1,18 +1,18 @@ -import os +# +# +import os import numpy as np import pyphare.pharein as ph import matplotlib.pyplot as plt -from pyphare.cpp import cpp_lib +from pyphare import cpp from pyphare.simulator.simulator import Simulator from pyphare.pharesee.hierarchy.fromh5 import get_times_from_h5 from pyphare.pharesee.run import Run ph.NO_GUI() -cpp = cpp_lib() - def config(): # most unstable mode at k=0.19, that is lambda = 33 diff --git a/tests/functional/shock/shock.py b/tests/functional/shock/shock.py index 092407773..0edd1eb77 100644 --- a/tests/functional/shock/shock.py +++ b/tests/functional/shock/shock.py @@ -1,17 +1,18 @@ #!/usr/bin/env python3 -import pyphare.pharein as ph -from pyphare.simulator.simulator import Simulator, startMPI -from pyphare.pharesee.run import Run -import matplotlib.pyplot as plt -import matplotlib as mpl import numpy as np +import matplotlib.pyplot as plt + + +import pyphare.pharein as ph + +from pyphare import cpp +from pyphare.pharesee.run import Run +from pyphare.simulator.simulator import Simulator, startMPI -mpl.use("Agg") -from pyphare.cpp import cpp_lib -cpp = cpp_lib() +ph.NO_GUI() def config(interp_order): diff --git a/tests/functional/tdtagged/td1dtagged.py b/tests/functional/tdtagged/td1dtagged.py index 248e9f4f2..aa25563e2 100644 --- a/tests/functional/tdtagged/td1dtagged.py +++ b/tests/functional/tdtagged/td1dtagged.py @@ -12,9 +12,7 @@ from tests.simulator.test_advance import AdvanceTestBase from tests.diagnostic import all_timestamps -from pyphare.cpp import cpp_lib - -cpp = cpp_lib() +from pyphare import cpp mpl.use("Agg") diff --git a/tests/simulator/__init__.py b/tests/simulator/__init__.py index 3e131f81a..0876267a2 100644 --- a/tests/simulator/__init__.py +++ b/tests/simulator/__init__.py @@ -1,7 +1,6 @@ # # -import os import unittest import numpy as np from datetime import datetime @@ -164,6 +163,8 @@ def populate_simulation(dim, interp, **input): def diff_boxes(slice1, slice2, box, atol=None): + from pyphare.core.box import Box + if atol is not None: ignore = np.isclose(slice1, slice2, atol=atol, rtol=0) @@ -247,20 +248,19 @@ def run(self, result=None): super().run(result) def unique_diag_dir_for_test_case(self, base_path, ndim, interp, post_path=""): - from pyphare.cpp import cpp_lib + from pyphare import cpp - cpp = cpp_lib() return f"{base_path}/{self._testMethodName}/{cpp.mpi_size()}/{ndim}/{interp}/{post_path}" def clean_up_diags_dirs(self): - from pyphare.cpp import cpp_lib + from pyphare import cpp - cpp_lib().mpi_barrier() - if cpp_lib().mpi_rank() == 0 and self.success: + cpp.mpi_barrier() + if cpp.mpi_rank() == 0 and self.success: import os import shutil for diag_dir in self.diag_dirs: if os.path.exists(diag_dir): shutil.rmtree(diag_dir) - cpp_lib().mpi_barrier() + cpp.mpi_barrier() diff --git a/tests/simulator/data_wrangler.py b/tests/simulator/data_wrangler.py index f8fad0afb..31141965b 100644 --- a/tests/simulator/data_wrangler.py +++ b/tests/simulator/data_wrangler.py @@ -1,19 +1,11 @@ #!/usr/bin/env python3 -# -# formatted with black - import unittest import numpy as np -from pyphare.cpp import cpp_lib from pyphare.simulator.simulator import Simulator - from tests.simulator import populate_simulation -cpp = cpp_lib() - - # TODO - validate data from somewhere! diff --git a/tests/simulator/initialize/test_particles_init_1d.py b/tests/simulator/initialize/test_particles_init_1d.py index 8487a2e0f..2fcd92126 100644 --- a/tests/simulator/initialize/test_particles_init_1d.py +++ b/tests/simulator/initialize/test_particles_init_1d.py @@ -8,11 +8,10 @@ import matplotlib from ddt import data, ddt, unpack from pyphare.core.box import Box1D -from pyphare.cpp import cpp_lib + from tests.simulator.test_initialization import InitializationTest -cpp = cpp_lib() matplotlib.use("Agg") # for systems without GUI diff --git a/tests/simulator/per_test.hpp b/tests/simulator/per_test.hpp index ec4498367..c7e8c3a67 100644 --- a/tests/simulator/per_test.hpp +++ b/tests/simulator/per_test.hpp @@ -1,10 +1,12 @@ #ifndef PHARE_TEST_SIMULATOR_PER_TEST_HPP #define PHARE_TEST_SIMULATOR_PER_TEST_HPP -#include "phare/phare.hpp" +#include "amr/samrai.hpp" +#include "simulator/simulator.hpp" #include "initializer/python_data_provider.hpp" #include "tests/core/data/field/test_field.hpp" + #include "gtest/gtest.h" using SimOpts = PHARE::SimOpts; diff --git a/tests/simulator/refined_particle_nbr.py b/tests/simulator/refined_particle_nbr.py index 51182f07f..59b3271d3 100644 --- a/tests/simulator/refined_particle_nbr.py +++ b/tests/simulator/refined_particle_nbr.py @@ -9,15 +9,13 @@ import unittest import numpy as np -from pyphare.cpp import cpp_lib -from pyphare.cpp import splitter_type +from pyphare import cpp from pyphare.simulator.simulator import Simulator -from tests.simulator import NoOverwriteDict, populate_simulation +from tests.simulator import NoOverwriteDict +from tests.simulator import populate_simulation from tests.simulator.config import project_root -cpp = cpp_lib() - class SimulatorRefinedParticleNbr(unittest.TestCase): def __init__(self, *args, **kwargs): @@ -40,7 +38,7 @@ def _less_per_dim(self, dim, refined_particle_nbr, patch): return refined_particle_nbr * ((cellNbr[0] * 2 + (cellNbr[1] * 2))) raise ValueError("Unhandled dimension for function") - def _check_deltas_and_weights(self, dim, interp, refined_particle_nbr): + def _check_deltas_and_weights(self, sim, dim, interp, refined_particle_nbr): yaml_dim = self.yaml_root["dimension_" + str(dim)] yaml_interp = yaml_dim["interp_" + str(interp)] yaml_n_particles = yaml_interp["N_particles_" + str(refined_particle_nbr)] @@ -48,7 +46,7 @@ def _check_deltas_and_weights(self, dim, interp, refined_particle_nbr): yaml_delta = [float(s) for s in str(yaml_n_particles["delta"]).split(" ")] yaml_weight = [float(s) for s in str(yaml_n_particles["weight"]).split(" ")] - splitter_t = splitter_type(dim, interp, refined_particle_nbr) + splitter_t = cpp.splitter_type(sim) np.testing.assert_allclose(yaml_delta, splitter_t.delta) np.testing.assert_allclose(yaml_weight, splitter_t.weight) @@ -58,12 +56,14 @@ def _do_dim(self, dim, min_diff, max_diff): for interp in range(1, 4): prev_split_particle_max = 0 for refined_particle_nbr in valid_refined_particle_nbr[dim][interp]: - self._check_deltas_and_weights(dim, interp, refined_particle_nbr) simInput = NoOverwriteDict( {"refined_particle_nbr": refined_particle_nbr} ) - self.simulator = Simulator(populate_simulation(dim, interp, **simInput)) + sim = populate_simulation(dim, interp, **simInput) + self._check_deltas_and_weights(sim, dim, interp, refined_particle_nbr) + + self.simulator = Simulator(sim) self.simulator.initialize() dw = self.simulator.data_wrangler() max_per_pop = 0 diff --git a/tests/simulator/refinement/test_2d_10_core.py b/tests/simulator/refinement/test_2d_10_core.py index 79c1aab5b..71368ade8 100644 --- a/tests/simulator/refinement/test_2d_10_core.py +++ b/tests/simulator/refinement/test_2d_10_core.py @@ -10,10 +10,14 @@ import numpy as np + +from pyphare import cpp import pyphare.pharein as ph import pyphare.core.box as boxm from pyphare.simulator.simulator import Simulator, startMPI +from tests.simulator.test_advance import AdvanceTestBase + ph.NO_GUI() @@ -120,11 +124,6 @@ def get_hier(path): return get_time(path) -from pyphare.cpp import cpp_lib - -from tests.simulator.test_advance import AdvanceTestBase - -cpp = cpp_lib() test = AdvanceTestBase(rethrow=True) # change to False for debugging images L0_diags = "phare_outputs/test_x_homo_0" L0L1_diags = "phare_outputs/test_x_homo_1" diff --git a/tests/simulator/refinement/test_2d_2_core.py b/tests/simulator/refinement/test_2d_2_core.py index 22e0400ae..ac19a9d97 100644 --- a/tests/simulator/refinement/test_2d_2_core.py +++ b/tests/simulator/refinement/test_2d_2_core.py @@ -11,8 +11,8 @@ import numpy as np +from pyphare import cpp import pyphare.pharein as ph -from pyphare.cpp import cpp_lib import pyphare.core.box as boxm from pyphare.simulator.simulator import Simulator, startMPI @@ -147,7 +147,6 @@ def get_hier(path): return get_time(path) -cpp = cpp_lib() test = AdvanceTestBase(rethrow=True) # change to False for debugging images L0_diags = "phare_outputs/test_homo_0" L0L1_diags = "phare_outputs/test_homo_1" diff --git a/tests/simulator/test_advance.py b/tests/simulator/test_advance.py index e3abececb..102318c9d 100644 --- a/tests/simulator/test_advance.py +++ b/tests/simulator/test_advance.py @@ -1,13 +1,13 @@ # # - import unittest import numpy as np from ddt import ddt -import pyphare.core.box as boxm -from pyphare.cpp import cpp_lib + +from pyphare import cpp +import pyphare.core.box as boxm from pyphare.core.box import Box from pyphare.core.phare_utilities import assert_fp_any_all_close, np_array_ify from pyphare.pharein import ElectronModel, MaxwellianFluidModel @@ -26,8 +26,6 @@ from tests.diagnostic import all_timestamps from tests.simulator import SimulatorTest, diff_boxes -cpp = cpp_lib() - @ddt class AdvanceTestBase(SimulatorTest): diff --git a/tests/simulator/test_diagnostic_timestamps.py b/tests/simulator/test_diagnostic_timestamps.py index 2c9b624ba..8ddae1231 100644 --- a/tests/simulator/test_diagnostic_timestamps.py +++ b/tests/simulator/test_diagnostic_timestamps.py @@ -1,13 +1,13 @@ #!/usr/bin/env python3 - import os import unittest + import numpy as np from ddt import data, ddt import pyphare.pharein as ph -from pyphare.cpp import cpp_lib + from pyphare.core.box import Box1D from pyphare.pharein import ElectromagDiagnostics, ElectronModel from pyphare.pharesee.hierarchy import hierarchy_from @@ -15,8 +15,6 @@ from pyphare.pharesee.hierarchy.hierarchy import format_timestamp from pyphare.simulator.simulator import Simulator -cpp = cpp_lib() - def setup_model(ppc): def density(x): diff --git a/tests/simulator/test_diagnostics.py b/tests/simulator/test_diagnostics.py index ffad698f2..d24008384 100644 --- a/tests/simulator/test_diagnostics.py +++ b/tests/simulator/test_diagnostics.py @@ -6,18 +6,17 @@ import numpy as np from ddt import data, ddt +from pyphare import cpp import pyphare.pharein as ph -from pyphare.cpp import cpp_lib -from pyphare.simulator.simulator import startMPI -from pyphare.simulator.simulator import Simulator -from pyphare.pharesee.hierarchy import hierarchy_from + from pyphare.pharein.simulation import supported_dimensions from pyphare.pharesee.hierarchy.fromh5 import h5_filename_from, h5_time_grp_key +from pyphare.pharesee.hierarchy import hierarchy_from +from pyphare.simulator.simulator import Simulator +from pyphare.simulator.simulator import startMPI from tests.diagnostic import dump_all_diags -cpp = cpp_lib() - def setup_model(ppc=100): def density(*xyz): diff --git a/tests/simulator/test_initialization.py b/tests/simulator/test_initialization.py index 8a32d46ef..bf2ebe3ec 100644 --- a/tests/simulator/test_initialization.py +++ b/tests/simulator/test_initialization.py @@ -1,11 +1,11 @@ # # + import unittest import numpy as np from ddt import ddt -from pyphare.cpp import cpp_lib from pyphare.core.box import nDBox from pyphare.core.phare_utilities import assert_fp_any_all_close from pyphare.pharein import ElectronModel, MaxwellianFluidModel @@ -24,9 +24,6 @@ from tests.simulator import SimulatorTest -cpp = cpp_lib() - - @ddt class InitializationTest(SimulatorTest): def _density(*xyz): diff --git a/tests/simulator/test_load_balancing.py b/tests/simulator/test_load_balancing.py index 4ddaddf9b..c5bae9fef 100644 --- a/tests/simulator/test_load_balancing.py +++ b/tests/simulator/test_load_balancing.py @@ -3,22 +3,20 @@ # basically a harris run import unittest +import numpy as np from ddt import data, ddt, unpack + import pyphare.pharein as ph + +from pyphare import cpp +from pyphare.simulator.simulator import Simulator, startMPI from pyphare.pharesee.hierarchy.hierarchy_utils import hierarchy_compare from pyphare.pharesee.particles import single_patch_per_level_per_pop_from -from pyphare.simulator.simulator import Simulator, startMPI from tests.simulator import SimulatorTest -import numpy as np -import matplotlib as mpl - -mpl.use("Agg") - -from pyphare.cpp import cpp_lib -cpp = cpp_lib() +ph.NO_GUI() ndim = 2 diff --git a/tests/simulator/test_restarts.py b/tests/simulator/test_restarts.py index 47eaa5c55..8d36aabfa 100644 --- a/tests/simulator/test_restarts.py +++ b/tests/simulator/test_restarts.py @@ -2,7 +2,7 @@ # import copy -import time +from time import sleep import datetime import unittest import numpy as np @@ -11,9 +11,8 @@ from datetime import timedelta from ddt import ddt, data, unpack +from pyphare import cpp import pyphare.pharein as ph - -from pyphare.cpp import cpp_lib from pyphare.pharesee.run import Run from pyphare.simulator.simulator import Simulator @@ -22,8 +21,6 @@ from pyphare.pharesee.hierarchy.patchdata import ParticleData from pyphare.pharesee.hierarchy.fromh5 import get_all_available_quantities_from_h5 -cpp = cpp_lib() - def permute(dic, expected_num_levels): # from pyphare.pharein.simulation import supported_dimensions # eventually @@ -349,7 +346,7 @@ def test_restarts_elapsed_time(self, ndim, interp, simInput, expected_num_levels # autodump false to ignore possible init dump simulator = Simulator(ph.global_vars.sim, auto_dump=False).initialize() - time.sleep(5) + sleep(5) simulator.advance().dump() # should trigger restart on "restart_idx" advance simulator.advance().dump() simulator.reset() diff --git a/tests/simulator/test_run.py b/tests/simulator/test_run.py index 7d54c6fc6..66b19e908 100644 --- a/tests/simulator/test_run.py +++ b/tests/simulator/test_run.py @@ -2,17 +2,14 @@ import numpy as np from pathlib import Path -import matplotlib as mpl +from pyphare import cpp import pyphare.pharein as ph -from pyphare.cpp import cpp_lib from pyphare.simulator.simulator import Simulator, startMPI from pyphare.pharesee.run import Run from tests.simulator import SimulatorTest -mpl.use("Agg") - -cpp = cpp_lib() +ph.NO_GUI() time_step = 0.005 diff --git a/tests/simulator/test_tagging.py.off b/tests/simulator/test_tagging.py.off index c7a325335..eef5d63f3 100644 --- a/tests/simulator/test_tagging.py.off +++ b/tests/simulator/test_tagging.py.off @@ -2,16 +2,13 @@ # renamed to not be run on test discovery by directory -from pyphare.cpp import cpp_lib - -cpp = cpp_lib() - import os import unittest import numpy as np import pyphare.pharein as ph +from pyphare import cpp from ddt import data, ddt from pyphare.pharein import ElectronModel from pyphare.pharein.simulation import supported_dimensions diff --git a/tests/simulator/test_validation.py b/tests/simulator/test_validation.py index 9f5139160..13313dd3c 100644 --- a/tests/simulator/test_validation.py +++ b/tests/simulator/test_validation.py @@ -2,16 +2,13 @@ # # formatted with black - from ddt import data, ddt -from pyphare.cpp import cpp_lib from pyphare.core.box import Box, Box2D from pyphare.simulator.simulator import Simulator from tests.simulator import NoOverwriteDict, populate_simulation from tests.simulator import SimulatorTest -cpp = cpp_lib() out = "phare_outputs/valid/refinement_boxes/" diags = { diff --git a/tools/bench/amr/data/particles/copy_data.cpp b/tools/bench/amr/data/particles/copy_data.cpp index 9e1a2779d..e8c3f36b7 100644 --- a/tools/bench/amr/data/particles/copy_data.cpp +++ b/tools/bench/amr/data/particles/copy_data.cpp @@ -1,5 +1,5 @@ -#include "phare/phare.hpp" // samrai lifecycle +#include "amr/samrai.hpp" // IWYU pragma: keep #include "amr/data/particles/particles_data.hpp" diff --git a/tools/bench/hi5/write_particles.cpp b/tools/bench/hi5/write_particles.cpp index 3de35b889..bb2fdf49e 100644 --- a/tools/bench/hi5/write_particles.cpp +++ b/tools/bench/hi5/write_particles.cpp @@ -1,9 +1,10 @@ -#include "phare/phare.hpp" #include "core/data/particles/particle_array.hpp" #include "core/data/particles/particle_packer.hpp" +#include "amr/samrai.hpp" // IWYU pragma: keep + #include "hdf5/detail/hdf5_utils.hpp" #include "hdf5/detail/h5/h5_file.hpp" diff --git a/tools/bench/real/CMakeLists.txt b/tools/bench/real/CMakeLists.txt deleted file mode 100644 index c01f25ce5..000000000 --- a/tools/bench/real/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required (VERSION 3.20.1) - -project(phare_real_bench) - -pybind11_add_module(cpp_sim_2_1_4 sim/sim_2_1_4.cpp) -target_link_libraries(cpp_sim_2_1_4 PUBLIC phare_simulator) -target_compile_options(cpp_sim_2_1_4 PRIVATE ${PHARE_FLAGS} -DPHARE_HAS_HIGHFIVE=${PHARE_HAS_HIGHFIVE}) # pybind fails with Werror -set_target_properties(cpp_sim_2_1_4 - PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/pybindlibs" -) -# this is on by default "pybind11_add_module" but can interfere with coverage so we disable it if coverage is enabled -set_property(TARGET cpp_sim_2_1_4 PROPERTY INTERPROCEDURAL_OPTIMIZATION ${PHARE_INTERPROCEDURAL_OPTIMIZATION}) - diff --git a/tools/bench/real/bench_harris.py b/tools/bench/real/bench_harris.py deleted file mode 100644 index 3f50c5fb8..000000000 --- a/tools/bench/real/bench_harris.py +++ /dev/null @@ -1,131 +0,0 @@ -import numpy as np -from pyphare.cpp import cpp_lib # must be first - -cpp_lib("pybindlibs.cpp_sim_2_1_4") -import pyphare.pharein as ph - -seed = 133333333337 -cells, dl = 100, 0.2 -patch_sizes = [50, 100] -diag_outputs = "tools/bench/real/harris/outputs" - - -def density(x, y): - L = ph.global_vars.sim.simulation_domain()[1] - return ( - 0.2 - + 1.0 / np.cosh((y - L * 0.3) / 0.5) ** 2 - + 1.0 / np.cosh((y - L * 0.7) / 0.5) ** 2 - ) - - -def by(x, y): - sim = ph.global_vars.sim - Lx = sim.simulation_domain()[0] - Ly = sim.simulation_domain()[1] - w1, w2 = 0.2, 1.0 - x0 = x - 0.5 * Lx - y1 = y - 0.3 * Ly - y2 = y - 0.7 * Ly - w3 = np.exp(-(x0 * x0 + y1 * y1) / (w2 * w2)) - w4 = np.exp(-(x0 * x0 + y2 * y2) / (w2 * w2)) - w5 = 2.0 * w1 / w2 - return (w5 * x0 * w3) + (-w5 * x0 * w4) - - -def S(y, y0, l): - return 0.5 * (1.0 + np.tanh((y - y0) / l)) - - -def bx(x, y): - sim = ph.global_vars.sim - Lx = sim.simulation_domain()[0] - Ly = sim.simulation_domain()[1] - w1, w2 = 0.2, 1.0 - x0 = x - 0.5 * Lx - y1 = y - 0.3 * Ly - y2 = y - 0.7 * Ly - w3 = np.exp(-(x0 * x0 + y1 * y1) / (w2 * w2)) - w4 = np.exp(-(x0 * x0 + y2 * y2) / (w2 * w2)) - w5 = 2.0 * w1 / w2 - v1, v2 = -1, 1.0 - return ( - v1 - + (v2 - v1) * (S(y, Ly * 0.3, 0.5) - S(y, Ly * 0.7, 0.5)) - + (-w5 * y1 * w3) - + (+w5 * y2 * w4) - ) - - -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): - return 1.0 / density(x, y) * (1 - b2(x, y) * 0.5) - - -def vxyz(x, y): - return 0.0 - - -def vthxyz(x, y): - return np.sqrt(T(x, y)) - - -def config(): - ph.Simulation( # strict=True, - smallest_patch_size=patch_sizes[0], - largest_patch_size=patch_sizes[1], - time_step_nbr=10, - time_step=0.001, - cells=[cells] * 2, - dl=[dl] * 2, - resistivity=0.001, - hyper_resistivity=0.001, - diag_options={ - "format": "phareh5", - "options": {"dir": diag_outputs, "mode": "overwrite"}, - }, - refinement_boxes={}, - ) - ph.MaxwellianFluidModel( - bx=bx, - by=by, - bz=bz, - protons={ - "charge": 1, - "density": density, - "init": {"seed": seed}, - **{ - "nbr_part_per_cell": 100, - "vbulkx": vxyz, - "vbulky": vxyz, - "vbulkz": vxyz, - "vthx": vthxyz, - "vthy": vthxyz, - "vthz": vthxyz, - }, - }, - ) - ph.ElectronModel(closure="isothermal", Te=0.0) - - from tests.diagnostic import all_timestamps - - timestamps = all_timestamps(ph.global_vars.sim) - timestamps = np.asarray([timestamps[0], timestamps[-1]]) - for quantity in ["E", "B"]: - ph.ElectromagDiagnostics(quantity=quantity, write_timestamps=timestamps) - - -if ph.PHARE_EXE or __name__ == "__main__": - config() - -if __name__ == "__main__": - from pyphare.simulator.simulator import Simulator - - Simulator(ph.global_vars.sim).run() diff --git a/tools/bench/real/sim/sim_2_1_4.cpp b/tools/bench/real/sim/sim_2_1_4.cpp deleted file mode 100644 index 3a84bb314..000000000 --- a/tools/bench/real/sim/sim_2_1_4.cpp +++ /dev/null @@ -1,16 +0,0 @@ - - -#include "python3/cpp_simulator.hpp" - -namespace PHARE::pydata -{ -PYBIND11_MODULE(cpp_sim_2_1_4, m) -{ - using dim = std::integral_constant; - using interp = std::integral_constant; - using nbRefinePart = std::integral_constant; - - declare_essential(m); - declare_sim(m); -} -} // namespace PHARE::pydata From 5935af34f226ef6846e27ab4eb531cdd4d16acf2 Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Wed, 21 Jan 2026 15:01:03 +0100 Subject: [PATCH 2/6] allow real type simulation --- src/amr/CMakeLists.txt | 1 - src/python3/data_wrangler.hpp | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/amr/CMakeLists.txt b/src/amr/CMakeLists.txt index 2535cd0bd..15113ae57 100644 --- a/src/amr/CMakeLists.txt +++ b/src/amr/CMakeLists.txt @@ -104,7 +104,6 @@ target_link_libraries(${PROJECT_NAME} PUBLIC SAMRAI_xfer MPI::MPI_C cppdict - ) ) if (HighFive) # SAMRAI USES HDF5 so we need this here diff --git a/src/python3/data_wrangler.hpp b/src/python3/data_wrangler.hpp index ab6061d83..05628bdc7 100644 --- a/src/python3/data_wrangler.hpp +++ b/src/python3/data_wrangler.hpp @@ -72,11 +72,18 @@ class __attribute__((visibility("hidden"))) DataWrangler using Simulator = PHARE::Simulator; using HybridModel = Simulator::HybridModel; + + DataWrangler(std::shared_ptr const& simulator, + std::shared_ptr const& hierarchy) + : simulator_{*simulator} + , hierarchy_{hierarchy} + { + } + DataWrangler(std::shared_ptr const& simulator, std::shared_ptr const& hierarchy) : simulator_{cast_simulator(simulator)} , hierarchy_{hierarchy} - { } @@ -178,7 +185,7 @@ class __attribute__((visibility("hidden"))) DataWrangler simDict["dimension"].template to(), simDict["interp_order"].template to(), simDict["refined_particle_nbr"].template to(), SimulatorCaster{simulator}); if (!simulator_ptr) - throw std::runtime_error("Data Wranger creation error: failed to cast Simulator"); + throw std::runtime_error("Data Wrangler creation error: failed to cast Simulator"); return *simulator_ptr; } From 9725d83af17f5006238b9e168539833c57d16a93 Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Wed, 21 Jan 2026 15:13:51 +0100 Subject: [PATCH 3/6] document samrai shared library requirements --- ISSUES.TXT | 5 +++++ res/__tc/clang/0_config.sh | 6 ------ res/__tc/clang/1_build.sh | 20 ------------------ res/__tc/clang/2_test.sh | 27 ------------------------ res/__tc/clang/3_test_mpi.sh | 31 ---------------------------- res/__tc/clang_samraisub/0_config.sh | 6 ------ res/__tc/clang_samraisub/1_build.sh | 15 -------------- res/__tc/clang_samraisub/2_test.sh | 19 ----------------- res/__tc/gcc/0_config.sh | 6 ------ res/__tc/gcc/1_build.sh | 17 --------------- res/__tc/gcc/2_test.sh | 19 ----------------- res/__tc/gcc/3_test_mpi.sh | 23 --------------------- res/__tc/gcc_samraisub/0_config.sh | 6 ------ res/__tc/gcc_samraisub/1_build.sh | 14 ------------- res/__tc/gcc_samraisub/2_test.sh | 19 ----------------- res/__tc/nightly/0_config.sh | 6 ------ res/__tc/nightly/1_build.sh | 14 ------------- res/__tc/nightly/2_test.sh | 19 ----------------- res/__tc/nightly/3_test_mpi.sh | 24 --------------------- 19 files changed, 5 insertions(+), 291 deletions(-) delete mode 100644 res/__tc/clang/0_config.sh delete mode 100644 res/__tc/clang/1_build.sh delete mode 100644 res/__tc/clang/2_test.sh delete mode 100644 res/__tc/clang/3_test_mpi.sh delete mode 100644 res/__tc/clang_samraisub/0_config.sh delete mode 100644 res/__tc/clang_samraisub/1_build.sh delete mode 100644 res/__tc/clang_samraisub/2_test.sh delete mode 100644 res/__tc/gcc/0_config.sh delete mode 100644 res/__tc/gcc/1_build.sh delete mode 100644 res/__tc/gcc/2_test.sh delete mode 100644 res/__tc/gcc/3_test_mpi.sh delete mode 100644 res/__tc/gcc_samraisub/0_config.sh delete mode 100644 res/__tc/gcc_samraisub/1_build.sh delete mode 100644 res/__tc/gcc_samraisub/2_test.sh delete mode 100644 res/__tc/nightly/0_config.sh delete mode 100644 res/__tc/nightly/1_build.sh delete mode 100644 res/__tc/nightly/2_test.sh delete mode 100644 res/__tc/nightly/3_test_mpi.sh diff --git a/ISSUES.TXT b/ISSUES.TXT index d4e3d3a9d..c3feb4fca 100644 --- a/ISSUES.TXT +++ b/ISSUES.TXT @@ -27,3 +27,8 @@ Outline the context of your issue, and upload the zip Solution: LD_PRELOAD=/path/to/your/libmpi.so python3 $SCRIPT +3. SAMRAI libraries used by PHARE python modules must not be static archives. + SAMRAI has static singletons which may exist more than once. + This will likely lead to unsatisfactory results. + By default, PHARE will build SAMRAI in place with shared libaries, + The CMake flag `-DSAMRAI_ROOT=/path` may be used to target an existing installation diff --git a/res/__tc/clang/0_config.sh b/res/__tc/clang/0_config.sh deleted file mode 100644 index 89dc08ae0..000000000 --- a/res/__tc/clang/0_config.sh +++ /dev/null @@ -1,6 +0,0 @@ -pwd -set -ex -ulimit -a -clang -v -ldd --version -ld -v diff --git a/res/__tc/clang/1_build.sh b/res/__tc/clang/1_build.sh deleted file mode 100644 index ceb6eea19..000000000 --- a/res/__tc/clang/1_build.sh +++ /dev/null @@ -1,20 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -export CC=clang -export CXX=clang++ -export ASAN_OPTIONS=detect_leaks=0 - -( - mkdir build && cd build - cmake .. -G Ninja -Dasan=ON \ - -DdevMode=ON \ - -DCMAKE_BUILD_TYPE=Debug \ - -Dphare_configurator=ON -DSAMRAI_ROOT=/usr/local \ - -DCMAKE_CXX_FLAGS="-g3 -O3 -march=native -mtune=native -DPHARE_DIAG_DOUBLES=1" - - # NO SUBPROJECT SAMRAI EXPECTED! - [ -d ../subprojects/samrai ] && exit 1 - ninja -j$N_CORES -v -) diff --git a/res/__tc/clang/2_test.sh b/res/__tc/clang/2_test.sh deleted file mode 100644 index 3039378ec..000000000 --- a/res/__tc/clang/2_test.sh +++ /dev/null @@ -1,27 +0,0 @@ -set -ex -pwd -ulimit -a - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -export TMPDIR=/tmp -export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles -export GTEST_OUTPUT=xml:gtest_out.xml - -# prevent blas_thread_server from spawning a bajillion threads -export OMP_NUM_THREADS=1 -export OPENBLAS_NUM_THREADS=1 -export MKL_NUM_THREADS=1 -export VECLIB_MAXIMUM_THREADS=1 -export NUMEXPR_NUM_THREADS=1 - - -export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer -export ASAN_OPTIONS=detect_leaks=0 -GCC_ASAN_PRELOAD=$(gcc -print-file-name=libasan.so) -CLANG_ASAN_PRELOAD=$(clang -print-file-name=libclang_rt.asan.so) - -( - cd build - LD_PRELOAD=$CLANG_ASAN_PRELOAD ctest -j$N_CORES --output-on-failure -) diff --git a/res/__tc/clang/3_test_mpi.sh b/res/__tc/clang/3_test_mpi.sh deleted file mode 100644 index 18f169402..000000000 --- a/res/__tc/clang/3_test_mpi.sh +++ /dev/null @@ -1,31 +0,0 @@ -set -ex -pwd -ulimit -a - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -export TMPDIR=/tmp -export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles -export GTEST_OUTPUT=xml:gtest_out.xml - -# prevent blas_thread_server from spawning a bajillion threads -export OMP_NUM_THREADS=1 -export OPENBLAS_NUM_THREADS=1 -export MKL_NUM_THREADS=1 -export VECLIB_MAXIMUM_THREADS=1 -export NUMEXPR_NUM_THREADS=1 - - -export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer -export ASAN_OPTIONS=detect_leaks=0 -GCC_ASAN_PRELOAD=$(gcc -print-file-name=libasan.so) -CLANG_ASAN_PRELOAD=$(clang -print-file-name=libclang_rt.asan.so) - -( - cd build - cmake .. -G Ninja -Dasan=ON -DtestMPI=ON \ - -DdevMode=ON -Dcppcheck=ON \ - -DCMAKE_CXX_FLAGS="-O3 -g3" -Dphare_configurator=ON - ninja -j$N_CORES -v - LD_PRELOAD=$CLANG_ASAN_PRELOAD ctest -j$N_CORES --output-on-failure -) diff --git a/res/__tc/clang_samraisub/0_config.sh b/res/__tc/clang_samraisub/0_config.sh deleted file mode 100644 index 89dc08ae0..000000000 --- a/res/__tc/clang_samraisub/0_config.sh +++ /dev/null @@ -1,6 +0,0 @@ -pwd -set -ex -ulimit -a -clang -v -ldd --version -ld -v diff --git a/res/__tc/clang_samraisub/1_build.sh b/res/__tc/clang_samraisub/1_build.sh deleted file mode 100644 index 2c13d6f0c..000000000 --- a/res/__tc/clang_samraisub/1_build.sh +++ /dev/null @@ -1,15 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -( - mkdir build && cd build - cmake .. -G Ninja \ - -DdevMode=ON \ - -DCMAKE_BUILD_TYPE=Debug \ - -Dphare_configurator=ON \ - -DCMAKE_CXX_FLAGS="-g3 -O3 -march=native -mtune=native -DPHARE_DIAG_DOUBLES=1" - - [ -d ../subprojects/samrai ] && exit 1 - ninja -j$N_CORES -v -) diff --git a/res/__tc/clang_samraisub/2_test.sh b/res/__tc/clang_samraisub/2_test.sh deleted file mode 100644 index 1679c8f7d..000000000 --- a/res/__tc/clang_samraisub/2_test.sh +++ /dev/null @@ -1,19 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -export TMPDIR=/tmp -export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles -export GTEST_OUTPUT=xml:gtest_out.xml - -# prevent blas_thread_server from spawning a bajillion threads -export OMP_NUM_THREADS=1 -export OPENBLAS_NUM_THREADS=1 -export MKL_NUM_THREADS=1 -export VECLIB_MAXIMUM_THREADS=1 -export NUMEXPR_NUM_THREADS=1 - -( - cd build - ctest -j$N_CORES --output-on-failure -) diff --git a/res/__tc/gcc/0_config.sh b/res/__tc/gcc/0_config.sh deleted file mode 100644 index 702fe6519..000000000 --- a/res/__tc/gcc/0_config.sh +++ /dev/null @@ -1,6 +0,0 @@ -pwd -set -ex -ulimit -a -gcc -v -ldd --version -ld -v diff --git a/res/__tc/gcc/1_build.sh b/res/__tc/gcc/1_build.sh deleted file mode 100644 index e6882fbcc..000000000 --- a/res/__tc/gcc/1_build.sh +++ /dev/null @@ -1,17 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -( - mkdir build && cd build - cmake .. -G Ninja -Dasan=ON \ - -DdevMode=ON -Dcppcheck=ON \ - -DCMAKE_BUILD_TYPE=Debug \ - -Dphare_configurator=ON -DSAMRAI_ROOT=/usr/local \ - -DCMAKE_CXX_FLAGS="-g3 -O3 -march=native -mtune=native -DPHARE_DIAG_DOUBLES=1" - - - # NO SUBPROJECT SAMRAI EXPECTED! - [ -d ../subprojects/samrai ] && exit 1 - ninja -j$N_CORES -v -) diff --git a/res/__tc/gcc/2_test.sh b/res/__tc/gcc/2_test.sh deleted file mode 100644 index 1679c8f7d..000000000 --- a/res/__tc/gcc/2_test.sh +++ /dev/null @@ -1,19 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -export TMPDIR=/tmp -export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles -export GTEST_OUTPUT=xml:gtest_out.xml - -# prevent blas_thread_server from spawning a bajillion threads -export OMP_NUM_THREADS=1 -export OPENBLAS_NUM_THREADS=1 -export MKL_NUM_THREADS=1 -export VECLIB_MAXIMUM_THREADS=1 -export NUMEXPR_NUM_THREADS=1 - -( - cd build - ctest -j$N_CORES --output-on-failure -) diff --git a/res/__tc/gcc/3_test_mpi.sh b/res/__tc/gcc/3_test_mpi.sh deleted file mode 100644 index 1a90db6f0..000000000 --- a/res/__tc/gcc/3_test_mpi.sh +++ /dev/null @@ -1,23 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -export TMPDIR=/tmp -export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles -export GTEST_OUTPUT=xml:gtest_out.xml - -# prevent blas_thread_server from spawning a bajillion threads -export OMP_NUM_THREADS=1 -export OPENBLAS_NUM_THREADS=1 -export MKL_NUM_THREADS=1 -export VECLIB_MAXIMUM_THREADS=1 -export NUMEXPR_NUM_THREADS=1 - -( - cd build - cmake .. -G Ninja -DtestMPI=ON \ - -DdevMode=ON -Dcppcheck=ON \ - -DCMAKE_CXX_FLAGS="-O3 -g3" -Dphare_configurator=ON - ninja -j$N_CORES -v - ctest -j$N_CORES --output-on-failure -) diff --git a/res/__tc/gcc_samraisub/0_config.sh b/res/__tc/gcc_samraisub/0_config.sh deleted file mode 100644 index 702fe6519..000000000 --- a/res/__tc/gcc_samraisub/0_config.sh +++ /dev/null @@ -1,6 +0,0 @@ -pwd -set -ex -ulimit -a -gcc -v -ldd --version -ld -v diff --git a/res/__tc/gcc_samraisub/1_build.sh b/res/__tc/gcc_samraisub/1_build.sh deleted file mode 100644 index c49082803..000000000 --- a/res/__tc/gcc_samraisub/1_build.sh +++ /dev/null @@ -1,14 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -( - mkdir build && cd build - cmake .. -G Ninja \ - -DdevMode=ON \ - -DCMAKE_BUILD_TYPE=Debug \ - -Dphare_configurator=ON \ - -DCMAKE_CXX_FLAGS="-g3 -O3 -march=native -mtune=native -DPHARE_DIAG_DOUBLES=1" - - ninja -j$N_CORES -v -) diff --git a/res/__tc/gcc_samraisub/2_test.sh b/res/__tc/gcc_samraisub/2_test.sh deleted file mode 100644 index 1679c8f7d..000000000 --- a/res/__tc/gcc_samraisub/2_test.sh +++ /dev/null @@ -1,19 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -export TMPDIR=/tmp -export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles -export GTEST_OUTPUT=xml:gtest_out.xml - -# prevent blas_thread_server from spawning a bajillion threads -export OMP_NUM_THREADS=1 -export OPENBLAS_NUM_THREADS=1 -export MKL_NUM_THREADS=1 -export VECLIB_MAXIMUM_THREADS=1 -export NUMEXPR_NUM_THREADS=1 - -( - cd build - ctest -j$N_CORES --output-on-failure -) diff --git a/res/__tc/nightly/0_config.sh b/res/__tc/nightly/0_config.sh deleted file mode 100644 index 702fe6519..000000000 --- a/res/__tc/nightly/0_config.sh +++ /dev/null @@ -1,6 +0,0 @@ -pwd -set -ex -ulimit -a -gcc -v -ldd --version -ld -v diff --git a/res/__tc/nightly/1_build.sh b/res/__tc/nightly/1_build.sh deleted file mode 100644 index 65db93349..000000000 --- a/res/__tc/nightly/1_build.sh +++ /dev/null @@ -1,14 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -( - mkdir build && cd build - cmake .. -G Ninja \ - -DdevMode=ON -Dcppcheck=ON \ - -DCMAKE_BUILD_TYPE=Debug \ - -Dphare_configurator=ON \ - -DCMAKE_CXX_FLAGS="-g3 -O3 -march=native -mtune=native -DPHARE_DIAG_DOUBLES=1" - - ninja -j$N_CORES -v -) diff --git a/res/__tc/nightly/2_test.sh b/res/__tc/nightly/2_test.sh deleted file mode 100644 index 1679c8f7d..000000000 --- a/res/__tc/nightly/2_test.sh +++ /dev/null @@ -1,19 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -export TMPDIR=/tmp -export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles -export GTEST_OUTPUT=xml:gtest_out.xml - -# prevent blas_thread_server from spawning a bajillion threads -export OMP_NUM_THREADS=1 -export OPENBLAS_NUM_THREADS=1 -export MKL_NUM_THREADS=1 -export VECLIB_MAXIMUM_THREADS=1 -export NUMEXPR_NUM_THREADS=1 - -( - cd build - ctest -j$N_CORES --output-on-failure -) diff --git a/res/__tc/nightly/3_test_mpi.sh b/res/__tc/nightly/3_test_mpi.sh deleted file mode 100644 index 2c208ed94..000000000 --- a/res/__tc/nightly/3_test_mpi.sh +++ /dev/null @@ -1,24 +0,0 @@ -set -ex - -[ -z "$N_CORES" ] && echo "N_CORES not set: error" && exit 1 - -export TMPDIR=/tmp -export MODULEPATH=/etc/scl/modulefiles:/etc/scl/modulefiles:/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles -export GTEST_OUTPUT=xml:gtest_out.xml - -# prevent blas_thread_server from spawning a bajillion threads -export OMP_NUM_THREADS=1 -export OPENBLAS_NUM_THREADS=1 -export MKL_NUM_THREADS=1 -export VECLIB_MAXIMUM_THREADS=1 -export NUMEXPR_NUM_THREADS=1 - - -( - cd build - cmake .. -G Ninja -DtestMPI=ON \ - -DdevMode=ON -Dcppcheck=ON \ - -DCMAKE_CXX_FLAGS="-O3 -g3" -Dphare_configurator=ON - ninja -j$N_CORES -v - ctest -j$N_CORES --output-on-failure -) From 9573dff6834846a38ca0cfe6be17a39dd001fab2 Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Thu, 22 Jan 2026 17:44:58 +0100 Subject: [PATCH 4/6] clearer restart file usage --- res/cmake/dep/samrai.cmake | 8 ------ src/amr/wrappers/hierarchy.hpp | 45 +++++++++++++++++----------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/res/cmake/dep/samrai.cmake b/res/cmake/dep/samrai.cmake index 5c940d492..09a70a71a 100644 --- a/res/cmake/dep/samrai.cmake +++ b/res/cmake/dep/samrai.cmake @@ -35,12 +35,4 @@ else() unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY CACHE) # undoes what samrai does, so ctest can continue to work include_directories(${CMAKE_BINARY_DIR}/include) # this is needed to find build-dir/include/SAMRAI/SAMRAI_config.h - - # REMOVE AFTER MERGED https://github.com/LLNL/SAMRAI/pull/294 - target_link_libraries(SAMRAI_algs PUBLIC SAMRAI_mesh) - target_link_libraries(SAMRAI_appu PUBLIC SAMRAI_geom) - target_link_libraries(SAMRAI_mesh PUBLIC SAMRAI_pdat) - target_link_libraries(SAMRAI_solv PUBLIC SAMRAI_geom) - - endif(DEFINED SAMRAI_ROOT) diff --git a/src/amr/wrappers/hierarchy.hpp b/src/amr/wrappers/hierarchy.hpp index 83953ca28..201cdcddf 100644 --- a/src/amr/wrappers/hierarchy.hpp +++ b/src/amr/wrappers/hierarchy.hpp @@ -45,40 +45,32 @@ class HierarchyRestarter { public: HierarchyRestarter(initializer::PHAREDict const& _sim_dict) - : sim_dict{_sim_dict} + : _restartFilePath{restartFilePath(_sim_dict)} + , sim_dict{_sim_dict} { - if (sim_dict["simulation"].contains("restarts")) + if (_restartFilePath) { - auto& dict = sim_dict["simulation"]["restarts"]; - - if (dict.contains("loadPath")) - { - auto restart_manager = SamraiLifeCycle::getRestartManager(); - auto pdrm = SamraiLifeCycle::getPatchDataRestartManager(); + auto& dict = sim_dict["simulation"]["restarts"]; + auto restart_manager = SamraiLifeCycle::getRestartManager(); + auto pdrm = SamraiLifeCycle::getPatchDataRestartManager(); - for (auto& id : dict["restart_ids"].template to>()) - pdrm->registerPatchDataForRestart(id); + for (auto& id : dict["restart_ids"].template to>()) + pdrm->registerPatchDataForRestart(id); - int timeStepIdx = 0; // forced to zero as we wrap in our own timestamp directories - auto& directory = dict["loadPath"].template to(); - restart_manager->openRestartFile(directory, timeStepIdx, core::mpi::size()); - } + int timeStepIdx = 0; // forced to zero as we wrap in our own timestamp directories + restart_manager->openRestartFile(*_restartFilePath, timeStepIdx, core::mpi::size()); } } ~HierarchyRestarter() { - if (sim_dict["simulation"].contains("restarts")) + if (_restartFilePath) { auto& dict = sim_dict["simulation"]["restarts"]; + auto pdrm = SamraiLifeCycle::getPatchDataRestartManager(); - if (dict.contains("loadPath")) - { - auto pdrm = SamraiLifeCycle::getPatchDataRestartManager(); - - for (auto& id : dict["restart_ids"].template to>()) - pdrm->unregisterPatchDataForRestart(id); - } + for (auto& id : dict["restart_ids"].template to>()) + pdrm->unregisterPatchDataForRestart(id); } } @@ -102,6 +94,15 @@ class HierarchyRestarter } private: + std::optional static restartFilePath(auto const& dict) + { + if (dict["simulation"].contains("restarts")) + if (dict["simulation"]["restarts"].contains("loadPath")) + return dict["simulation"]["restarts"]["loadPath"].template to(); + return std::nullopt; + } + + std::optional _restartFilePath; // only set if we have a restart to load initializer::PHAREDict sim_dict; }; From 26d46669cf38ab41350596b8665afcdbdbcc04cb Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Sun, 25 Jan 2026 15:27:30 +0100 Subject: [PATCH 5/6] ++ --- ISSUES.TXT | 2 +- res/cmake/dep/samrai.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ISSUES.TXT b/ISSUES.TXT index c3feb4fca..a54983b2d 100644 --- a/ISSUES.TXT +++ b/ISSUES.TXT @@ -30,5 +30,5 @@ Outline the context of your issue, and upload the zip 3. SAMRAI libraries used by PHARE python modules must not be static archives. SAMRAI has static singletons which may exist more than once. This will likely lead to unsatisfactory results. - By default, PHARE will build SAMRAI in place with shared libaries, + By default, PHARE will build SAMRAI in place with shared libraries, The CMake flag `-DSAMRAI_ROOT=/path` may be used to target an existing installation diff --git a/res/cmake/dep/samrai.cmake b/res/cmake/dep/samrai.cmake index 09a70a71a..0db7cb838 100644 --- a/res/cmake/dep/samrai.cmake +++ b/res/cmake/dep/samrai.cmake @@ -25,7 +25,7 @@ else() endif() if(SAMRAI_BUILD_SHARED_LIBS) - option(BUILD_SHARED_LIBS "Make shared libs" ON ) # default as of 15/JUL/2025 is static libs + set(BUILD_SHARED_LIBS ON CACHE BOOL "Make shared libs" FORCE) # default as of 25/JAN/2026 is static libs endif(SAMRAI_BUILD_SHARED_LIBS) option(ENABLE_TESTS "Enable Samrai Test" OFF ) # disable SAMRAI Test so that we can use the googletest pulled after From 6c5c24b6f0a0397c9a2c710b69602a24208164d1 Mon Sep 17 00:00:00 2001 From: deegan Date: Mon, 26 Jan 2026 15:44:09 +0100 Subject: [PATCH 6/6] :rabbit: --- src/python3/patch_level.hpp | 4 +--- tests/functional/shock/shock.py | 8 +++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/python3/patch_level.hpp b/src/python3/patch_level.hpp index 1eb0f4156..44d141f76 100644 --- a/src/python3/patch_level.hpp +++ b/src/python3/patch_level.hpp @@ -1,15 +1,13 @@ #ifndef PHARE_PYTHON_PATCH_LEVEL_HPP #define PHARE_PYTHON_PATCH_LEVEL_HPP -#include "patch_data.hpp" #include "phare_solver.hpp" +#include "python3/patch_data.hpp" #include #include #include -#include "python3/patch_data.hpp" - namespace PHARE::pydata { diff --git a/tests/functional/shock/shock.py b/tests/functional/shock/shock.py index 0edd1eb77..8d2b84b69 100644 --- a/tests/functional/shock/shock.py +++ b/tests/functional/shock/shock.py @@ -2,12 +2,9 @@ import numpy as np -import matplotlib.pyplot as plt - - -import pyphare.pharein as ph from pyphare import cpp +import pyphare.pharein as ph from pyphare.pharesee.run import Run from pyphare.simulator.simulator import Simulator, startMPI @@ -115,9 +112,10 @@ def vthz(x): def main(): import os - import subprocess import glob import shlex + import subprocess + import matplotlib.pyplot as plt for interp_order in (1, 2, 3): sim = config(interp_order)