Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkpoint recent developments #70

Merged
merged 50 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
03162d0
Print expression when an exception is thrown during evaluation
ReubenJ Jan 9, 2024
82289e2
Added parameter documentation to main search method, based on search_…
Jan 18, 2024
f29ee97
Make RuleNodeAndCount mutable fixing sampling bugs
THinnerichs Jan 18, 2024
786e114
Merge pull request #49 from Herb-AI/display-expr-on-eval-exception
THinnerichs Jan 18, 2024
a75cac1
Merge pull request #51 from Herb-AI/search_function_parameters
THinnerichs Jan 18, 2024
add67bb
rewrote realistic test to julia tests
Jan 18, 2024
942850c
not running long tests standard
Jan 19, 2024
0b80297
Add `mod` keyword to search functions
ReubenJ Jan 8, 2024
f0cc1eb
Added parameter documentation to main search method, based on search_…
Jan 18, 2024
da48c8b
Merge pull request #53 from Herb-AI/realistic_tests_julia
IssaHanou Jan 19, 2024
f5e008e
Refactor enumerators to iterators and search strategies
Whebon Jan 19, 2024
5ad3c7a
Remove cfg from HerbSearch
Whebon Jan 19, 2024
a967b1a
Refactor search into synth and evaluate
Whebon Jan 19, 2024
553c268
Define top down iterators using the program iterator macro
Whebon Jan 19, 2024
8b04c7f
Export synth
Whebon Jan 19, 2024
20a7423
add MLStyle
sourceCode4 Jan 21, 2024
2a62bce
add iterator macro
sourceCode4 Jan 21, 2024
d431783
add tests for the iterator macro
sourceCode4 Jan 21, 2024
d3d36c6
Merge branch 'search-strategies' into iterator-macro
Whebon Jan 21, 2024
8bf5537
Make TopDownIterators compatible with the programiterator macro
Whebon Jan 21, 2024
e7cab30
correct the ProgramIterator doc
sourceCode4 Jan 22, 2024
97b7962
add the documentation for the macro
sourceCode4 Jan 22, 2024
299ff81
clarify the doc
sourceCode4 Jan 22, 2024
03e3ed6
add the header to the doc
sourceCode4 Jan 22, 2024
e3ef827
Add keyworded arguments to @programiterator (wip)
Whebon Jan 22, 2024
f974bdc
Merge branch 'iterator-macro' of https://github.com/Herb-AI/HerbSearc…
Whebon Jan 22, 2024
2707b39
Propagate `shortcircuit` and `allow_evaluation_errors` params
Whebon Jan 22, 2024
b5a5c96
fix the macro to work with default values
sourceCode4 Jan 23, 2024
c3f9a8a
add tests
sourceCode4 Jan 23, 2024
bfe09b1
rename variable
sourceCode4 Jan 23, 2024
a57b65c
add to the docstring
sourceCode4 Jan 23, 2024
292faca
merge commits
THinnerichs Jan 25, 2024
8fd7aa3
Update for HerbSpecifications and HerbInterpret
THinnerichs Jan 23, 2024
7fa2d43
Update tests for new search procedure
THinnerichs Jan 25, 2024
fd3ae1b
Start refactor of stochastic iterators
THinnerichs Jan 29, 2024
0f81b1a
Fix all tests fro stochastic and genetic search
THinnerichs Jan 31, 2024
f6e3db9
Add docs to TopDown Iterators
THinnerichs Jan 31, 2024
5949d96
Update casting in fitness function; add version bound for HerbSpecifi…
THinnerichs Feb 7, 2024
0039742
Merge iterator-macro branch with dev, and added mod to synth
THinnerichs Feb 7, 2024
1f0086b
Fix realistic tests
THinnerichs Feb 7, 2024
f90ca79
Update introduction
THinnerichs Feb 7, 2024
c8b6cba
Update README.md
THinnerichs Feb 7, 2024
ee7f7f9
Fix type in versioning
THinnerichs Feb 26, 2024
2afd84c
Grammar -> AbstractGrammar according to HerbCore 0.2, HerbGrammar -> 0.2
THinnerichs Feb 26, 2024
2fa7093
Fix DataStructures version
THinnerichs Feb 27, 2024
b060f8b
Merge pull request #62 from Herb-AI/upate_versions
THinnerichs Feb 29, 2024
760a80f
Add test coverage reporting to CI.yml
ReubenJ Mar 1, 2024
7a8cc81
Update README.md to include codecov badge
ReubenJ Mar 1, 2024
d0de9c8
Test on latest stable release rather than 1.10 explicitly
ReubenJ Mar 4, 2024
e08f886
Merge pull request #64 from Herb-AI/CI/report-coverage
THinnerichs Mar 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
matrix:
version:
- '1.8'
- '1'
- 'nightly'
os:
- ubuntu-latest
Expand All @@ -33,3 +34,11 @@ jobs:
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: Herb-AI/HerbSearch.jl
files: lcov.info
fail_ci_if_error: false

