Skip to content

Commit

Permalink
update fields in Decapodes Language closes #131 (#132)
Browse files Browse the repository at this point in the history
* update fields in Decapodes Language closes #131

* ENH: more descriptive field names in decapodes language

* ENH: rename judgements to context

* change Judge to Judgement for consistency
  • Loading branch information
jpfairbanks authored Jul 27, 2023
1 parent 169876c commit 335818f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/Decapodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Unicode

export normalize_unicode, DerivOp, append_dot,
SchDecapode, SchNamedDecapode, AbstractDecapode, AbstractNamedDecapode, Decapode, NamedDecapode, SummationDecapode, fill_names!, expand_operators, add_constant!, add_parameter, infer_types!, resolve_overloads!, op1_inf_rules_1D, op2_inf_rules_1D, op1_inf_rules_2D, op2_inf_rules_2D, op1_res_rules_1D, op2_res_rules_1D, op1_res_rules_2D, op2_res_rules_2D,
Term, Var, Judge, Eq, AppCirc1, AppCirc2, App1, App2, Plus, Tan, term, parse_decapode,
Term, Var, Judgement, Eq, AppCirc1, AppCirc2, App1, App2, Plus, Tan, term, parse_decapode,
VectorForm, PhysicsState, findname, findnode,
compile, compile_env, gensim, evalsim, closest_point, flat_op,
AbstractMeshKey, loadmesh, Icosphere, Rectangle_30x10, Torus_30x10, Point_Map,
Expand Down
51 changes: 25 additions & 26 deletions src/language.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
# - This is straightforward from a language perspective but unclear the best
# - way to represent this in a Decapode ACSet.
@data Term begin
Var(Symbol)
Lit(Symbol)
Judge(Var, Symbol, Symbol) # Symbol 1: Form0 Symbol 2: X
AppCirc1(Vector{Symbol}, Term)
App1(Symbol, Term)
App2(Symbol, Term, Term)
Plus(Vector{Term})
Mult(Vector{Term})
Tan(Term)
Var(name::Symbol)
Lit(name::Symbol)
Judgement(var::Var, dim::Symbol, space::Symbol) # Symbol 1: Form0 Symbol 2: X
AppCirc1(fs::Vector{Symbol}, arg::Term)
App1(f::Symbol, arg::Term)
App2(f::Symbol, arg1::Term, arg2::Term)
Plus(args::Vector{Term})
Mult(args::Vector{Term})
Tan(var::Term)
end

@data Equation begin
Eq(Term, Term)
Eq(lhs::Term, rhs::Term)
end

# A struct to store a complete Decapode
# TODO: Have the decopode macro compile to a DecaExpr
struct DecaExpr
judgements::Vector{Judge}
@as_record struct DecaExpr
context::Vector{Judgement}
equations::Vector{Equation}
end

Expand Down Expand Up @@ -53,11 +52,11 @@ function parse_decapode(expr::Expr)
::LineNumberNode => missing
# TODO: If user doesn't provide space, this gives a temp space so we can continue to construction
# For now spaces don't matter so this is fine but if they do, this will need to change
Expr(:(::), a::Symbol, b::Symbol) => Judge(Var(a), b, :I)
Expr(:(::), a::Expr, b::Symbol) => map(sym -> Judge(Var(sym), b, :I), a.args)
Expr(:(::), a::Symbol, b::Symbol) => Judgement(Var(a), b, :I)
Expr(:(::), a::Expr, b::Symbol) => map(sym -> Judgement(Var(sym), b, :I), a.args)

Expr(:(::), a::Symbol, b) => Judge(Var(a), b.args[1], b.args[2])
Expr(:(::), a::Expr, b) => map(sym -> Judge(Var(sym), b.args[1], b.args[2]), a.args)
Expr(:(::), a::Symbol, b) => Judgement(Var(a), b.args[1], b.args[2])
Expr(:(::), a::Expr, b) => map(sym -> Judgement(Var(sym), b.args[1], b.args[2]), a.args)

