Skip to content

Commit 429d4cc

Browse files
authored
Merge branch 'master' into master
2 parents 62f5f29 + 024fc3c commit 429d4cc

7 files changed

Lines changed: 559 additions & 19 deletions

File tree

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ install:
1818

1919
before_script:
2020
- export PYTHONPATH=$PYTHONPATH:$(pwd)
21+
- export PYRO_HOME=$(pwd)
2122
- ./mk.sh
2223

2324
script:
2425
- flake8 .
25-
- pytest -v --cov=. --cov-config .coveragerc --nbval --ignore=docs --ignore=./multigrid/variable_coeff_elliptic.ipynb --ignore=examples
26+
- pytest -v --cov=. --cov-config .coveragerc --nbval --ignore=docs --ignore=./multigrid/variable_coeff_elliptic.ipynb --ignore=examples/mesh --ignore=examples/multigrid
2627
# - travis-sphinx build
2728

2829
# after_success:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ http://python-hydro.github.io/pyro2/
7777
directory.
7878

7979
* Define the environment variable `PYRO_HOME` to point to the
80-
`pyro2/` directory (only needed to regression testing)
80+
`pyro2/` directory (only needed for regression testing)
8181

8282
* Build the Fortran source. In `pyro2/` type
8383

docs/source/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The following steps are needed before running pyro:
3636
./mk.sh
3737
3838
* define the environment variable ``PYRO_HOME`` to point to
39-
the ``pyro2/`` directory (only needed for regression testing)
39+
the ``pyro2/`` directory
4040

4141
.. code-block:: none
4242

docs/source/running.rst

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Running
22
=======
33

4-
Pyro can be run in two ways: either from the commandline, using the ``pyro.py`` script and passing in the solver, problem and inputs as arguments, or by using the :func:`Pyro <pyro.Pyro>` class.
4+
Pyro can be run in two ways: either from the commandline, using the ``pyro.py``
5+
script and passing in the solver, problem and inputs as arguments, or by using
6+
the :func:`Pyro <pyro.Pyro>` class.
57

68
Commandline
79
------------
@@ -47,13 +49,17 @@ above run, we could do:
4749
Pyro class
4850
----------
4951

50-
Alternatively, pyro can be run using the :func:`Pyro <pyro.Pyro>` class. This is done by the following steps:
52+
Alternatively, pyro can be run using the :func:`Pyro <pyro.Pyro>` class. This provides
53+
an interface that enables simulations to be set up and run in a Jupyter notebook - see
54+
``examples/examples.ipynb`` for an example notebook. A simulation can be set up and run
55+
by carrying out the following steps:
5156

5257
* create a ``Pyro`` object, initializing it with a specific solver
5358
* initialize the problem, passing in runtime parameters and inputs
5459
* run the simulation
5560

56-
For example, if we wished to use the ``compressible`` solver to run the Kelvin-Helmholtz problem ``kh``, we would do the following:
61+
For example, if we wished to use the ``compressible`` solver to run the
62+
Kelvin-Helmholtz problem ``kh``, we would do the following:
5763

5864
.. code-block:: python
5965
@@ -62,7 +68,12 @@ For example, if we wished to use the ``compressible`` solver to run the Kelvin-H
6268
inputs_file="inputs.kh")
6369
pyro.run_sim()
6470
65-
Instead of using an inputs file to define the problem parameters, we can define a dictionary of parameters and pass them into the :func:`initialize_problem <pyro.Pyro.initialize_problem>` function using the keyword argument ``inputs_dict``. If an inputs file is also passed into the function, the parameters in the dictionary will override any parameters in the file. For example, if we wished to turn off visualization for the previous example, we would do:
71+
Instead of using an inputs file to define the problem parameters, we can define a
72+
dictionary of parameters and pass them into the :func:`initialize_problem
73+
<pyro.Pyro.initialize_problem>` function using the keyword argument ``inputs_dict``.
74+
If an inputs file is also passed into the function, the parameters in the dictionary
75+
will override any parameters in the file. For example, if we wished to turn off
76+
visualization for the previous example, we would do:
6677

6778
.. code-block:: python
6879
@@ -71,21 +82,26 @@ Instead of using an inputs file to define the problem parameters, we can define
7182
inputs_file="inputs.kh",
7283
inputs_dict=parameters)
7384
74-
It's possible to evolve the simulation forward timestep by timestep manually using the :func:`single_step <pyro.Pyro.single_step>` function (rather than allowing :func:`run_sim <pyro.Pyro.run_sim>` to do this for us). To evolve our example simulation forward by a single step, we'd run
85+
It's possible to evolve the simulation forward timestep by timestep manually using
86+
the :func:`single_step <pyro.Pyro.single_step>` function (rather than allowing
87+
:func:`run_sim <pyro.Pyro.run_sim>` to do this for us). To evolve our example
88+
simulation forward by a single step, we'd run
7589

7690
.. code-block:: python
7791
7892
pyro.single_step()
7993
80-
This will fill the boundary conditions, compute the timestep ``dt``, evolve a single timestep and do output/visualization (if required).
94+
This will fill the boundary conditions, compute the timestep ``dt``, evolve a
95+
single timestep and do output/visualization (if required).
8196

8297

8398
Runtime options
8499
---------------
85100

