Skip to content

Commit

Permalink
get rid of command_line_params
Browse files Browse the repository at this point in the history
we don't need a separate RuntimeParameters method to parse a string,
instead we can just do this in pyro_sim.py and then use the existing
set_val method from a dict.  This also allows us to simplify the
confusing Pyro() interface.
  • Loading branch information
zingale committed Sep 6, 2024
1 parent 633f394 commit 85e09cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 41 deletions.
23 changes: 12 additions & 11 deletions pyro/pyro_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

import pyro.util.io_pyro as io
import pyro.util.profile_pyro as profile
from pyro.util import compare, msg, runparams
from pyro.util import compare, msg
from pyro.util.runparams import RuntimeParameters, _get_val


valid_solvers = ["advection",
"advection_nonuniform",
Expand Down Expand Up @@ -71,16 +73,15 @@ def __init__(self, solver_name, *, from_commandline=False):
# -------------------------------------------------------------------------

# parameter defaults
self.rp = runparams.RuntimeParameters()
self.rp = RuntimeParameters()
self.rp.load_params(self.pyro_home + "_defaults")
self.rp.load_params(self.pyro_home + self.solver_name + "/_defaults")

self.tc = profile.TimerCollection()

self.is_initialized = False

def initialize_problem(self, problem_name, *, inputs_file=None, inputs_dict=None,
other_commands=None):
def initialize_problem(self, problem_name, *, inputs_file=None, inputs_dict=None):
"""
Initialize the specific problem
Expand All @@ -92,8 +93,6 @@ def initialize_problem(self, problem_name, *, inputs_file=None, inputs_dict=None
Filename containing problem's runtime parameters
inputs_dict : dict
Dictionary containing extra runtime parameters
other_commands : str
Other command line parameter options
"""
# pylint: disable=attribute-defined-outside-init

Expand Down Expand Up @@ -128,10 +127,6 @@ def initialize_problem(self, problem_name, *, inputs_file=None, inputs_dict=None
for k, v in inputs_dict.items():
self.rp.set_param(k, v)

# and any commandline overrides
if other_commands is not None:
self.rp.command_line_params(other_commands)

# write out the inputs.auto
self.rp.print_paramfile()

Expand Down Expand Up @@ -401,9 +396,15 @@ def main():
else:
pyro = Pyro(args.solver[0], from_commandline=True)

other = {}
for param_string in args.other:
k, v = param_string.split("=")
other[k] = _get_val(v)

print(other)
pyro.initialize_problem(problem_name=args.problem[0],
inputs_file=args.param[0],
other_commands=args.other)
inputs_dict=other)
pyro.run_sim()


Expand Down
30 changes: 0 additions & 30 deletions pyro/util/runparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,36 +163,6 @@ def load_params(self, pfile, no_new=0):

self.param_comments[key] = comment.strip()

def command_line_params(self, cmd_strings):
"""
finds dictionary pairs from a string that came from the
commandline. Stores the parameters in only if they
already exist.
we expect things in the string in the form:
["sec.opt=value", "sec.opt=value"]
with each opt an element in the list
Parameters
----------
cmd_strings : list
The list of strings containing runtime parameter pairs
"""

for item in cmd_strings:

# break it apart
key, value = item.split("=")

# we only want to override existing keys/values
if key not in self.params:
msg.warning("warning, key: %s not defined" % (key))
continue

# check in turn whether this is an integer, float, or string
self.params[key] = _get_val(value)

def get_param(self, key):
"""
returns the value of the runtime parameter corresponding to the
Expand Down

0 comments on commit 85e09cd

Please sign in to comment.