Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/cmake_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ jobs:
python -m pip install -r requirements.txt

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build
run: cmake -E make_directory ${{github.workspace}}/build

- name: Configure CMake
working-directory: ${{runner.workspace}}/build
working-directory: ${{github.workspace}}/build
run: |
cmake $GITHUB_WORKSPACE -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
Expand All @@ -81,10 +81,10 @@ jobs:
-DCMAKE_CXX_FLAGS="-DPHARE_DIAG_DOUBLES=1 "

- name: Build
working-directory: ${{runner.workspace}}/build
working-directory: ${{github.workspace}}/build
run: cmake --build . -j 2

- name: Test
working-directory: ${{runner.workspace}}/build
working-directory: ${{github.workspace}}/build
run: ctest -j 2 --output-on-failure

12 changes: 6 additions & 6 deletions .github/workflows/cmake_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ jobs:
python -m pip install -r requirements.txt

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build
run: cmake -E make_directory ${{github.workspace}}/build

- name: Configure CMake
working-directory: ${{runner.workspace}}/build
working-directory: ${{github.workspace}}/build
run: |
set -ex
export CC=gcc CXX=g++
[ "${{ matrix.cc }}" = "clang" ] && export CC=clang CXX=clang++
cmake $GITHUB_WORKSPACE
cd ${{runner.workspace}}/PHARE/subprojects/samrai && mkdir build && cd build
cd ${{github.workspace}}/subprojects/samrai && mkdir build && cd build
cmake .. -DENABLE_SAMRAI_TESTS=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -j2 && sudo make install && cd ../.. && rm -rf samrai
cd ${{runner.workspace}}/build && rm -rf *
cd ${{github.workspace}}/build && rm -rf *
cmake $GITHUB_WORKSPACE -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON --fresh \
-DCMAKE_BUILD_TYPE=Debug -Dasan=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
Expand All @@ -87,9 +87,9 @@ jobs:
-DCMAKE_CXX_FLAGS="-O3 -DPHARE_DIAG_DOUBLES=1 " -Dphare_configurator=ON

- name: Build
working-directory: ${{runner.workspace}}/build
working-directory: ${{github.workspace}}/build
run: cmake --build . -j 1

- name: Test
working-directory: ${{runner.workspace}}/build
working-directory: ${{github.workspace}}/build
run: ctest -j 2 --output-on-failure
79 changes: 79 additions & 0 deletions doc/conventions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# PHARE Conventions

### Reference document for the code base


# Sections

1. C++
2. Python
3. CMake
4. Tests
5. Etc

<br/>

# 1. C++

## 1.1 General

...


<br/>

# 2. Python

## 2.1 General

...

## 2.2 dependencies and imports

Third party depenencies are stated in the file `requirements.txt` in the project root.
Fewer dependencies is generally better but there should be a cost/benefit assessment for adding new dependencies.

### 2.2.1 Python file import structure.

Generally, we want to avoid importing any dependency at the top of a python script that may rely on binary libraries.

Exceptions to this are things like numpy, which are widely used and tested.

Things to expressly avoid importing at the top of a python script are

- h5py
- mpi4py
- scipy.optimize

The first two are noted as they can, and will pull in system libraries such as libmpi.so and libhdf5.so, which may not be the libraries which were used during PHARE build time, this can cause issues at runtime.

scipy.optimize relies on system libraries which may not be available at runtime.

The gist here is to only import these libraries at function scope when you actually need them, so that python files can be imported
or scanned for tests and not cause issues during these operations, until the functions are used at least.

<br/>

# 3. CMake

## 3.1 General

...


<br/>

# 4. Tests

## 4.1 General

...

<br/>

# 5. Etc

## 5.1 General

...

21 changes: 3 additions & 18 deletions pyphare/pyphare/cpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,10 @@
#


import json

# continue to use override if set
_cpp_lib_override = None


def cpp_lib(override=None):
import importlib

global _cpp_lib_override
if override is not None:
_cpp_lib_override = override
if _cpp_lib_override is not None:
return importlib.import_module(_cpp_lib_override)