19 changes: 10 additions & 9 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
name = "HerbSearch"
uuid = "3008d8e8-f9aa-438a-92ed-26e9c7b4829f"
authors = ["Sebastijan Dumancic <[email protected]>", "Jaap de Jong <[email protected]>", "Nicolae Filat <[email protected]>", "Piotr Cichoń <[email protected]>", "Tilman Hinnerichs <[email protected]>"]
version = "0.1.1"
version = "0.2.0"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
HerbConstraints = "1fa96474-3206-4513-b4fa-23913f296dfc"
HerbCore = "2b23ba43-8213-43cb-b5ea-38c12b45bd45"
HerbData = "495a3ad3-8034-41b3-a087-aacf2fd71098"
HerbGrammar = "4ef9e186-2fe5-4b24-8de7-9f7291f24af7"
HerbInterpret = "5bbddadd-02c5-4713-84b8-97364418cca7"
HerbSpecification = "6d54aada-062f-46d8-85cf-a1ceaf058a06"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
DataStructures = "0.17,0.18"
HerbConstraints = "0.1.0"
HerbCore = "0.1.1"
HerbData = "0.1.1"
HerbGrammar = "0.1.0"
HerbInterpret = "0.1.0"
StatsBase = "0.34"
julia = "1.8"
HerbConstraints = "^0.1.0"
HerbCore = "^0.2.0"
HerbGrammar = "^0.2.0"
HerbInterpret = "^0.1.1"
HerbSpecification = "^0.1.0"
StatsBase = "^0.34"
julia = "^1.8"

[extras]
LegibleLambdas = "f1f30506-32fe-5131-bd72-7c197988f9e5"
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Search.jl

