From 557602ca77db47cc5c44a06f3d5972f148893493 Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Fri, 22 Mar 2024 15:14:44 -0400 Subject: [PATCH] Fixed issues for thermal conductivity and running in parallel. --- HISTORY.rst | 4 ++++ lammps_step/data/configuration.txt | 21 ------------------- lammps_step/data/lammps.ini | 18 +++++++++++++++- lammps_step/data/seamm-lammps.yml | 2 +- lammps_step/lammps.py | 33 ++++++++++++++++++++++-------- 5 files changed, 46 insertions(+), 32 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 83d20f9..ddafba3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,10 @@ ======= History ======= +2024.3.22 -- Corrected issue with e.g. heat flux calculations + * Corrected an issue running LAMMPS via Python, intorduced in the new scheme for + executing. It ignored parallelism. + 2024.3.21 -- Switched to new installation scheme * Fully support ~/SEAMM/lammps.ini * Updated to new installer diff --git a/lammps_step/data/configuration.txt b/lammps_step/data/configuration.txt index ae37b84..c1b2f2f 100644 --- a/lammps_step/data/configuration.txt +++ b/lammps_step/data/configuration.txt @@ -21,24 +21,3 @@ # they can be viewed without the SEAMM Dashboard. # html = False - -# -# SEAMM picks up the environment variables such as SLURM_NTASKS, strips the -# prefix from them and replaces any instances in the command line that are -# enclosed in braces. Hopefully this lets you construct the correct command -# line. -# -# The LAMMPS installer does not handle these variables! They are here -# just in case! - -# lammps-serial = lmp_serial -# lammps-mpi = lmp_mpi -# mpiexec = mpiexec - -# Optional command-line arguments for LAMMPS. These are usually used with accelerators -# such as Kokkos or GPU to automatically apply the accelerator. Again there is a normal -# and GPU version - -# cmd-args = -k on -sf kk -# gpu-cmd-args = -k on g {ngpus} -sf kk -pk kokkos gpu/aware on newton on neigh full neigh/thread on neigh/transpose off comm device - diff --git a/lammps_step/data/lammps.ini b/lammps_step/data/lammps.ini index 8bf0847..5bcc419 100644 --- a/lammps_step/data/lammps.ini +++ b/lammps_step/data/lammps.ini @@ -15,6 +15,14 @@ # code = mpirun -n {NTASKS} -H {NODELIST} -npernode {NTASKS_PER_NODE} code = mpirun -n {NTASKS} lmp +python = python + +# Optional command-line arguments for LAMMPS. These are usually used with accelerators +# such as Kokkos or GPU to automatically apply the accelerator. Again there is a normal +# and GPU version + +# cmd-args = -k on -sf kk +# gpu-cmd-args = -k on g {ngpus} -sf kk -pk kokkos gpu/aware on newton on neigh full neigh/thread on neigh/transpose off comm device # The name and location of the Docker container to use, optionally with the version @@ -53,7 +61,15 @@ installation = conda # # code = mpirun -n {NTASKS} -H {NODELIST} -npernode {NTASKS_PER_NODE} -code = mpirun -n {NTASKS} lmp +code = mpirun -np {NTASKS} lmp +python = mpirun -np {NTASKS} python + +# Optional command-line arguments for LAMMPS. These are usually used with accelerators +# such as Kokkos or GPU to automatically apply the accelerator. Again there is a normal +# and GPU version + +# cmd-args = -k on -sf kk +# gpu-cmd-args = -k on g {ngpus} -sf kk -pk kokkos gpu/aware on newton on neigh full neigh/thread on neigh/transpose off comm device ######################### conda section ############################ # The full path to the conda executable: diff --git a/lammps_step/data/seamm-lammps.yml b/lammps_step/data/seamm-lammps.yml index 9a7df87..77766e5 100644 --- a/lammps_step/data/seamm-lammps.yml +++ b/lammps_step/data/seamm-lammps.yml @@ -5,6 +5,6 @@ dependencies: - python # Executables, etc. - openmpi - - lammps + - lammps * *mpi_openmpi* - openkim-models - mpi4py diff --git a/lammps_step/lammps.py b/lammps_step/lammps.py index 33475f1..444bc42 100644 --- a/lammps_step/lammps.py +++ b/lammps_step/lammps.py @@ -663,16 +663,18 @@ def _execute_single_sim(self, files, np=1, return_files=None): if path.exists(): full_config.read(ini_dir / "lammps.ini") + full_config.set("local", "_origin_", f"{ini_dir / 'lammps.ini'}") # If the section we need doesn't exists, get the default if not path.exists() or executor_type not in full_config: resources = importlib.resources.files("lammps_step") / "data" ini_text = (resources / "lammps.ini").read_text() full_config.read_string(ini_text) + full_config.set("local", "_origin_", "lammps default ini file") # Getting desperate! Look for an executable in the path if executor_type not in full_config: - path = shutil.which("lammps") + path = shutil.which("lmp") if path is None: raise RuntimeError( f"No section for '{executor_type}' in LAMMPS ini file " @@ -680,10 +682,15 @@ def _execute_single_sim(self, files, np=1, return_files=None): "in the path!" ) else: - full_config[executor_type] = { - "installation": "local", - "code": str(path), - } + full_config.add_section(executor_type) + full_config.set(executor_type, "installation", "local") + full_config.set(executor_type, "code", str(path)) + + # And we may need python! + full_config.set("local", "items", f"{full_config.items('local')}") + if not full_config.has_option(executor_type, "python"): + full_config.set(executor_type, "python", "mpirun -np {NTASKS} python") + full_config.set(executor_type, "_python source_", "default value") # If the ini file does not exist, write it out! if not path.exists(): @@ -707,11 +714,19 @@ def _execute_single_sim(self, files, np=1, return_files=None): # Setup the command lines cmd = [] - if "python script" in files: + if "run_lammps" in files: cmd = ["{python}", "run_lammps"] - if "GPUS" not in ce and config["cmd_args"] != "": + if ( + "GPUS" not in ce + and "cmd_args" in config + and config["cmd_args"] != "" + ): cmd.extend(["--cmd-args", config["cmd_args"]]) - if "GPUS" in ce and config["gpu_cmd_args"] != "": + if ( + "GPUS" in ce + and "gpu_cmd_args" in config + and config["gpu_cmd_args"] != "" + ): cmd.extend(["--cmd-args", config["gpu_cmd_args"]]) else: cmd = ["{code}"] @@ -723,7 +738,7 @@ def _execute_single_sim(self, files, np=1, return_files=None): cmd.extend(config["cmd_args"].split()) if ( "GPUS" in ce - and config["gpu_cmd_args"] != "" + and "gpu_cmd_args" in config and config["gpu_cmd_args"] != "" ): cmd.extend(config["gpu_cmd_args"].split())