86101
The behavior of the main driver, the solver, and the problem setup can
87102
be controlled by runtime parameters specified in the inputs file (or
88-
via the command line or passed into the ``initialize_problem`` function). Runtime parameters are grouped into sections,
103+
via the command line or passed into the ``initialize_problem`` function).
104+
Runtime parameters are grouped into sections,
89105
with the heading of that section enclosed in ``[ .. ]``. The list of
90106
parameters are stored in three places:
91107

examples/examples.ipynb

Lines changed: 497 additions & 0 deletions
Large diffs are not rendered by default.

paper/paper.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ tags:
99
- partial differential equations
1010

1111
authors:
12-
- name: Michael Zingale
13-
orcid: 0000-0001-8401-030X
14-
affiliation: 1
1512
- name: Alice Harpole
1613
orcid: 0000-0002-1530-781X
1714
affiliation: 1
15+
- name: Michael Zingale
16+
orcid: 0000-0001-8401-030X
17+
affiliation: 1
1818
- name: Ian Hawke
1919
orcid: 0000-0003-4805-0309
2020
affiliation: 2

pyro.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def __init__(self, solver_name):
4747
if solver_name not in valid_solvers:
4848
msg.fail("ERROR: %s is not a valid solver" % solver_name)
4949

50+
self.pyro_home = os.path.dirname(os.path.realpath(__file__)) + '/'
51+
5052
# import desired solver under "solver" namespace
5153
self.solver = importlib.import_module(solver_name)
5254
self.solver_name = solver_name
@@ -57,11 +59,13 @@ def __init__(self, solver_name):
5759

5860
# parameter defaults
5961
self.rp = runparams.RuntimeParameters()
60-
self.rp.load_params("_defaults")
61-
self.rp.load_params(solver_name + "/_defaults")
62+
self.rp.load_params(self.pyro_home + "_defaults")
63+
self.rp.load_params(self.pyro_home + solver_name + "/_defaults")
6264

6365
self.tc = profile.TimerCollection()
6466

67+
self.is_initialized = False
68+
6569
def initialize_problem(self, problem_name, inputs_file=None, inputs_dict=None,
6670
other_commands=None):
6771
"""
@@ -79,7 +83,7 @@ def initialize_problem(self, problem_name, inputs_file=None, inputs_dict=None,
7983
Other command line parameter options
8084
"""
8185

82-
problem_defaults_file = self.solver_name + \
86+
problem_defaults_file = self.pyro_home + self.solver_name + \
8387
"/problems/_" + problem_name + ".defaults"
8488

8589
# problem-specific runtime parameters
@@ -90,7 +94,7 @@ def initialize_problem(self, problem_name, inputs_file=None, inputs_dict=None,
9094
if inputs_file is not None:
9195
if not os.path.isfile(inputs_file):
9296
# check if the param file lives in the solver's problems directory
93-
inputs_file = self.solver_name + "/problems/" + inputs_file
97+
inputs_file = self.pyro_home + self.solver_name + "/problems/" + inputs_file
9498
if not os.path.isfile(inputs_file):
9599
msg.fail("ERROR: inputs file does not exist")
96100

@@ -127,11 +131,16 @@ def initialize_problem(self, problem_name, inputs_file=None, inputs_dict=None,
127131

128132
self.sim.cc_data.t = 0.0
129133

134+
self.is_initialized = True
135+
130136
def run_sim(self):
131137
"""
132138
Evolve entire simulation
133139
"""
134140

141+
if not self.is_initialized:
142+
msg.fail("ERROR: problem has not been initialized")
143+
135144
tm_main = self.tc.timer("main")
136145
tm_main.begin()
137146

@@ -168,6 +177,10 @@ def single_step(self):
168177
"""
169178
Do a single step
170179
"""
180+
181+
if not self.is_initialized:
182+
msg.fail("ERROR: problem has not been initialized")
183+
171184
# fill boundary conditions
172185
self.sim.cc_data.fill_BC_all()
173186

@@ -200,7 +213,20 @@ def single_step(self):
200213
basename = self.rp.get_param("io.basename")
201214
plt.savefig("{}{:04d}.png".format(basename, self.sim.n))
202215

203-
tm_vis.end()
216+
if self.make_bench or (result != 0 and self.reset_bench_on_fail):
217+
self.store_as_benchmark()
218+
219+
def __repr__(self):
220+
""" Return a representation of the Pyro object """
221+
s = "Solver = {}\n".format(self.solver_name)
222+
if self.is_initialized:
223+
s += "Problem = {}\n".format(self.sim.problem_name)
224+
s += "Simulation time = {}\n".format(self.sim.cc_data.t)
225+
s += "Simulation step number = {}\n".format(self.sim.n)
226+
s += "\nRuntime Parameters"
227+
s += "\n------------------\n"
228+
s += str(self.sim.rp)
229+
return s
204230

205231

206232
class PyroBenchmark(Pyro):
@@ -284,7 +310,7 @@ def store_as_benchmark(self):
284310
"ERROR: unable to create the solver's tests/ directory")
285311

286312
basename = self.rp.get_param("io.basename")
287-
bench_file = self.solver_name + "/tests/" + \
313+
bench_file = self.pyro_home + self.solver_name + "/tests/" + \
288314
basename + "%4.4d" % (self.sim.n)
289315
msg.warning("storing new benchmark: {}\n".format(bench_file))
290316
self.sim.write(bench_file)

0 commit comments

Comments
 (0)