From 97a0718426ccf156c37939413b60fd507b65d80e Mon Sep 17 00:00:00 2001 From: Tilman Hinnerichs Date: Sat, 23 Nov 2024 13:00:25 +0100 Subject: [PATCH 1/5] Removed FixedShapedIterator --- src/fixed_shaped_iterator.jl | 107 ----------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 src/fixed_shaped_iterator.jl diff --git a/src/fixed_shaped_iterator.jl b/src/fixed_shaped_iterator.jl deleted file mode 100644 index 3712fbfe..00000000 --- a/src/fixed_shaped_iterator.jl +++ /dev/null @@ -1,107 +0,0 @@ -Base.@doc """ - @programiterator FixedShapedIterator() - -Enumerates all programs that extend from the provided fixed shaped tree. -The [Solver](@ref) is required to be in a state without any [Hole](@ref)s. - -!!! warning: this iterator is used as a baseline for the constraint propagation thesis. After the thesis, this iterator can (and should) be deleted. -""" FixedShapedIterator -@programiterator FixedShapedIterator() - -""" - priority_function(::FixedShapedIterator, g::AbstractGrammar, tree::AbstractRuleNode, parent_value::Union{Real, Tuple{Vararg{Real}}}) - -Assigns a priority value to a `tree` that needs to be considered later in the search. Trees with the lowest priority value are considered first. -""" -function priority_function( - ::FixedShapedIterator, - g::AbstractGrammar, - tree::AbstractRuleNode, - parent_value::Union{Real, Tuple{Vararg{Real}}} -) - parent_value + 1; -end - - -""" - hole_heuristic(::FixedShapedIterator, node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference} - -Defines a heuristic over fixed shaped holes. Returns a [`HoleReference`](@ref) once a hole is found. -""" -function hole_heuristic(::FixedShapedIterator, node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference} - return heuristic_leftmost_fixed_shaped_hole(node, max_depth); -end - -""" - Base.iterate(iter::FixedShapedIterator) - -Describes the iteration for a given [`TopDownIterator`](@ref) over the grammar. The iteration constructs a [`PriorityQueue`](@ref) first and then prunes it propagating the active constraints. Recursively returns the result for the priority queue. -""" -function Base.iterate(iter::FixedShapedIterator) - # Priority queue with number of nodes in the program - pq :: PriorityQueue{SolverState, Union{Real, Tuple{Vararg{Real}}}} = PriorityQueue() - - solver = iter.solver - @assert !contains_nonuniform_hole(get_tree(iter.solver)) "A FixedShapedIterator cannot iterate partial programs with Holes" - - if isfeasible(solver) - enqueue!(pq, get_state(solver), priority_function(iter, get_grammar(solver), get_tree(solver), 0)) - end - return _find_next_complete_tree(solver, pq, iter) -end - - -""" - Base.iterate(iter::FixedShapedIterator, pq::DataStructures.PriorityQueue) - -Describes the iteration for a given [`TopDownIterator`](@ref) and a [`PriorityQueue`](@ref) over the grammar without enqueueing new items to the priority queue. Recursively returns the result for the priority queue. -""" -function Base.iterate(iter::FixedShapedIterator, pq::DataStructures.PriorityQueue) - return _find_next_complete_tree(iter.solver, pq, iter) -end - -""" - _find_next_complete_tree(solver::Solver, pq::PriorityQueue, iter::FixedShapedIterator)::Union{Tuple{RuleNode, PriorityQueue}, Nothing} - -Takes a priority queue and returns the smallest AST from the grammar it can obtain from the queue or by (repeatedly) expanding trees that are in the queue. -Returns `nothing` if there are no trees left within the depth limit. -""" -function _find_next_complete_tree( - solver::Solver, - pq::PriorityQueue, - iter::FixedShapedIterator -)::Union{Tuple{RuleNode, PriorityQueue}, Nothing} - while length(pq) ≠ 0 - (state, priority_value) = dequeue_pair!(pq) - load_state!(solver, state) - - hole_res = hole_heuristic(iter, get_tree(solver), typemax(Int)) - if hole_res ≡ already_complete - #the tree is complete - return (get_tree(solver), pq) - elseif hole_res ≡ limit_reached - # The maximum depth is reached - continue - elseif hole_res isa HoleReference - # UniformHole was found - (; hole, path) = hole_res - - rules = findall(hole.domain) - number_of_rules = length(rules) - for (i, rule_index) ∈ enumerate(findall(hole.domain)) - if i < number_of_rules - state = save_state!(solver) - end - @assert isfeasible(solver) "Attempting to expand an infeasible tree: $(get_tree(solver))" - remove_all_but!(solver, path, rule_index) - if isfeasible(solver) - enqueue!(pq, get_state(solver), priority_function(iter, get_grammar(solver), get_tree(solver), priority_value)) - end - if i < number_of_rules - load_state!(solver, state) - end - end - end - end - return nothing -end From 47616a5188c12855d443acb5bc4d16c30aef3559 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Tue, 10 Dec 2024 12:18:36 +0300 Subject: [PATCH 2/5] Remove non-existent symbols from export Add `Aqua.jl` to test for this in the future as well as other Aqua tests. Ignoring the type piracies on `RuleNode`s and `AbstractGrammar`. Ideally, this functionality would be moved to `HerbCore`, but that can wait. --- Project.toml | 10 ++++++++-- src/HerbSearch.jl | 4 ---- test/runtests.jl | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 92925bb3..605a2844 100644 --- a/Project.toml +++ b/Project.toml @@ -10,25 +10,31 @@ HerbCore = "2b23ba43-8213-43cb-b5ea-38c12b45bd45" 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] +Aqua = "0.8.9" DataStructures = "0.17,0.18" HerbConstraints = "^0.2.0" HerbCore = "^0.3.0" HerbGrammar = "^0.4.0" HerbInterpret = "^0.1.3" HerbSpecification = "^0.1.0" +LegibleLambdas = "0.3.0" +Logging = "1.11.0" MLStyle = "^0.4.17" +Random = "1.11.0" StatsBase = "^0.34" +Test = "1.11.0" julia = "^1.8" [extras] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" LegibleLambdas = "f1f30506-32fe-5131-bd72-7c197988f9e5" +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "LegibleLambdas"] +test = ["Test", "LegibleLambdas", "Aqua", "Logging"] diff --git a/src/HerbSearch.jl b/src/HerbSearch.jl index 1573f9b3..b9c8ac6d 100644 --- a/src/HerbSearch.jl +++ b/src/HerbSearch.jl @@ -16,7 +16,6 @@ include("uniform_iterator.jl") include("heuristics.jl") -include("fixed_shaped_iterator.jl") include("top_down_iterator.jl") include("evaluate.jl") @@ -42,8 +41,6 @@ export ProgramIterator, @programiterator, - ContextSensitivePriorityEnumerator, - heuristic_leftmost, heuristic_rightmost, heuristic_random, @@ -56,7 +53,6 @@ export optimal_program, suboptimal_program, - FixedShapedIterator, UniformIterator, next_solution!, diff --git a/test/runtests.jl b/test/runtests.jl index 35428d65..d0ffaa7b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,12 +5,14 @@ using HerbInterpret using HerbConstraints using HerbSpecification using Test +using Aqua include("test_helpers.jl") using Random Random.seed!(1234) @testset "HerbSearch.jl" verbose=true begin + @testset "Aqua" Aqua.test_all(HerbSearch, piracies = (treat_as_own=[RuleNode, AbstractGrammar],)) include("test_search_procedure.jl") include("test_context_free_iterators.jl") include("test_sampling.jl") From 00fdacf2ab1bde66b603ba458e214710c7acbe2b Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Tue, 10 Dec 2024 12:22:58 +0300 Subject: [PATCH 3/5] Fix compat bounds for standard libraries --- Project.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 605a2844..0a81598a 100644 --- a/Project.toml +++ b/Project.toml @@ -23,11 +23,11 @@ HerbGrammar = "^0.4.0" HerbInterpret = "^0.1.3" HerbSpecification = "^0.1.0" LegibleLambdas = "0.3.0" -Logging = "1.11.0" +Logging = "1.8.0,1.9.0,1.10.0,1.11.0" MLStyle = "^0.4.17" -Random = "1.11.0" +Random = "1.8.0,1.9.0,1.10.0,1.11.0" StatsBase = "^0.34" -Test = "1.11.0" +Test = "1.8.0,1.9.0,1.10.0,1.11.0" julia = "^1.8" [extras] From 88ac91f2bd54e61308f14adc92928c837558eb89 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:27:24 +0300 Subject: [PATCH 4/5] Switch to separate test `Project.toml` structure --- Project.toml | 13 ------------- test/Project.toml | 12 ++++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 test/Project.toml diff --git a/Project.toml b/Project.toml index 0a81598a..5bcd8220 100644 --- a/Project.toml +++ b/Project.toml @@ -15,26 +15,13 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" [compat] -Aqua = "0.8.9" DataStructures = "0.17,0.18" HerbConstraints = "^0.2.0" HerbCore = "^0.3.0" HerbGrammar = "^0.4.0" HerbInterpret = "^0.1.3" HerbSpecification = "^0.1.0" -LegibleLambdas = "0.3.0" -Logging = "1.8.0,1.9.0,1.10.0,1.11.0" MLStyle = "^0.4.17" Random = "1.8.0,1.9.0,1.10.0,1.11.0" StatsBase = "^0.34" -Test = "1.8.0,1.9.0,1.10.0,1.11.0" julia = "^1.8" - -[extras] -Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" -LegibleLambdas = "f1f30506-32fe-5131-bd72-7c197988f9e5" -Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[targets] -test = ["Test", "LegibleLambdas", "Aqua", "Logging"] diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 00000000..9e172f7b --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,12 @@ +[deps] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +HerbConstraints = "1fa96474-3206-4513-b4fa-23913f296dfc" +HerbCore = "2b23ba43-8213-43cb-b5ea-38c12b45bd45" +HerbGrammar = "4ef9e186-2fe5-4b24-8de7-9f7291f24af7" +HerbInterpret = "5bbddadd-02c5-4713-84b8-97364418cca7" +HerbSearch = "3008d8e8-f9aa-438a-92ed-26e9c7b4829f" +HerbSpecification = "6d54aada-062f-46d8-85cf-a1ceaf058a06" +LegibleLambdas = "f1f30506-32fe-5131-bd72-7c197988f9e5" +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From b9ad9ab07ffb1adbde176910ab6f7bf1381fae54 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:27:37 +0300 Subject: [PATCH 5/5] Bump minor version number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 5bcd8220..9f9d5d3f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "HerbSearch" uuid = "3008d8e8-f9aa-438a-92ed-26e9c7b4829f" authors = ["Sebastijan Dumancic ", "Jaap de Jong ", "Nicolae Filat ", "Piotr Cichoń ", "Tilman Hinnerichs "] -version = "0.3.1" +version = "0.4.0" [deps] DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"