From c61a0a24a024f29440efb99c63d47c58e12b8711 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:32:13 +0100 Subject: [PATCH] Add skeleton for probe --- Project.toml | 4 ++++ src/Garden.jl | 6 ++++- src/probe/README.md | 17 ++++++++++++++ src/probe/method.jl | 56 +++++++++++++++++++++++++++++++++++++++++++++ src/probe/ref.bib | 11 +++++++++ test/Project.toml | 1 + test/runtests.jl | 6 ++++- test/test_probe.jl | 21 +++++++++++++++++ 8 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 src/probe/README.md create mode 100644 src/probe/method.jl create mode 100644 src/probe/ref.bib create mode 100644 test/test_probe.jl diff --git a/Project.toml b/Project.toml index dff7aa8..f293049 100644 --- a/Project.toml +++ b/Project.toml @@ -2,5 +2,9 @@ name = "Garden" uuid = "22d0bc84-1826-4aaf-b584-c2a6a91114a2" version = "0.1.0" +[deps] +DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +Herb = "c09c6b7f-4f63-49de-90d9-97a3563c0f4a" + [compat] julia = "^1.8" diff --git a/src/Garden.jl b/src/Garden.jl index 2e9e045..9d0184a 100644 --- a/src/Garden.jl +++ b/src/Garden.jl @@ -1,5 +1,9 @@ module Garden -greet() = print("Hello World!") +using DocStringExtensions +using Herb + +include("probe/method.jl") +export probe, decide_probe, modify_grammar_probe end # module Garden diff --git a/src/probe/README.md b/src/probe/README.md new file mode 100644 index 0000000..e347378 --- /dev/null +++ b/src/probe/README.md @@ -0,0 +1,17 @@ +# Probe + +[Publication (Open Access)](https://doi.org/10.1145/3428295) + +``` +@article{DBLP:journals/pacmpl/BarkePP20, + author = {Shraddha Barke and + Hila Peleg and + Nadia Polikarpova}, + title = {Just-in-time learning for bottom-up enumerative synthesis}, + journal = {Proc. {ACM} Program. Lang.}, + volume = {4}, + number = {{OOPSLA}}, + pages = {227:1--227:29}, + year = {2020} +} +``` diff --git a/src/probe/method.jl b/src/probe/method.jl new file mode 100644 index 0000000..2a69e65 --- /dev/null +++ b/src/probe/method.jl @@ -0,0 +1,56 @@ +using Herb.HerbCore: AbstractRuleNode, AbstractGrammar +using Herb.HerbSpecification: AbstractSpecification, Problem +using Herb.HerbSearch: ProgramIterator + +""" + $(TYPEDSIGNATURES) + +Decide whether to keep a program, or discard it, based on the specification. +""" +function decide_probe( + program::AbstractRuleNode, + spec::AbstractSpecification +)::Bool end + +""" + $(TYPEDSIGNATURES) + +Modify the grammar based on the programs kept during the `decide` step. +""" +function modify_grammar_probe( + saved_programs::AbstractVector{<:AbstractRuleNode}, + grammar::AbstractGrammar +)::AbstractGrammar end + +""" + $(TYPEDSIGNATURES) + +Synthesize a program using the `grammar` that follows the `spec` following the method from +["Just-in-time learning for bottom-up enumerative synthesis"](https://doi.org/10.1145/3428295). +``` +""" +function probe( + iterator::ProgramIterator, + grammar::AbstractGrammar, + spec::Problem, + budget::Int, + max_total_iterations::Int; + kwargs... +)::AbstractRuleNode + + # - Run a budgeted search + # - Gets an iterator with some limit (the low-level budget) + # - This is a normal iterator + # - Collect (partial) successes + # - Function to define success, which is just % of examples solved by default + # - Function takes any kind of specification + # - Boolean output: should the program be saved or not? + # - Modify the grammar + # - Function to modify the grammar based on the successes + # - Takes the successes (saved programs) + # - Modify the grammar: in place or return a new one, TBD + # - Rinse and repeat + # - Function defining high-level budget + # - For now, just a parameter defining the number of overall runs of budgeted search + +end \ No newline at end of file diff --git a/src/probe/ref.bib b/src/probe/ref.bib new file mode 100644 index 0000000..77b7c41 --- /dev/null +++ b/src/probe/ref.bib @@ -0,0 +1,11 @@ +@article{DBLP:journals/pacmpl/BarkePP20, + author = {Shraddha Barke and + Hila Peleg and + Nadia Polikarpova}, + title = {Just-in-time learning for bottom-up enumerative synthesis}, + journal = {Proc. {ACM} Program. Lang.}, + volume = {4}, + number = {{OOPSLA}}, + pages = {227:1--227:29}, + year = {2020} +} \ No newline at end of file diff --git a/test/Project.toml b/test/Project.toml index 737dfda..f083866 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,5 @@ [deps] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +Herb = "c09c6b7f-4f63-49de-90d9-97a3563c0f4a" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index d62ec4b..958b426 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,5 +10,9 @@ using JET @testset "Code linting (JET.jl)" begin JET.test_package(Garden; target_defined_modules = true) end - # Write your tests here. + for (root, dirs, files) in walkdir(@__DIR__) + for file in filter(contains(r"test_"), files) + include(file) + end + end end diff --git a/test/test_probe.jl b/test/test_probe.jl new file mode 100644 index 0000000..66145bc --- /dev/null +++ b/test/test_probe.jl @@ -0,0 +1,21 @@ +using Herb.HerbGrammar: @cfgrammar +using Herb.HerbSearch: BFSIterator +using Herb.HerbSpecification: IOExample, Problem + +@testset "Probe" begin + grammar = @cfgrammar begin + Int = Int + Int + Int = 1 | 2 + end + problem = Problem( + [IOExample(Dict(), 2)] + ) + result = probe( + BFSIterator, + grammar, + problem, + 10, + 20 + ) + @test !isnothing(result) +end \ No newline at end of file