Skip to content

Commit

Permalink
Merge pull request #70 from Herb-AI/dev
Browse files Browse the repository at this point in the history
Checkpoint recent developments
  • Loading branch information
ReubenJ authored Mar 14, 2024
2 parents c5e7dde + e08f886 commit 183a8b8
Show file tree
Hide file tree
Showing 36 changed files with 1,138 additions and 1,204 deletions.
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)
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)")

"""
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

4 comments on commit 183a8b8

@ReubenJ
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

Release Notes:

  • The search(...) function replaced by synth(...)—this includes a new signature. Please refer to the updated documentation.
  • All iterators have been refactored
  • Herb dependencies updated, most importantly, HerbData -> HerbSpecification

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Register Failed
@ReubenJ, it looks like you are not a publicly listed member/owner in the parent organization (Herb-AI).
If you are a member/owner, you will need to change your membership to public. See GitHub Help

@ReubenJ
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

Release Notes:

  • The search(...) function replaced by synth(...)—this includes a new signature. Please refer to the updated documentation.
  • All iterators have been refactored
  • Herb dependencies updated, most importantly, HerbData -> HerbSpecification

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/102860

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 183a8b8a7e7791774cbf09eb5850e2375fd22ccf
git push origin v0.2.0

Please sign in to comment.