From 1ad0793c3d46da5e7ce001a147a1ee9b61554879 Mon Sep 17 00:00:00 2001 From: Jaap de Jong Date: Tue, 16 May 2023 16:48:23 +0200 Subject: [PATCH 1/5] Add warnings for exceptions that might be thrown when evaluating to docstring and handle exceptions in test_examples function --- src/interpreter.jl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/interpreter.jl b/src/interpreter.jl index a6ac2cc..4bc361b 100644 --- a/src/interpreter.jl +++ b/src/interpreter.jl @@ -1,6 +1,8 @@ """ Runs the interpreter on all examples with the given input table and expression. Returns a list of true/false values indicating if the expression satisfies the corresponding example. +WARNING: This function throws exceptions that are caused in the given expression. +These exceptions have to be handled by the caller of this function. """ function test_all_examples(tab::SymbolTable, expr::Any, examples::Vector{Example})::Vector{Bool} outcomes = Vector{Bool}() @@ -14,10 +16,16 @@ end """ Evaluates all examples and returns true iff all examples pass. Shortcircuits as soon as an example is found for which the program doesn't work. +Returns false if one of the examples produces an error. """ function test_examples(tab::SymbolTable, expr::Any, examples::Vector{Example})::Bool for example ∈ filter(e -> e isa IOExample, examples) - if example.out ≠ test_with_input(tab, expr, example.in) + try + output = test_with_input(tab, expr, example.in) + if output ≠ test_with_input(tab, expr, example.in) + return false + end + catch return false end end @@ -27,6 +35,8 @@ end """ Interprets an expression or symbol with the given symboltable and the input. +WARNING: This function throws exceptions that are caused in the given expression. +These exceptions have to be handled by the caller of this function. """ function test_with_input(tab::SymbolTable, expr::Any, input::Dict) # Add input variable values @@ -37,6 +47,8 @@ end """ Executes a given expression on a set of inputs and returns the respective outputs. +WARNING: This function throws exceptions that are caused in the given expression. +These exceptions have to be handled by the caller of this function. """ function execute_on_examples(tab::SymbolTable, expr::Any, example_inputs::Vector{Dict{Symbol, Any}})::Vector{Any} return [test_with_input(tab, expr, example) for example in example_inputs] @@ -51,6 +63,8 @@ Example: tab = SymbolTable(:f => f, :x => x) ex = :(f(x)) interpret(tab, ex) +WARNING: This function throws exceptions that are caused in the given expression. +These exceptions have to be handled by the caller of this function. """ interpret(tab::SymbolTable, x::Any) = x interpret(tab::SymbolTable, s::Symbol) = tab[s] From 292f5842e24136de034fa0b13bf364fa24a705ae Mon Sep 17 00:00:00 2001 From: Jaap de Jong Date: Thu, 29 Jun 2023 11:17:01 +0200 Subject: [PATCH 2/5] Add HerbCore dependency --- src/HerbEvaluation.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HerbEvaluation.jl b/src/HerbEvaluation.jl index 83a21ea..259c2e8 100644 --- a/src/HerbEvaluation.jl +++ b/src/HerbEvaluation.jl @@ -1,5 +1,6 @@ module HerbEvaluation +using ..HerbCore using ..HerbData using ..HerbGrammar From 5fc6d5f10b8633a31d2ed6d65968cc81acbe8567 Mon Sep 17 00:00:00 2001 From: Tilman Hinnerichs Date: Wed, 16 Aug 2023 11:41:34 +0200 Subject: [PATCH 3/5] Mollify Readme and update documentation for interpret --- README.md | 7 +++++-- src/interpreter.jl | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 344ad36..9fdb217 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ -# Evaluation.jl +# HerbEvaluation.jl + +This package provides functionality for evaluating (candidate) programs in the Herb Program Synthesis framework. `HerbEvaluation` can handle arbitrary Julia expressions, but also arbitrary other interpretors for which an evaluation function is given. + +For general usage please see the `HerbExamples` and our test suite. -This package provides functionality for evaluating (candidate) programs in the Herb Program Synthesis framework. diff --git a/src/interpreter.jl b/src/interpreter.jl index 8bac8e6..5b63cef 100644 --- a/src/interpreter.jl +++ b/src/interpreter.jl @@ -53,6 +53,8 @@ end """ + interpret(tab::SymbolTable, ex::Expr) + Evaluates an expression without compiling it. Uses AST and symbol lookups. Only supports :call and :(=) expressions at the moment. From e9bcf99f17e6066afa8d7db4997a97dd1dfdec20 Mon Sep 17 00:00:00 2001 From: Tilman Hinnerichs Date: Wed, 16 Aug 2023 12:11:09 +0200 Subject: [PATCH 4/5] Update dependencies for Test and HerbCore --- Project.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index fb9a75b..1942b70 100644 --- a/Project.toml +++ b/Project.toml @@ -1,16 +1,19 @@ name = "HerbEvaluation" uuid = "eb1bf938-813d-4942-ac0f-b4657a683e76" -authors = ["Jaap de Jong "] +authors = ["Jaap de Jong ", "Tilman Hinnerichs "] version = "0.1.0" [deps] HerbData = "495a3ad3-8034-41b3-a087-aacf2fd71098" HerbGrammar = "4ef9e186-2fe5-4b24-8de7-9f7291f24af7" +HerbCore = "2b23ba43-8213-43cb-b5ea-38c12b45bd45" [compat] julia = "1.8" HerbData = "0.1.0" HerbGrammar = "0.1.0" +HerbCore = "0.1.0" +julia = "1.8" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From e10ba9c180c2c2a952f6f324e1bd136d7a26d5ed Mon Sep 17 00:00:00 2001 From: Tilman Hinnerichs Date: Wed, 16 Aug 2023 12:15:29 +0200 Subject: [PATCH 5/5] Remove double julia dep --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index 1942b70..b79a996 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,6 @@ julia = "1.8" HerbData = "0.1.0" HerbGrammar = "0.1.0" HerbCore = "0.1.0" -julia = "1.8" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"