Skip to content

Commit

Permalink
Merge pull request #188 from yardasol/mpi-arguments
Browse files Browse the repository at this point in the history
Overhaul parallel runs
  • Loading branch information
LukeSeifert authored Jan 27, 2023
2 parents 5b4e60c + 191a0b5 commit 419447d
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 97 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ reactors.
How to run SaltProc:

cd /path/to/saltproc
python saltproc -n 4 -d 1 -i examples/tap/tap_main.json
python saltproc -s 2 -i examples/tap/tap_main.json
```
-n number of cluster nodes to use in Serpent
-d number of threads to use in Serpent
-s number of threads to use for shared-memory paralleism (optional)
-i path and name of SaltProc main input file
```

Expand Down
12 changes: 12 additions & 0 deletions doc/fileformatspec/depcode_input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ OpenMC-specific properties
:description:
Path to fission Q values

:type:
``string``, ``null``

:default:
``null``

Expand Down Expand Up @@ -383,6 +386,9 @@ OpenMC-specific properties
:description:
Arguments for the fission yield helper

:type:
``object``, ``null``

:default:
``null``. See :ref:`openmc_constant_fission_yield_opts_properties`
and :ref:`openmc_cutoff_fission_yield_opts_properties` for object
Expand All @@ -409,6 +415,9 @@ OpenMC-specific properties
``reaction_rate_opts``
~~~~~~~~~~~~~~~~~~~~~~

:type:
``object``, ``null``

:default:
``null``. See :ref:`openmc_flux_reaction_rate_opts_properties` for
object properties when ``reaction_rate_mode`` is ``flux``.
Expand All @@ -433,6 +442,9 @@ OpenMC-specific properties
:description:
Depth of serach while reducing depletion chain

:type:
``integer``, ``null``

:default:
``null``

Expand Down
21 changes: 21 additions & 0 deletions doc/fileformatspec/saltproc_input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ Required properties are as follows: ``proc_input_file``, ``dot_input_file``, ``o
``number``


.. _mpi_args_property:

``mpi_args``
---------------------

:description:
Arguments for running simulations on supercomputers using ``mpiexec``
or similar programs

:type:
``array``, ``null``

:items:

:type:
``string``, ``integer``

:default:
``null``


.. _depcode_property:

``depcode``
Expand Down
8 changes: 8 additions & 0 deletions doc/releasenotes/v0.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ Python API Changes

- Input file format changes:

- Removed the ``-n`` command line argument in favor of the new ``mpi_args`` input parameter
- Chaged the ``-d`` command line argument to ``-s``/``--threads``.
- (new) → ``mpi_args``
- Added default values for certain input parameters
- Added depletion settings for OpenMC
- ``num_depsteps`` → ``n_depletion_steps``
Expand Down Expand Up @@ -195,6 +198,11 @@ Python API Changes
- (new) → ``timestep_units``
- (new) → ``timestep_type``

- ``Simulation``

- ``core_number`` → (removed)
- ``node_number`` → (removed)

- ``Sparger``

- ``calc_rem_efficiency()`` → ``calculate_removal_efficiency``
Expand Down
3 changes: 2 additions & 1 deletion saltproc/_schema_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def set_defaults(validator, properties, instance, schema):
):
yield error


return validators.extend(
validator_class, {"properties" : set_defaults},
validator_class, {"properties" : set_defaults}
)


Expand Down
12 changes: 7 additions & 5 deletions saltproc/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,17 @@ def read_depleted_materials(self, read_at_end=False):
"""

@abstractmethod
def run_depletion_step(self, cores, nodes):
def run_depletion_step(self, mpi_args, threads):
"""Runs a depletion step as a subprocess with the given parameters.
Parameters
----------
cores : int
Number of cores to use for depletion code run.
nodes : int
Number of nodes to use for depletion code run.
mpi_args : list of str
Arguments for running simulations on supercomputers using
``mpiexec`` or similar programs.
threads : int
Threads to use for shared-memory parallelism
"""

@abstractmethod
Expand Down
57 changes: 29 additions & 28 deletions saltproc/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from pathlib import Path
from copy import deepcopy

from collections import OrderedDict

import argparse
import numpy as np
import json
import jsonschema
import traceback
import json, jsonschema
import gc
import networkx as nx
import pydotplus
Expand All @@ -28,14 +29,14 @@

def run():
""" Inititializes main run"""
nodes, cores, saltproc_input = parse_arguments()
input_path, process_file, dot_file, object_input = \
threads, saltproc_input = parse_arguments()
input_path, process_file, dot_file, mpi_args, object_input = \
read_main_input(saltproc_input)
_print_simulation_input_info(object_input[1], object_input[0])
# Intializing objects
depcode = _create_depcode_object(object_input[0])
simulation = _create_simulation_object(
object_input[1], depcode, cores, nodes)
object_input[1], depcode)
msr = _create_reactor_object(object_input[2])

# Check: Restarting previous simulation or starting new?
Expand All @@ -47,7 +48,7 @@ def run():
simulation.sim_depcode.write_runtime_input(msr,
step_idx,
simulation.restart_flag)
depcode.run_depletion_step(cores, nodes)
depcode.run_depletion_step(mpi_args, threads)
if step_idx == 0 and simulation.restart_flag is False: # First step
# Read general simulation data which never changes
simulation.store_run_init_info()
Expand Down Expand Up @@ -111,31 +112,24 @@ def parse_arguments():
Returns
-------
n: int
Number of nodes for use in depletion code simulation.
d: int
Number of cores for use in depletion code simulation.
i: str
s : int
Number of threads to use for shared-memory parallelism.
i : str
Path and name of main SaltProc input file (json format).
"""
parser = argparse.ArgumentParser()
parser.add_argument('-n', # Number of nodes to use
type=int,
default=1,
help='number of cluster nodes to use in \
depletion code simulation')
parser.add_argument('-d', # Number of cores to use
parser.add_argument('-s', '--threads',
type=int,
default=1,
help='number of threads to use in \
depletion code simulation')
default=None,
help='Number of threads to use for shared-memory \
parallelism.')
parser.add_argument('-i', # main input file
type=str,
default=None,
help='path and name of SaltProc main input file')
help='Path and name of SaltProc main input file')
args = parser.parse_args()
return int(args.n), int(args.d), str(args.i)
return args.threads, args.i


