Skip to content

Commit

Permalink
config-generator: non-interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Horn committed Aug 13, 2024
1 parent c42c63e commit adc73fd
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 75 deletions.
6 changes: 4 additions & 2 deletions examples/config-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ This file has the following structure:

### Usage
1. Navigate to the target directory for the `couette.xml` file (most likely the MaMiCo build folder)
2. Execute `$MAMICO_DIR/examples/config-generator/run`
2. Execute `$MAMICO_DIR/examples/config-generator/run`
Specific values can be fixed by providing them as a command line argument, e.g. `--override=domain_size=large,use_checkpoint=False,multi_md=2`.
The corresponding entries will be removed from the interactive menu. If all configurations are overwritten, the script will run non-interactively. (May be used for automated testing.)
3. Customize the generator settings and generate the `couette.xml` file
3. Customize the generated configuration even further according to the [documentation](https://github.com/HSU-HPC/MaMiCo/wiki/couette.xml) (optional)
4. Customize the generated configuration even further according to the [documentation](https://github.com/HSU-HPC/MaMiCo/wiki/couette.xml) (optional)
13 changes: 5 additions & 8 deletions examples/config-generator/assets/configuration_template.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
[
{
"key": "domain",
"key": "domain_size",
"label": "domain size",
"options": [
{
"selected": true,
"value": 1,
"label": "small",
"value": "small",
"description": "MD/CFD domain size = 30\u00B3/50\u00B3"
},
{
"value": 2,
"label": "medium",
"value": "medium",
"description": "MD/CFD domain size = 60\u00B3/100\u00B3"
},
{
"value": 3,
"label": "large",
"value": "large",
"description": "MD/CFD domain size = 120\u00B3/200\u00B3"
}
]
Expand Down Expand Up @@ -188,4 +185,4 @@
}
]
}
]
]
4 changes: 2 additions & 2 deletions examples/config-generator/run
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Any dependencies are automatically installed.
# The output of the script is saved to the current working directory.

OUTPUT="$(pwd)/couette.xml"
OUTPUT="$(pwd)"

cd "$(dirname "$0")" || exit

Expand All @@ -22,4 +22,4 @@ fi
source .venv/bin/activate

# Run the config builder
python3 src/main.py "$OUTPUT"
python3 src/main.py --output "$OUTPUT" "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
from generators.mpi_ranks import get_ranks_xyz


def _get_domain_size(get_config_value) -> int:
def get_domain_size(get_config_value) -> int:
key = __name__.split(".")[-1]
return get_config_value(key)
domain_size_name = get_config_value(key)
domain_size_names = ["small", "medium", "large"]
return domain_size_names.index(domain_size_name) + 1


def get_domain_sizes(get_config_value) -> int:
size = _get_domain_size(get_config_value)
size = get_domain_size(get_config_value)
md_base_size = 30
cfd_base_size = 50
md_domain_size = md_base_size * size
cfd_domain_size = cfd_base_size * size
if size == 3:
md_domain_size = 120 # instead of 90
cfd_domain_size = 200 # instead of 150
return md_domain_size, cfd_domain_size


Expand All @@ -35,7 +38,7 @@ def validate(get_config_value) -> str:
def apply(partial_xml, get_config_value) -> None:
equilibration_steps = 10000
equilibration_steps_max = 20000
size = _get_domain_size(get_config_value)
size = get_domain_size(get_config_value)
md_domain_size, cfd_domain_size = get_domain_sizes(get_config_value)
domain_offset_xy = (cfd_domain_size - md_domain_size) / 2 # Centered
partial_xml.substitute("md-size", md_domain_size)
Expand Down
2 changes: 1 addition & 1 deletion examples/config-generator/src/generators/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def apply(partial_xml, get_config_value) -> None:
""".strip()

if filtering == False:
per_instance_filtering_xml = "<per-instance output=\"md\"></per-instance>"
per_instance_filtering_xml = '<per-instance output="md"></per-instance>'
elif filtering == "gauss":
per_instance_filtering_xml = xml_2d_gaussian
elif filtering == "nlm":
Expand Down
5 changes: 4 additions & 1 deletion examples/config-generator/src/generators/simulation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from generators.domain_size import get_domain_size


def apply(partial_xml, get_config_value) -> None:
key = __name__.split(".")[-1]
simulation_type = get_config_value(key)
domain_size = get_config_value("domain")
domain_size = get_domain_size(get_config_value)
match simulation_type:
case "test":
partial_xml.substitute("coupling-cycles", 50)
Expand Down
4 changes: 2 additions & 2 deletions examples/config-generator/src/generators/solver_md.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

from generators.cell_size import get_molecules_per_direction
from generators.domain import get_domain_sizes
from generators.domain_size import get_domain_sizes
from utils import get_asset_text
from xml_templating import PartialXml

Expand All @@ -15,7 +15,7 @@ def _create_ls1_config(get_config_value) -> None:
xml.substitute("grid-filler-lattice", grid_filler_lattice)
boundary_condition = get_config_value("boundary")
xml.substitute("boundary-condition", boundary_condition)
filename = Path(get_config_value("output_filename")).parent / "ls1config.xml"
filename = Path(get_config_value("output_dir")) / "ls1config.xml"
with open(filename, "w") as file:
file.write(xml.get())

Expand Down
7 changes: 4 additions & 3 deletions examples/config-generator/src/generators/use_checkpoint.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import shutil
from pathlib import Path

from generators.domain_size import get_domain_size


def validate(get_config_value) -> str:
"""MaMiCo config validation:
A pre-computed checkpoint is (currently) only available for Simple MD with a 30x30x30 domain.
"""
key = __name__.split(".")[-1]
use_checkpoint = get_config_value(key)
domain_size = get_config_value("domain")
domain_size = get_domain_size(get_config_value)
solver_md = get_config_value("solver_md")
if use_checkpoint and (domain_size > 1 or solver_md != "md"):
return f"Example checkpoint file only provided for small Simple MD simulation."
Expand All @@ -29,8 +31,7 @@ def apply(partial_xml, get_config_value) -> None:
/ f"CheckpointSimpleMD_10000_{boundary_condition}_0.checkpoint"
)
checkpoint_dst_path = (
Path(get_config_value("output_filename")).parent
/ "CheckpointSimpleMD.checkpoint"
Path(get_config_value("output_dir")) / "CheckpointSimpleMD.checkpoint"
)
# Avoid reading and writing the contents of the file, because it is rather large
shutil.copyfile(checkpoint_src_path, checkpoint_dst_path)
Expand Down
Loading

0 comments on commit adc73fd

Please sign in to comment.