[![codecov](https://codecov.io/gh/Herb-AI/HerbSearch.jl/graph/badge.svg?token=VUK6MXLCU4)](https://codecov.io/gh/Herb-AI/HerbSearch.jl)
[![Build Status](https://github.com/Herb-AI/HerbSearch.jl/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/Herb-AI/HerbSearch.jl/actions/workflows/CI.yml?query=branch%3Amaster)
[![Dev-Docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://Herb-AI.github.io/Herb.jl/dev)

# HerbSearch.jl

This package contains search procedure implementations for the Herb Program Synthesis framework.

For full documentation please see the `Herb.jl` documentation
For full documentation please see the [`Herb.jl` documentation](https://herb-ai.github.io/Herb.jl/dev/).

## Getting started
To use this project, initialize the project with
For a quick tutorial on how to get started with using `HerbSearch.jl` have a look at our [introductory tutorial](https://herb-ai.github.io/Herb.jl/dev/get_started/) or [Advanced search procedures](https://herb-ai.github.io/Herb.jl/dev/tutorials/advanced_search/).

If you want to help developing this project, initialize the project with
```shell
julia --project=. -e 'using Pkg; Pkg.instantiate()'
```
56 changes: 27 additions & 29 deletions src/HerbSearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,68 @@ using DataStructures
using HerbCore
using HerbGrammar
using HerbConstraints
using HerbData
using HerbInterpret
using HerbSpecification
using MLStyle

include("sampling_grammar.jl")
include("enumerator_constructors.jl")

include("expression_iterator.jl")
include("program_iterator.jl")
include("count_expressions.jl")

include("csg_priority_enumerator.jl")
include("cfg_priority_enumerator.jl")

include("heuristics.jl")

include("stochastic_search_iterator.jl")
include("top_down_iterator.jl")

include("evaluate.jl")

include("search_procedure.jl")
include("stochastic_functions/cost_functions.jl")

include("stochastic_iterator.jl")
include("stochastic_functions/cost_functions.jl")
include("stochastic_functions/neighbourhood.jl")
include("stochastic_functions/propose.jl")
include("stochastic_functions/accept.jl")
include("stochastic_functions/temperature.jl")
include("stochastic_enumerators.jl")

include("genetic_functions/fitness.jl")
include("genetic_functions/mutation.jl")
include("genetic_functions/crossover.jl")
include("genetic_functions/select_parents.jl")
include("genetic_search_iterator.jl")
include("genetic_enumerators.jl")

export
count_expressions,
ExpressionIterator,
ProgramIterator,
@programiterator,

ContextSensitivePriorityEnumerator,
ContextFreePriorityEnumerator,

heuristic_leftmost,
heuristic_rightmost,
heuristic_random,
heuristic_smallest_domain,

search_rulenode,
search,
search_best,
synth,
SynthResult,
optimal_program,
suboptimal_program,

TopDownIterator,
BFSIterator,
DFSIterator,
MLFSIterator,

MHSearchIterator,
VLSNSearchIterator,
SASearchIterator,

bfs_priority_function,
get_bfs_enumerator,
get_mh_enumerator,
get_vlsn_enumerator,
get_sa_enumerator,
get_genetic_enumerator,
mean_squared_error,
misclassification,
mse_error_function,

dfs_priority_function,
get_dfs_enumerator,

most_likely_priority_function,
get_most_likely_first_enumerator,
mutate_random!,
crossover_swap_children_2,
GeneticSearchIterator,
misclassification,
validate_iterator,
sample,
rand
end # module HerbSearch
15 changes: 0 additions & 15 deletions src/cfg_priority_enumerator.jl

This file was deleted.

10 changes: 5 additions & 5 deletions src/count_expressions.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"""
count_expressions(grammar::Grammar, max_depth::Int, max_size::Int, sym::Symbol)
count_expressions(grammar::AbstractGrammar, max_depth::Int, max_size::Int, sym::Symbol)

Counts and returns the number of possible expressions of a grammar up to max_depth with start symbol sym.
"""
function count_expressions(grammar::Grammar, max_depth::Int, max_size::Int, sym::Symbol)
function count_expressions(grammar::AbstractGrammar, max_depth::Int, max_size::Int, sym::Symbol)
l = 0
# Calculate length without storing all expressions
for _ ∈ get_bfs_enumerator(grammar, max_depth, max_size, sym)
for _ ∈ BFSIterator(grammar, sym, max_depth=max_depth, max_size=max_size)
l += 1
end
return l
end

"""
count_expressions(iter::ExpressionIterator)
count_expressions(iter::ProgramIterator)

Counts and returns the number of possible expressions in the expression iterator. The Iterator is not modified.
"""
count_expressions(iter::ExpressionIterator) = count_expressions(iter.grammar, iter.max_depth, iter.max_size, iter.sym)
count_expressions(iter::ProgramIterator) = count_expressions(iter.grammar, iter.max_depth, iter.max_size, iter.sym)

Check warning on line 20 in src/count_expressions.jl

View check run for this annotation

Codecov / codecov/patch

src/count_expressions.jl#L20

Added line #L20 was not covered by tests
122 changes: 0 additions & 122 deletions src/enumerator_constructors.jl

This file was deleted.

46 changes: 46 additions & 0 deletions src/evaluate.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
struct EvaluationError <: Exception
expr::Expr
input::Dict{Symbol, Any}
error::Exception
end

Base.showerror(io::IO, e::EvaluationError) = print(io, "An exception was thrown while evaluating the expression $(e.expr) on input $(e.input): $(e.error)")

Check warning on line 7 in src/evaluate.jl

View check run for this annotation

Codecov / codecov/patch

src/evaluate.jl#L7

Added line #L7 was not covered by tests

"""
evaluate(problem::Problem{Vector{IOExample}}, expr::Any, tab::SymbolTable; allow_evaluation_errors::Bool=false)

Evaluate the expression on the examples.

Optional parameters:

- `shortcircuit` - Whether to stop evaluating after finding single example fails, to speed up the [synth](@ref) procedure. If true, the returned score is an underapproximation of the actual score.
- `allow_evaluation_errors` - Whether the search should continue if an exception is thrown in the evaluation or throw the error

Returns a score in the interval [0, 1]
"""
function evaluate(problem::Problem{Vector{IOExample}}, expr::Any, symboltable::SymbolTable; shortcircuit::Bool=true, allow_evaluation_errors::Bool=false)::Number
number_of_satisfied_examples = 0

crashed = false
for example ∈ problem.spec
try
output = execute_on_input(symboltable, expr, example.in)
if (output == example.out)
number_of_satisfied_examples += 1
elseif (shortcircuit)
break;
end
catch e
# You could also decide to handle less severe errors (such as index out of range) differently,
# for example by just increasing the error value and keeping the program as a candidate.
crashed = true
# Throw the error again if evaluation errors aren't allowed
eval_error = EvaluationError(expr, example.in, e)
allow_evaluation_errors || throw(eval_error)
break
end
end

return number_of_satisfied_examples/length(problem.spec);
end

Loading
Loading