def read_main_input(main_inp_file):
Expand All @@ -154,6 +148,9 @@ def read_main_input(main_inp_file):
Path to the `.json` file describing the fuel reprocessing components.
dot_file : str
Path to the `.dot` describing the fuel reprocessing paths.
mpi_args : list of str
Arguments for running simulations on supercomputers using mpiexec or
similar programs.
object_inputs : 3-tuple of dict
tuple containing the inputs for constructing the
:class:`~saltproc.Depcode`, :class:`~saltproc.Simulation`, and
Expand All @@ -169,8 +166,13 @@ def read_main_input(main_inp_file):
try:
DefaultFillingValidator(schema).validate(input_parameters)
except jsonschema.exceptions.ValidationError:
print("Your input file is improperly structured.\
Please see saltproc/tests/test.json for an example.")
print("Your input file is improperly structured: \n")
traceback.print_exc()
except jsonschema.exceptions.SchemaError:
traceback.print_exc()
except:
print("Something went wrong during schema validation.")
traceback.print_exc()

# Global input path
input_path = (Path.cwd() / Path(f.name).parents[0])
Expand All @@ -183,6 +185,7 @@ def read_main_input(main_inp_file):
input_parameters['dot_input_file']).resolve())
output_path = input_parameters['output_path']
n_depletion_steps = input_parameters['n_depletion_steps']
mpi_args = input_parameters['mpi_args']

# Global output path
output_path = (input_path / output_path)
Expand Down Expand Up @@ -231,7 +234,7 @@ def read_main_input(main_inp_file):
reactor_input = _process_main_input_reactor_params(
reactor_input, n_depletion_steps, depcode_input['codename'])

return input_path, process_file, dot_file, (
return input_path, process_file, dot_file, mpi_args, (
depcode_input, simulation_input, reactor_input)

def _print_simulation_input_info(simulation_input, depcode_input):
Expand All @@ -258,13 +261,11 @@ def _create_depcode_object(depcode_input):
return depcode


def _create_simulation_object(simulation_input, depcode, cores, nodes):
def _create_simulation_object(simulation_input, depcode):
"""Helper function for `run()` """
simulation = Simulation(
sim_name='Super test',
sim_depcode=depcode,
core_number=cores,
node_number=nodes,
restart_flag=simulation_input['restart_flag'],
adjust_geo=simulation_input['adjust_geo'],
db_path=simulation_input['db_name'])
Expand Down
14 changes: 12 additions & 2 deletions saltproc/input_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"description": "Number of steps for constant power and depletion interval case",
"type": "number"
},
"mpi_args": {
"description": "Arguments for running simulations on supercomputers using ``mpiexec`` or similar programs.",
"type": ["array", "null"],
"items": { "type": ["string", "integer"]},
"default": null
},
"depcode": {
"description": "Depcode class input parameters",
"type": "object",
Expand Down Expand Up @@ -192,6 +198,7 @@
"default": "fission-q"},
"fission_q": {
"description": "Path to fission Q values",
"type": ["string", "null"],
"default": null},
"dilute_initial": {
"description": "Initial atom density to add for nuclides that are zero in initial condition.",
Expand All @@ -205,20 +212,23 @@
"default": "constant"},
"fission_yield_opts": {
"description": "Arguments for the fission yield helper",
"type": ["object", "null"],
"default": null},
"reaction_rate_mode": {
"description": "Indicate how one-group reaction rates should be calculated",
"type": "string",
"enum": ["direct", "flux"],
"default": "direct"},
"reaction_rate_opts": {
"type": ["object", "null"],
"default": null},
"reduce_chain": {
"description": "Whether or not to reduce the depletion chain.",
"type": "boolean",
"default": false},
"reduce_chain_level": {
"description": "Depth of serach while reducing depletion chain",
"type": ["integer", "null"],
"default": null}
},
"default": {}
Expand Down Expand Up @@ -252,6 +262,7 @@
"simulation": {
"description": "Simulation class input parameters",
"type": "object",
"default": {},
"properties": {
"sim_name": {
"description": "Name of simulation",
Expand All @@ -270,12 +281,12 @@
"type": "boolean",
"default": false}
},
"default": {},
"required": ["sim_name"]
},
"reactor": {
"description": "Reactor class input parameters",
"type": "object",
"default": {},
"properties": {
"volume": {
"description": "reactor core volume [cm^3]",
Expand Down Expand Up @@ -308,7 +319,6 @@
"enum": ["s", "sec", "min", "minute", "h", "hr", "hour", "d", "day", "a", "yr", "year", "MWd/kg", "mwd/kg", "MWD/KG", "MWD/kg", "MWd/KG"]
}
},
"default": {},
"required": ["volume", "mass_flowrate", "power_levels", "depletion_timesteps", "timestep_units"]
}
},
Expand Down
Loading

0 comments on commit 419447d

Please sign in to comment.