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

Constraint propagation solver and new hole types (4 PRs) #25

Merged
merged 26 commits into from
Apr 2, 2024
Merged

Conversation

Whebon
Copy link
Contributor

@Whebon Whebon commented Mar 11, 2024

Large PR involving 4 repositories:

  • HerbSearch @solver
  • HerbConstraints @solver
  • HerbCore @holes-types
  • HerbGrammar @holes-types (small changes)

On these respective branches, I am worked on two new major components:

  1. A constraint propagation solver

  2. New hole types

  3. I am replacing propagate_constraints with a new constraint Solver struct. The goal is to increase the inference of constraint propagators while reducing the number of propagations needed. Currently constraint solving is integrated in the top down iterator, but the new solver should also be compatible with any type of program iterator. This means that all program iterators should be rewritten to be compatible with the constraint solver. The idea is that iterators must manipulate program trees through the solver’s API so the propagation of the constraints can happen under the hood. For example:

"""
    substitute!(solver::Solver, path::Vector{Int}, new_node::AbstractRuleNode)

Substitute the node at the `path`, with a `new_node`
"""
function substitute!(solver::Solver, path::Vector{Int}, new_node::AbstractRuleNode)
    #...
end
"""
    fill_hole!(solver::Solver, path::Vector{Int}, rule_index::Int)

Fill in the hole located at the `path` with rule `rule_index`.
It is assumed the path points to a hole, otherwise an exception will be thrown.
It is assumed rule_index ∈ hole.domain, otherwise an exception will be thrown.
"""
function fill_hole!(solver::Solver, path::Vector{Int}, rule_index::Int)
    #...
end
  1. The Hole struct will be split up into two new concrete hole structs: FixedShapedHole and VariableShapedHole. The main difference between these two structs is that the domain of a fixed shaped hole contains only rules of exactly the same child types (e.g. A -> A + B and A -> A * B have the same childtypes. A -> A + A has different childtypes). The advantage of fixed shaped holes is that child nodes can already be instantiated before the concrete rule of the parent is known. This reduces the amount of trees that need to be stored in memory and can be exploited for stronger inference during constraint propagation.

…h_with_hole`, and `_rulenode_match` with `pattern_match`
@Whebon Whebon requested a review from THinnerichs March 11, 2024 18:09
@@ -0,0 +1,56 @@
"""
Forbidden <: GrammarConstraint
Copy link
Member

Choose a reason for hiding this comment

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

it is not clear from the naming what Forbidden actually is. Maybe rename to ForbiddenConstraint?



"""
Solver(grammar::Grammar, sym::Symbol)
Copy link
Member

Choose a reason for hiding this comment

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

Why not add with_statistics to docs?

track!(solver.statistics, "schedule!")
track!(solver.statistics, "schedule! $(typeof(constraint))")
if constraint ∉ keys(solver.schedule)
enqueue!(solver.schedule, constraint, 99) #TODO: replace `99` with `get_priority(c)`
Copy link
Member

Choose a reason for hiding this comment

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

We need to fix this asap before the hackathon.

end

#TODO: remove the scope of `HerbCore`?
function HerbCore.get_node_at_location(solver::Solver, location::Vector{Int})::AbstractRuleNode
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep this, as it provides some module separation.

empty!(dict[event_path])
end
end
# Always propagate all constraints:
Copy link
Member

Choose a reason for hiding this comment

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

Remove comments.

include("test_treemanipulations.jl")
include("test_varnode.jl")
include("test_pattern_match.jl")
#include("test_pattern_match_edgecases.jl")
Copy link
Member

Choose a reason for hiding this comment

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

We should re-include this in the hackathon.

@THinnerichs THinnerichs merged commit 4e4db46 into dev Apr 2, 2024
@THinnerichs THinnerichs deleted the solver branch July 15, 2024 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants