forked from PHAREHUB/PHARE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* report zip gen * consistent cmake version required * bind to none for better // of multiple mpirun calls * report zip gen * more * correct python cmake var name * revert default configurator option * PR comments / move ompi bind to none to configurator * default report writing on / disabled if testing / simulator retval consistency
- Loading branch information
1 parent
ea898ac
commit ced43dc
Showing
28 changed files
with
514 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ tools/cmake.sh | |
perf.* | ||
**/*.h5 | ||
.vscode | ||
|
||
.phare* | ||
PHARE_REPORT.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# | ||
# | ||
# | ||
# program help looks like | ||
""" | ||
usage: phare_sim.py [-h] [-d] | ||
options: | ||
-h, --help show this help message and exit | ||
-d, --dry-run Validate but do not run simulations | ||
""" | ||
|
||
import sys | ||
import dataclasses | ||
|
||
|
||
def disabled_for_testing(): | ||
# check if any module is loaded from PHARE tests directory | ||
from pathlib import Path | ||
|
||
test_dir = Path(__file__).resolve().parent.parent.parent.parent / "tests" | ||
if test_dir.exists(): | ||
test_dir = str(test_dir) | ||
for k, mod in sys.modules.items(): | ||
if hasattr(mod, "__file__") and mod.__file__ and test_dir in mod.__file__: | ||
return True | ||
return False | ||
|
||
|
||
@dataclasses.dataclass | ||
class CliArgs: | ||
dry_run: bool = dataclasses.field(default_factory=lambda: False) | ||
write_reports: bool = dataclasses.field(default_factory=lambda: False) | ||
|
||
|
||
def parse_cli_args(): | ||
default_off = len(sys.argv) == 1 and disabled_for_testing() | ||
if default_off: | ||
return CliArgs() | ||
|
||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-d", | ||
"--dry-run", | ||
help="Validate but do not run simulations", | ||
action="store_true", | ||
default=False, | ||
) | ||
parser.add_argument( | ||
"-w", | ||
"--write_reports", | ||
help="Write build and runtime configs to disk", | ||
action="store_true", | ||
default=True, | ||
) | ||
|
||
return CliArgs(**vars(parser.parse_args())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
""" | ||
PHARE build and runtime validation checks | ||
""" | ||
|
||
import os | ||
import sys | ||
import json | ||
import dataclasses | ||
from pathlib import Path | ||
|
||
from pyphare.core import phare_utilities | ||
from pyphare import cpp | ||
|
||
DOT_PHARE_DIR = Path(os.getcwd()) / ".phare" | ||
|
||
|
||
ERROR_MESSAGES = dict( | ||
on_phare_config_error=""" | ||
Warning: PHARE was not built with the configurator active""", | ||
on_python3_version_mismatch=""" | ||
Inconsistency detected! | ||
Python during build and now are not the same! | ||
Build python version : {} | ||
Current python version: {}""", | ||
on_build_config_check_runtime_error=""" | ||
Could not interrogate python versions | ||
Please see 'Having Issues' Section of ISSUES.TXT | ||
Actual error (consider adding to issue report): {}""", | ||
) | ||
|
||
|
||
def print_error(key, *args): | ||
print(ERROR_MESSAGES[key].format(*args).strip()) | ||
|
||
|
||
def python_version_from(binary): | ||
return phare_utilities.decode_bytes( | ||
phare_utilities.run_cli_cmd(f"{binary} -V", check=True).stdout.strip() | ||
) | ||
|
||
|
||
def check_build_config_is_runtime_compatible(strict=True): | ||
try: | ||
build_config: dict = cpp.build_config() | ||
|
||
if "PHARE_CONFIG_ERROR" in build_config: | ||
print_error("on_phare_config_error") | ||
return | ||
|
||
build_python_version = build_config["PYTHON_VERSION"] | ||
current_python_version = python_version_from(sys.executable) | ||
if build_python_version != current_python_version: | ||
print_error( | ||
"on_python3_version_mismatch", | ||
build_python_version, | ||
current_python_version, | ||
) | ||
|
||
raise ValueError("Python version mismatch!") | ||
|
||
except RuntimeError as e: | ||
print_error("on_build_config_check_runtime_error", e) | ||
|
||
except ValueError as e: | ||
print(e) | ||
if strict: | ||
raise e | ||
|
||
|
||
@dataclasses.dataclass | ||
class RuntimeSettings: | ||
python_version: str | ||
python_binary: str | ||
|
||
|
||
def try_system_binary(cli, log_to): | ||
with open(log_to, "w") as f: | ||
try: | ||
proc = phare_utilities.run_cli_cmd(cli, check=True) | ||
f.write(phare_utilities.decode_bytes(proc.stdout).strip()) | ||
except Exception as e: | ||
f.write(f"failed to run cli command {cli}\n") | ||
f.write(f"error {e}") | ||
|
||
|
||
def try_system_binaries(log_dir): | ||
try_system_binary("free -g", log_dir / "free_dash_g.txt") | ||
try_system_binary("lscpu", log_dir / "lscpu.txt") | ||
try_system_binary("hwloc-info", log_dir / "hwloc_info.txt") | ||
|
||
|
||
def log_runtime_config(): | ||
cpp_lib = cpp.cpp_lib() | ||
|
||
settings = RuntimeSettings( | ||
python_binary=sys.executable, python_version=python_version_from(sys.executable) | ||
) | ||
|
||
if cpp_lib.mpi_rank() == 0: | ||
DOT_PHARE_DIR.mkdir(exist_ok=True, parents=True) | ||
cpp_lib.mpi_barrier() | ||
|
||
rank_dir = DOT_PHARE_DIR / f"rank_{cpp_lib.mpi_rank()}" | ||
rank_dir.mkdir(exist_ok=True) | ||
|
||
with open(rank_dir / "runtime_config.json", "w") as f: | ||
json.dump(dataclasses.asdict(settings), f) | ||
|
||
try_system_binaries(rank_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.