Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #11 from Herb-AI/dev
Browse files Browse the repository at this point in the history
Merge changes from dev
  • Loading branch information
THinnerichs authored Aug 16, 2023
2 parents 5fce19b + e10ba9c commit 6baff57
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name = "HerbEvaluation"
uuid = "eb1bf938-813d-4942-ac0f-b4657a683e76"
authors = ["Jaap de Jong <[email protected]>"]
authors = ["Jaap de Jong <[email protected]>", "Tilman Hinnerichs <[email protected]>"]
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"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions src/HerbEvaluation.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module HerbEvaluation

using HerbCore
using HerbData
using HerbGrammar

Expand Down
21 changes: 19 additions & 2 deletions src/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Runs the interpreter on all examples with the given input table and expression.
The symbol table defines everything (functions, symbols) that are not input variables to the program to be synthesised.
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}(undef, length(examples))
Expand All @@ -19,10 +21,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
Expand All @@ -34,6 +42,8 @@ end
test_with_input(tab::SymbolTable, expr::Any, input::Dict)
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
Expand All @@ -46,23 +56,30 @@ end
execute_on_examples(tab::SymbolTable, expr::Any, example_inputs::Vector{Dict{Symbol, Any}})::Vector{Any}
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]
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.
### Example usage
Example usage:
```
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]
Expand Down

0 comments on commit 6baff57

Please sign in to comment.