Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable runtime vis by default when using the Pyro class directly #220

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -368,7 +380,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