if not __debug__:
return importlib.import_module("pybindlibs.cpp")
try:
return importlib.import_module("pybindlibs.cpp_dbg")
except ImportError:
return importlib.import_module("pybindlibs.cpp")
return importlib.import_module("pybindlibs.cpp")


def cpp_etc_lib():
Expand All @@ -37,6 +20,8 @@ def build_config():


def build_config_as_json():
import json

return json.dumps(build_config())


Expand Down
2 changes: 1 addition & 1 deletion pyphare/pyphare/pharein/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def __init__(self, **kwargs):


class ParticleDiagnostics(Diagnostics):
particle_quantities = ["space_box", "domain", "levelGhost", "patchGhost"]
particle_quantities = ["space_box", "domain", "levelGhost"]
type = "particle"

def __init__(self, **kwargs):
Expand Down
11 changes: 9 additions & 2 deletions pyphare/pyphare/pharesee/hierarchy/fromh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
)
from ...core.gridlayout import GridLayout
from .hierarchy_utils import field_qties
import h5py

from pathlib import Path
from pyphare.core.phare_utilities import listify


h5_time_grp_key = "t"
particle_files_patterns = ("domain", "patchGhost", "levelGhost")
particle_files_patterns = ("domain", "levelGhost")


def get_all_available_quantities_from_h5(filepath, time=0, exclude=["tags"], hier=None):
Expand Down Expand Up @@ -129,6 +129,8 @@ def h5_filename_from(diagInfo):


def get_times_from_h5(filepath, as_float=True):
import h5py # see doc/conventions.md section 2.1.1

f = h5py.File(filepath, "r")
if as_float:
times = np.array(sorted([float(s) for s in list(f[h5_time_grp_key].keys())]))
Expand Down Expand Up @@ -216,6 +218,7 @@ def add_time_from_h5(hier, filepath, time, **kwargs):
# add times to 'hier'
# we may have a different selection box for that time as for already existing times
# but we need to keep them, per time
import h5py # see doc/conventions.md section 2.1.1

h5f = h5py.File(filepath, "r")
selection_box = kwargs.get("selection_box", None)
Expand All @@ -239,6 +242,8 @@ def add_data_from_h5(hier, filepath, time):
if not hier.has_time(time):
raise ValueError("time does not exist in hierarchy")

import h5py # see doc/conventions.md section 2.1.1

h5f = h5py.File(filepath, "r")

# force using the hierarchy selection box at that time if existing
Expand All @@ -260,6 +265,8 @@ def new_from_h5(filepath, times, **kwargs):
# loads all datasets from the filepath h5 file as patchdatas
# we authorize user to pass only one selection box for all times
# but in this case they're all the same
import h5py # see doc/conventions.md section 2.1.1

selection_box = kwargs.get("selection_box", [None] * len(times))
if none_iterable(selection_box) and all_iterables(times):
selection_box = [selection_box] * len(times)
Expand Down
2 changes: 1 addition & 1 deletion pyphare/pyphare/pharesee/hierarchy/fromsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def hierarchy_from_sim(simulator, qty, pop=""):
# domain... while looping on the patchGhost items, we need to search in
# the already created patches which one to which add the patchGhost particles

for ghostParticles in ["patchGhost", "levelGhost"]:
for ghostParticles in ["levelGhost"]:
if ghostParticles in populationdict:
for dwpatch in populationdict[ghostParticles]:
v = np.asarray(dwpatch.data.v)
Expand Down
10 changes: 0 additions & 10 deletions pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,14 @@ def merge_particles(hierarchy):
(pdname, pd) for pdname, pd in pdatas.items() if "domain" in pdname
][0]

pghost_pdatas = [
(pdname, pd)
for pdname, pd in pdatas.items()
if "patchGhost" in pdname
]
lghost_pdatas = [
(pdname, pd)
for pdname, pd in pdatas.items()
if "levelGhost" in pdname
]

pghost_pdata = pghost_pdatas[0] if pghost_pdatas else None
lghost_pdata = lghost_pdatas[0] if lghost_pdatas else None

if pghost_pdata is not None:
domain_pdata[1].dataset.add(pghost_pdata[1].dataset)
del pdatas[pghost_pdata[0]]

