From cb4076c2427d35b72a5fd3cd1d4b4ee3891fab28 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Mon, 25 Nov 2019 00:12:19 -0600 Subject: [PATCH 1/4] Fix bitrot in example; add Examples CI job --- .gitlab-ci.yml | 14 ++++++++++++++ examples/adaptive_rk.py | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1c8d95b..1dfa95e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,6 +28,20 @@ Python 3: reports: junit: test/pytest.xml +Python 3 Examples: + script: + - py_version=3 + - EXTRA_INSTALL=numpy + - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-py-project-and-run-examples.sh + - ". ./build-py-project-and-run-examples.sh" + tags: + - python3 + except: + - tags + artifacts: + reports: + junit: test/pytest.xml + Documentation: script: - EXTRA_INSTALL="numpy" diff --git a/examples/adaptive_rk.py b/examples/adaptive_rk.py index c2b093d..999598d 100644 --- a/examples/adaptive_rk.py +++ b/examples/adaptive_rk.py @@ -59,7 +59,7 @@ def adaptive_rk_method(tol): return Min(((tol / Max((1.0e-16, norm(err)))) ** (1 / 2), 2.0)) # Code for the main state - with CodeBuilder(label="adaptrk") as cb: + with CodeBuilder("adaptrk") as cb: # Euler cb(y_e, y + dt * g(t, y)) @@ -68,7 +68,6 @@ def adaptive_rk_method(tol): # Adaptation cb(dt_old, dt) - cb.reset_dep_tracking() cb(dt, dt * dt_scaling(tol, y_h - y_e)) # Accept or reject step @@ -78,7 +77,8 @@ def adaptive_rk_method(tol): cb(y, y_h) cb(t, t + dt_old) - return DAGCode.create_with_steady_phase(cb.phase_dependencies, cb.statements) + return DAGCode.from_phases_list( + [cb.as_execution_phase("adaptrk")], "adaptrk") if __name__ == "__main__": -- GitLab From df4f4900b74f394f3a3e7c9b5e222a4f42f90f52 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Mon, 25 Nov 2019 00:14:43 -0600 Subject: [PATCH 2/4] Minor code organization improvements --- examples/adaptive_rk.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/adaptive_rk.py b/examples/adaptive_rk.py index 999598d..f5fb89a 100644 --- a/examples/adaptive_rk.py +++ b/examples/adaptive_rk.py @@ -23,6 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +import numpy as np + from dagrt.language import DAGCode, CodeBuilder from pymbolic import var @@ -81,10 +83,7 @@ def adaptive_rk_method(tol): [cb.as_execution_phase("adaptrk")], "adaptrk") -if __name__ == "__main__": - from dagrt.codegen import PythonCodeGenerator - import numpy as np - +def main(): def rhs(t, y): u, v = y return np.array([v, -u/t**2], dtype=np.float64) @@ -94,8 +93,9 @@ if __name__ == "__main__": return np.sqrt(t)*( 5*np.sqrt(3)/3*np.sin(inner) + np.cos(inner) - ) + ) + from dagrt.codegen import PythonCodeGenerator codegen = PythonCodeGenerator("AdaptiveRK") tolerances = [1.0e-1, 1.0e-2, 1.0e-3, 1.0e-5] @@ -114,3 +114,7 @@ if __name__ == "__main__": print("-" * 25) for tol, error in zip(tolerances, errors): print("{:.2e}\t{:.2e}".format(tol, error)) + + +if __name__ == "__main__": + main() -- GitLab From 89ce32c8e574cd45526ff5ae307c82279a04654f Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Mon, 25 Nov 2019 00:19:58 -0600 Subject: [PATCH 3/4] Fix computation of final time --- examples/adaptive_rk.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/adaptive_rk.py b/examples/adaptive_rk.py index f5fb89a..1034602 100644 --- a/examples/adaptive_rk.py +++ b/examples/adaptive_rk.py @@ -107,8 +107,8 @@ def main(): solver = AdaptiveRK({"g": rhs}) solver.set_up(t_start=1.0, dt_start=0.1, context={"y": np.array([1., 3.])}) for evt in solver.run(t_end=10.0): - pass - errors.append(solver.global_state_y[0] - soln(10.0)) + final_time = evt.t + errors.append(solver.global_state_y[0] - soln(final_time)) print("Tolerance\tError") print("-" * 25) -- GitLab From 4f8363a39e83db275fd24f379918821b3f3571a7 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Mon, 25 Nov 2019 00:21:15 -0600 Subject: [PATCH 4/4] Use absolute error --- examples/adaptive_rk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/adaptive_rk.py b/examples/adaptive_rk.py index 1034602..b1e3537 100644 --- a/examples/adaptive_rk.py +++ b/examples/adaptive_rk.py @@ -108,7 +108,7 @@ def main(): solver.set_up(t_start=1.0, dt_start=0.1, context={"y": np.array([1., 3.])}) for evt in solver.run(t_end=10.0): final_time = evt.t - errors.append(solver.global_state_y[0] - soln(final_time)) + errors.append(np.abs(solver.global_state_y[0] - soln(final_time))) print("Tolerance\tError") print("-" * 25) -- GitLab