Skip to content

Commit

Permalink
disable runtime vis by default when using the Pyro class directly (#220)
Browse files Browse the repository at this point in the history
this makes the Jupyter usage easier, since we don't fill up the
notebook with looks of plots.  Runtime vis is still on by default
when run via the commandline (using pyro_sim.py)
  • Loading branch information
zingale authored Aug 31, 2024
1 parent e9df7b2 commit ec50bf1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 50 deletions.
58 changes: 10 additions & 48 deletions examples/examples.ipynb

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions pyro/pyro_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,26 @@ class Pyro:
The main driver to run pyro.
"""

def __init__(self, solver_name):
def __init__(self, solver_name, from_commandline=False):
"""
Constructor
Parameters
----------
solver_name : str
Name of solver to use
from_commandline : bool
True if we are running from the commandline -- this enables
runtime vis by default.
"""

msg.bold('pyro ...')

if solver_name not in valid_solvers:
msg.fail(f"ERROR: {solver_name} is not a valid solver")

self.from_commandline = from_commandline

self.pyro_home = os.path.dirname(os.path.realpath(__file__)) + '/'
if not solver_name.startswith("pyro."):
solver_import = "pyro." + solver_name
Expand All @@ -70,6 +75,13 @@ def __init__(self, solver_name):
self.rp.load_params(self.pyro_home + "_defaults")
self.rp.load_params(self.pyro_home + self.solver_name + "/_defaults")

# manually override the dovis default
# for Jupyter, we want runtime vis disabled by default
if self.from_commandline:
self.rp.set_param("vis.dovis", 1)
else:
self.rp.set_param("vis.dovis", 0)

self.tc = profile.TimerCollection()

self.is_initialized = False
Expand Down Expand Up @@ -378,7 +390,7 @@ def main():
comp_bench=args.compare_benchmark,
make_bench=args.make_benchmark)
else:
pyro = Pyro(args.solver[0])
pyro = Pyro(args.solver[0], from_commandline=True)

pyro.initialize_problem(problem_name=args.problem[0],
inputs_file=args.param[0],
Expand Down
16 changes: 16 additions & 0 deletions pyro/util/runparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ def get_param(self, key):

if key in self.params:
return self.params[key]

raise KeyError(f"ERROR: runtime parameter {key} not found")

def set_param(self, key, value):
"""
manually set one of the existing runtime parameters
"""

if not self.params:
msg.warning("WARNING: runtime parameters not yet initialized")
self.load_params("_defaults")

if key in self.params:
self.params[key] = value
return

raise KeyError(f"ERROR: runtime parameter {key} not found")

def print_unused_params(self):
Expand Down

0 comments on commit ec50bf1

Please sign in to comment.