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 I/O by default in Jupyter #259

Merged
merged 3 commits into from
Sep 8, 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
3 changes: 2 additions & 1 deletion examples/examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@
"driver.tmax = 1.0\n",
"driver.verbose = 0\n",
"io.basename = smooth_\n",
"io.do_io = 1\n",
"io.do_io = 0\n",
"io.dt_out = 0.2\n",
"io.force_final_output = 0\n",
"io.n_out = 10000\n",
"mesh.grid_type = Cartesian2d\n",
"mesh.nx = 32\n",
Expand Down
1 change: 1 addition & 0 deletions pyro/_defaults
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ basename = pyro_ ; basename for output files
dt_out = 0.1 ; simulation time between writing output files
n_out = 10000 ; number of timesteps between writing output files
do_io = 1 ; do we output at all?
force_final_output = 0 ; regardless of do_io, do we output when the simulation ends?

[vis]

Expand Down
19 changes: 13 additions & 6 deletions pyro/pyro_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ def initialize_problem(self, problem_name, *, inputs_file=None, inputs_dict=None

self.rp.load_params(inputs_file, no_new=1)

# manually override the dovis and verbose defaults
# manually override the I/O, dovis, and verbose defaults
# for Jupyter, we want runtime vis disabled by default
if not self.from_commandline:
self.rp.set_param("vis.dovis", 0)
self.rp.set_param("driver.verbose", 0)
self.rp.set_param("io.do_io", 0)

if inputs_dict is not None:
for k, v in inputs_dict.items():
Expand Down Expand Up @@ -162,7 +163,10 @@ def run_sim(self):

# output the 0th data
basename = self.rp.get_param("io.basename")
self.sim.write(f"{basename}{self.sim.n:04d}")
do_io = self.rp.get_param("io.do_io")

if do_io:
self.sim.write(f"{basename}{self.sim.n:04d}")

if self.dovis:
plt.figure(num=1, figsize=(8, 6), dpi=100, facecolor='w')
Expand All @@ -172,10 +176,13 @@ def run_sim(self):
self.single_step()

# final output
if self.verbose > 0:
msg.warning("outputting...")
basename = self.rp.get_param("io.basename")
self.sim.write(f"{basename}{self.sim.n:04d}")
force_final_output = self.rp.get_param("io.force_final_output")

if do_io or force_final_output:
if self.verbose > 0:
msg.warning("outputting...")
basename = self.rp.get_param("io.basename")
self.sim.write(f"{basename}{self.sim.n:04d}")

tm_main.end()
# -------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions pyro/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ def run_test(t, reset_fails, store_all_benchmarks, rtol, nproc):
reset_bench_on_fail=reset_fails,
make_bench=store_all_benchmarks)
p.initialize_problem(t.problem, inputs_file=t.inputs, inputs_dict=t.options)
start_n = p.sim.n
err = p.run_sim(rtol)
finally:
os.chdir(orig_cwd)
if err == 0:
# the test passed; clean up the output files for developer use
basename = p.rp.get_param("io.basename")
(test_dir / f"{basename}{start_n:04d}.h5").unlink()
(test_dir / f"{basename}{p.sim.n:04d}.h5").unlink()
(test_dir / "inputs.auto").unlink()
test_dir.rmdir()
Expand All @@ -86,7 +84,7 @@ def do_tests(out_file,
reset_fails=False, store_all_benchmarks=False,
single=None, solver=None, rtol=1e-12, nproc=1):

opts = {"driver.verbose": 0, "vis.dovis": 0, "io.do_io": 0}
opts = {"driver.verbose": 0, "vis.dovis": 0, "io.do_io": 0, "io.force_final_output": 1}

results = {}

Expand Down