diff options
author | Nao Pross <np@0hm.ch> | 2024-03-19 03:38:52 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-03-19 03:38:52 +0100 |
commit | b6ac9461da70b0d3cf053caaca3ec03309b7da91 (patch) | |
tree | 338b0c92e2a8fd5289039f9110f10da0f85f49ee /examples/error_chain.py | |
parent | Add helper method WithOps.to_sparse to give sparse representation (diff) | |
download | mdpoly-b6ac9461da70b0d3cf053caaca3ec03309b7da91.tar.gz mdpoly-b6ac9461da70b0d3cf053caaca3ec03309b7da91.zip |
Improve error messages at evaluation time
Diffstat (limited to '')
-rw-r--r-- | examples/error_chain.py | 26 |
1 files changed, 26 insertions, 0 deletions
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()) |