From b6ac9461da70b0d3cf053caaca3ec03309b7da91 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 19 Mar 2024 03:38:52 +0100 Subject: Improve error messages at evaluation time --- examples/error_chain.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/error_chain.py (limited to 'examples') diff --git a/examples/error_chain.py b/examples/error_chain.py new file mode 100644 index 0000000..31a75ea --- /dev/null +++ b/examples/error_chain.py @@ -0,0 +1,26 @@ +try: + import mdpoly +except ModuleNotFoundError: + import sys + import pathlib + parent = pathlib.Path(__file__).resolve().parent.parent + sys.path.append(str(parent)) + +from mdpoly import State, Variable, Parameter +from mdpoly.representations import SparseRepr + +def make_invalid_expr(x, y): + return x ** (-4) + +def make_another_invalid(x, y): + return x ** -1 + +def make_ok_expr(x, y): + w = make_invalid_expr(x, y) + z = make_another_invalid(x, y) + return x + z + y + w + +x, y, z = Variable.from_names("x, y, z") + +bad = make_ok_expr(x, y) +bad.to_sparse(State()) -- cgit v1.2.1