Skip to content

Commit

Permalink
disable I/O by default in Jupyter (#259)
Browse files Browse the repository at this point in the history
also, the first and last plotfile were not respecting io.do_io
  • Loading branch information
zingale authored Sep 8, 2024
1 parent 8e6acd6 commit 73d8038
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
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 @@ -149,11 +149,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 @@ -198,7 +199,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 @@ -208,10 +212,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

0 comments on commit 73d8038

Please sign in to comment.