if lghost_pdata is not None:
domain_pdata[1].dataset.add(lghost_pdata[1].dataset)
del pdatas[lghost_pdata[0]]
Expand Down
2 changes: 1 addition & 1 deletion pyphare/pyphare/pharesee/run/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def GetParticleCount(self, time, **kwargs):
return c

def GetMass(self, pop_name, **kwargs):
list_of_qty = ["density", "flux", "domain", "levelGhost", "patchGhost"]
list_of_qty = ["density", "flux", "domain", "levelGhost"]
list_of_mass = []

import h5py
Expand Down
10 changes: 5 additions & 5 deletions pyphare/pyphare/pharesee/run/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def _compute_pressure(patch_datas, **kwargs):
Myy = patch_datas["Myy"].dataset[:]
Myz = patch_datas["Myz"].dataset[:]
Mzz = patch_datas["Mzz"].dataset[:]
massDensity = patch_datas["rho"].dataset[:]
massDensity = patch_datas["value"].dataset[:]
Vix = patch_datas["Vx"].dataset[:]
Viy = patch_datas["Vy"].dataset[:]
Viz = patch_datas["Vz"].dataset[:]
Expand Down Expand Up @@ -417,10 +417,10 @@ def _compute_pop_pressure(patch_datas, **kwargs):
Myy = patch_datas[popname + "_Myy"].dataset[:]
Myz = patch_datas[popname + "_Myz"].dataset[:]
Mzz = patch_datas[popname + "_Mzz"].dataset[:]
Fx = patch_datas[popname + "_Fx"].dataset[:]
Fy = patch_datas[popname + "_Fy"].dataset[:]
Fz = patch_datas[popname + "_Fz"].dataset[:]
N = patch_datas[popname + "_rho"].dataset[:]
Fx = patch_datas["x"].dataset[:]
Fy = patch_datas["y"].dataset[:]
Fz = patch_datas["z"].dataset[:]
N = patch_datas["value"].dataset[:]

mass = kwargs["mass"]

Expand Down
18 changes: 7 additions & 11 deletions pyphare/pyphare/simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

import os
import sys
import datetime
import atexit
import time as timem
Expand Down Expand Up @@ -91,7 +92,7 @@ def __init__(self, simulation, auto_dump=True, **kwargs):
self.cpp_sim = None # BE
self.cpp_dw = None # DRAGONS, i.e. use weakrefs if you have to ref these.
self.post_advance = kwargs.get("post_advance", None)

self.initialized = False
self.print_eol = "\n"
if kwargs.get("print_one_line", True):
self.print_eol = "\r"
Expand Down Expand Up @@ -132,32 +133,28 @@ def setup(self):
)
return self
except Exception:
import sys
import traceback

print('Exception caught in "Simulator.setup()": {}'.format(sys.exc_info()))
print(traceback.extract_stack())
raise ValueError("Error in Simulator.setup(), see previous error")

def initialize(self):
if self.cpp_sim is not None:
raise ValueError(
"Simulator already initialized: requires reset to re-initialize"
)
try:
if self.initialized:
return
if self.cpp_hier is None:
self.setup()

if self.simulation.dry_run:
return self

self.cpp_sim.initialize()
self.initialized = True
self._auto_dump() # first dump might be before first advance

return self
except Exception:
import sys

print(
'Exception caught in "Simulator.initialize()": {}'.format(
sys.exc_info()[0]
Expand All @@ -166,8 +163,6 @@ def initialize(self):
raise ValueError("Error in Simulator.initialize(), see previous error")

def _throw(self, e):
import sys

print_rank0(e)
sys.exit(1)

Expand Down Expand Up @@ -264,6 +259,7 @@ def reset(self):
self.cpp_dw = None
self.cpp_sim = None
self.cpp_hier = None
self.initialized = False
if "samrai" in life_cycles:
type(life_cycles["samrai"]).reset()
return self
Expand All @@ -289,7 +285,7 @@ def interp_order(self):
return self.cpp_sim.interp_order # constexpr static value

def _check_init(self):
if self.cpp_sim is None:
if not self.initialized:
self.initialize()

def _log_to_file(self):
Expand Down
Loading