Skip to content

Commit

Permalink
Merge pull request #133 from biaslab/128-meta-engine-is-still-based-o…
Browse files Browse the repository at this point in the history
…n-faulty-old-constraints-architecture

128 meta engine is still based on faulty old constraints architecture
  • Loading branch information
wouterwln authored Nov 21, 2023
2 parents 3ae0fab + 7ebcdb3 commit dbc0248
Show file tree
Hide file tree
Showing 21 changed files with 1,417 additions and 3,694 deletions.
26 changes: 26 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
style = "blue"
indent = 4
margin = 180
always_for_in = true
whitespace_typedefs = true
whitespace_ops_in_indices = true
remove_extra_newlines = true
import_to_using = false
pipe_to_function_call = false
short_to_long_function_def = false
long_to_short_function_def = false
always_use_return = false
whitespace_in_kwargs = true
annotate_untyped_fields_with_any = false
format_docstrings = false
conditional_to_if = true
trailing_comma = false
indent_submodule = false
align_assignment = true
align_struct_field = true
align_conditional = true
align_pair_arrow = true
align_matrix = false
join_lines_based_on_source = false
separate_kwargs_with_semicolon = false
surround_whereop_typeparameters = true
5 changes: 5 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ GraphPPLPlottingExt = ["Cairo", "Compose", "GraphPlot"]

[compat]
BitSetTuples = "1"
Cairo = "1.0"
Compose = "0.9"
DataStructures = "0.18"
Distributions = "0.25"
Documenter = "1.0"
GraphPlot = "0.5"
MacroTools = "0.5.6"
Memoization = "0.2"
MetaGraphsNext = "0.6"
Expand Down
7 changes: 1 addition & 6 deletions scripts/format.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ commandline_args = parse_args(s)
folders_to_format = ["scripts", "src", "test"]

overwrite = commandline_args["overwrite"]
formatted = all(
map(
folder -> JuliaFormatter.format(folder, overwrite = overwrite, verbose = true),
folders_to_format,
),
)
formatted = all(map(folder -> JuliaFormatter.format(folder, overwrite = overwrite, verbose = true), folders_to_format))

if !formatted && !overwrite
@error "JuliaFormatter lint has failed. Run `make format` from `GraphPPL.jl` main directory and commit your changes to fix code style."
Expand Down
1 change: 0 additions & 1 deletion src/GraphPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ include("constraints_macro.jl")
include("meta_engine.jl")
include("meta_macro.jl")


end # module
464 changes: 128 additions & 336 deletions src/constraints_engine.jl

Large diffs are not rendered by default.

27 changes: 6 additions & 21 deletions src/constraints_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ export @constraints
using MacroTools

function check_reserved_variable_names_constraints(e::Expr)
if any(
reserved_name -> MacroTools.inexpr(e, reserved_name),
[:(__constraints__), :(__outer_constraints__)],
)
error(
"Variable name in $(prettify(e)) cannot be used as it is a reserved variable name in the model macro.",
)
if any(reserved_name -> MacroTools.inexpr(e, reserved_name), [:(__constraints__), :(__outer_constraints__)])
error("Variable name in $(prettify(e)) cannot be used as it is a reserved variable name in the model macro.")
end
return e
end
Expand All @@ -30,8 +25,7 @@ function create_submodel_constraints(e::Expr)
end
))
if @capture(submodel, (name_, index_))
submodel_constructor =
:(GraphPPL.SpecificSubModelConstraints(GraphPPL.FactorID($name, $index)))
submodel_constructor = :(GraphPPL.SpecificSubModelConstraints(GraphPPL.FactorID($name, $index)))
else
submodel_constructor = :(GraphPPL.GeneralSubModelConstraints($submodel))
end
Expand Down Expand Up @@ -64,8 +58,7 @@ function create_factorization_combinedrange(e::Expr)
return e
end

__convert_to_indexed_statement(e::Symbol) =
:(GraphPPL.IndexedVariable($(QuoteNode(e)), nothing))
__convert_to_indexed_statement(e::Symbol) = :(GraphPPL.IndexedVariable($(QuoteNode(e)), nothing))
function __convert_to_indexed_statement(e::Expr)
if @capture(e, (var_[index_]))
return :(GraphPPL.IndexedVariable($(QuoteNode(var)), $index))
Expand Down Expand Up @@ -97,10 +90,7 @@ function convert_functionalform_constraints(e::Expr)
end
elseif @capture(e, (q(vars__)::T_))
return quote
push!(
__constraints__,
GraphPPL.FunctionalFormConstraint($(Expr(:tuple, vars...)), $T),
)
push!(__constraints__, GraphPPL.FunctionalFormConstraint($(Expr(:tuple, vars...)), $T))
end
else
return e
Expand Down Expand Up @@ -130,17 +120,12 @@ function convert_factorization_constraints(e::Expr)
return expr
end
return quote
push!(
__constraints__,
GraphPPL.FactorizationConstraint($(Expr(:tuple, lhs...)), $rhs),
)
push!(__constraints__, GraphPPL.FactorizationConstraint($(Expr(:tuple, lhs...)), $rhs))
end
end
return e
end



function constraints_macro_interior(cs_body::Expr)
cs_body = apply_pipeline(cs_body, check_for_returns_constraints)
cs_body = add_constraints_construction(cs_body)
Expand Down
Loading

0 comments on commit dbc0248

Please sign in to comment.