Expr(:call, :(==), lhs, rhs) => Eq(term(lhs), term(rhs))
_ => error("The line $line is malformed")
Expand All @@ -67,8 +66,8 @@ function parse_decapode(expr::Expr)
eqns = []
foreach(stmts) do s
@match s begin
::Judge => push!(judges, s)
::Vector{Judge} => append!(judges, s)
::Judgement => push!(judges, s)
::Vector{Judgement} => append!(judges, s)
::Eq => push!(eqns, s)
_ => error("Statement containing $s of type $(typeof(s)) was not added.")
end
Expand Down Expand Up @@ -133,7 +132,7 @@ reduce_term!(t::Term, d::AbstractDecapode, syms::Dict{Symbol, Int}) =
txv = add_part!(d, :Var, type=:infer)
tx = add_part!(d, :TVar, incl=txv)
tanop = add_part!(d, :Op1, src=!(t,d,syms), tgt=txv, op1=DerivOp)
return txv #syms[x._1]
return txv #syms[x[1]]
end
_ => throw("Inline type judgements not yet supported!")
end
Expand Down Expand Up @@ -201,9 +200,9 @@ end
function Decapode(e::DecaExpr)
d = Decapode{Any, Any}()
symbol_table = Dict{Symbol, Int}()
for judgement in e.judgements
var_id = add_part!(d, :Var, type=(judgement._2, judgement._3))
symbol_table[judgement._1._1] = var_id
for judgement in e.context
var_id = add_part!(d, :Var, type=(judgement.dim, judgement.space))
symbol_table[judgement.var.name] = var_id
end
deletions = Vector{Int}()
for eq in e.equations
Expand All @@ -218,9 +217,9 @@ function SummationDecapode(e::DecaExpr)
d = SummationDecapode{Any, Any, Symbol}()
symbol_table = Dict{Symbol, Int}()

for judgement in e.judgements
var_id = add_part!(d, :Var, name=judgement._1._1, type=judgement._2)
symbol_table[judgement._1._1] = var_id
for judgement in e.context
var_id = add_part!(d, :Var, name=judgement.var.name, type=judgement.dim)
symbol_table[judgement.var.name] = var_id
end

deletions = Vector{Int}()
Expand Down
12 changes: 6 additions & 6 deletions test/diag2dwd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import Decapodes: DecaExpr
#######

# Construct roughly what the @decapode macro should return for Diffusion
js = [Judge(Var(:C), :Form0, :X),
Judge(Var(:Ċ₁), :Form0, :X),
Judge(Var(:Ċ₂), :Form0, :X)
js = [Judgement(Var(:C), :Form0, :X),
Judgement(Var(:Ċ₁), :Form0, :X),
Judgement(Var(:Ċ₂), :Form0, :X)
]
# TODO: Do we need to handle the fact that all the functions are parameterized by a space?
eqs = [Eq(Var(:Ċ₁), AppCirc1([:₀⁻¹, :dual_d₁, :₁, :k, :d₀], Var(:C))),
Expand All @@ -66,9 +66,9 @@ import Decapodes: DecaExpr

all(isassigned(test_cset_named[:name], i) for i in parts(test_cset_named,:Var))

sup_js = js = [Judge(Var(:C), :Form0, :X),
Judge(Var(:ϕ₁), :Form0, :X),
Judge(Var(:ϕ₂), :Form0, :X)
sup_js = js = [Judgement(Var(:C), :Form0, :X),
Judgement(Var(:ϕ₁), :Form0, :X),
Judgement(Var(:ϕ₂), :Form0, :X)
]
sup_eqs = [Eq(Var(:ϕ₁), AppCirc1([:₀⁻¹, :dual_d₁, :₁, :k, :d₀], Var(:C))),
Eq(Var(:ϕ₂), AppCirc1([:₀⁻¹, :dual_d₁, :₁, :d₀], Var(:C))),
Expand Down

0 comments on commit 335818f

Please sign in to comment.