Skip to content

Commit

Permalink
Change PluginPyARC to use extra_inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed Feb 17, 2022
1 parent 991fc4f commit 7b13c27
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
32 changes: 17 additions & 15 deletions doc/source/user/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ added to WATTS and are available for your use.
MOOSE Plugin
~~~~~~~~~~

The :class:`~watts.PluginMOOSE` class enables MOOSE simulations using a templated
input file. This is demonstrated here for a SAM application, but other examples based on BISON are also available.
For MOOSE codes such as SAM or BISON that use text-based input files, WATTS relies on
the `Jinja <https://jinja.palletsprojects.com>`_ templating engine for handling
templated variables and expressions. The templated input file looks like a
normal MOOSE input file where some values have been replaced with
**variables**, which are denoted by ``{{`` and ``}}`` pairs and get replaced
with actual values when the template is *rendered*. For example, a templated
input file might look as follows:
The :class:`~watts.PluginMOOSE` class enables MOOSE simulations using a
templated input file. This is demonstrated here for a SAM application, but other
examples based on BISON are also available. For MOOSE codes such as SAM or BISON
that use text-based input files, WATTS relies on the `Jinja
<https://jinja.palletsprojects.com>`_ templating engine for handling templated
variables and expressions. The templated input file looks like a normal MOOSE
input file where some values have been replaced with **variables**, which are
denoted by ``{{`` and ``}}`` pairs and get replaced with actual values when the
template is *rendered*. For example, a templated input file might look as
follows:

.. code-block:: jinja
Expand All @@ -81,8 +82,9 @@ If the templated input file is ``sam_template.inp``, the SAM code will rely the

moose_plugin = watts.PluginMOOSE('sam_template.inp')

The MOOSE plugin provides the option to specify supplementary input files (in `supp_inputs` option) that
will be copied together with the templated input file (mesh or cross-section files).
The MOOSE plugin provides the option to specify non-templated input files (in
`extra_inputs` option) that will be copied together with the templated input
file (mesh or cross-section files).

The SAM executable defaults to ``sam-opt`` (assumed to be present on your
:envvar:`PATH`) but can also be specified explicitly with the
Expand Down Expand Up @@ -163,7 +165,7 @@ PyARC Plugin
~~~~~~~~~~~~~

The :class:`~watts.PluginPyARC` class handles PyARC execution in a similar
manner to the :class:`~watts.PluginSAM` class for SAM. PyARC use text-based
manner to the :class:`~watts.PluginSAM` class for SAM. PyARC use text-based
input files which can be templated as follows:

.. code-block:: jinja
Expand All @@ -176,15 +178,15 @@ input files which can be templated as follows:
If the templated input file is `pyarc_template`, then the PyARC plugin can be instantiated with following command line::

pyarc_plugin = watts.PluginPyARC('pyarc_template', show_stdout=True, supp_inputs=['lumped_test5.son'])
pyarc_plugin = watts.PluginPyARC('pyarc_template', show_stdout=True, extra_inputs=['lumped_test5.son'])

The path to PyARC directory must be specified explicitly with the
:attr:`~watts.PluginPyARC.pyarc_exec` attribute::

pyarc_plugin.pyarc_exec = "/path/to/PyARC"

To execute PyARC, the :meth:`~watts.PluginPyARC.workflow` method is called
the same way as other Plugins.
To execute PyARC, the :meth:`~watts.PluginPyARC.workflow` method is called
the same way as other Plugins.

Results
+++++++
Expand Down
2 changes: 1 addition & 1 deletion examples/example1c_PyARC/example1c.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# PyARC Workflow

pyarc_plugin = watts.PluginPyARC('pyarc_template', show_stdout=True, supp_inputs=['lumped_test5.son']) # show all the output
pyarc_plugin = watts.PluginPyARC('pyarc_template', show_stdout=True, extra_inputs=['lumped_test5.son']) # show all the output
pyarc_result = pyarc_plugin.workflow(params)
for key in pyarc_result.results_data:
print(key, pyarc_result.results_data[key])
Expand Down
4 changes: 2 additions & 2 deletions src/watts/plugin_moose.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def postrun(self, params: Parameters) -> ResultsMOOSE:

time = datetime.fromtimestamp(self._run_time * 1e-9)
# Start with non-templated input files
inputs = [Path.cwd() / p.name for p in self.extra_inputs]
inputs = [p.name for p in self.extra_inputs]
inputs.append('MOOSE.i')
outputs = [p for p in Path.cwd().iterdir() if p.name not in inputs]
return ResultsMOOSE(params, time, inputs, outputs)
return ResultsMOOSE(params, time, inputs, outputs)
22 changes: 11 additions & 11 deletions src/watts/plugin_pyarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import tempfile
import time
from typing import Mapping, List
from typing import Mapping, List, Optional

import h5py
import sys
Expand Down Expand Up @@ -62,7 +62,7 @@ def _save_PyARC(self, user_object) -> dict:
results_data["persent_sens"] = user_object.results_kuq_persent
results_data["gamsor"] = user_object.results_power_gamsor
results_data["dassh"] = user_object.results_dassh
# TODO - this is minimum information that can be brought back easily.
# TODO - this is minimum information that can be brought back easily.
# More should be returned but will require work on PyARC.
return results_data

Expand Down Expand Up @@ -98,12 +98,12 @@ class PluginPyARC(TemplatePlugin):
template_file
Templated PyARC input
show_stdout
Whether to display output from stdout when SAM is run
Whether to display output from stdout when PyARC is run
show_stderr
Whether to display output from stderr when SAM is run
supp_inputs
List of supplementary input files that are needed for running PyARC
Whether to display output from stderr when PyARC is run
extra_inputs
List of extra (non-templated) input files that are needed
Attributes
----------
pyarc_exec
Expand All @@ -112,13 +112,13 @@ class PluginPyARC(TemplatePlugin):
"""

def __init__(self, template_file: str, show_stdout: bool = False,
show_stderr: bool = False, supp_inputs: List[str] = []):
super().__init__(template_file)
show_stderr: bool = False,
extra_inputs: Optional[List[str]] = None):
super().__init__(template_file, extra_inputs)
self._pyarc_exec = Path(os.environ.get('PyARC_DIR', 'PyARC.py'))
self.pyarc_inp_name = "pyarc_input.son"
self.show_stdout = show_stdout
self.show_stderr = show_stderr
self.supp_inputs = [Path(f).resolve() for f in supp_inputs]

@property
def pyarc_exec(self) -> Path:
Expand Down Expand Up @@ -178,7 +178,7 @@ def postrun(self, params: Parameters) -> ResultsPyARC:
print("Post-run for PyARC Plugin")

time = datetime.fromtimestamp(self._run_time * 1e-9)
inputs = [p.name for p in self.supp_inputs]
inputs = [p.name for p in self.extra_inputs]
inputs.append(self.pyarc_inp_name)
outputs = [p for p in Path.cwd().iterdir() if p.name not in inputs]
return ResultsPyARC(params, time, inputs, outputs, self.pyarc.user_object)
Expand Down

0 comments on commit 7b13c27

Please sign in to comment.