Skip to content

Commit

Permalink
ENH: wip, convert from Decapodes to DecaExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfairbanks committed Oct 25, 2023
1 parent 335818f commit a9561a1
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/colanguage.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Decapodes
using Catlab
using Catlab.CategoricalAlgebra

function Term(s::SummationDecapode)
judgements = map(parts(s,:Var)) do v
var = s[v, :name]
typ = s[v, :type]
Judgement(Var(var), typ, :X)

Check warning on line 9 in src/colanguage.jl

View check run for this annotation

Codecov / codecov/patch

src/colanguage.jl#L5-L9

Added lines #L5 - L9 were not covered by tests
end

op1s = map(parts(s, :Op1)) do op
x = Var(s[op, [:src, :name]])
y = Var(s[op, [:tgt, :name]])
f = s[op, :op1]
if f == :∂ₜ
y = Tan(y)

Check warning on line 17 in src/colanguage.jl

View check run for this annotation

Codecov / codecov/patch

src/colanguage.jl#L12-L17

Added lines #L12 - L17 were not covered by tests
end
Eq(y, App1(f, x))

Check warning on line 19 in src/colanguage.jl

View check run for this annotation

Codecov / codecov/patch

src/colanguage.jl#L19

Added line #L19 was not covered by tests
end

op2s = map(parts(s, :Op2)) do op
x = Var(s[op, [:proj1, :name]])
y = Var(s[op, [:proj2, :name]])
z = Var(s[op, [:res, :name]])
f = s[op, :op2]
Eq(z, App2(f, x, y))

Check warning on line 27 in src/colanguage.jl

View check run for this annotation

Codecov / codecov/patch

src/colanguage.jl#L22-L27

Added lines #L22 - L27 were not covered by tests
end

sums = map(parts(s, )) do σ
terms = map(Var, s[incident(s, σ, :summation), [:summand, :name]])
Eq(Var(s[σ, [:sum,:name]]), Plus(terms))

Check warning on line 32 in src/colanguage.jl

View check run for this annotation

Codecov / codecov/patch

src/colanguage.jl#L30-L32

Added lines #L30 - L32 were not covered by tests
end
Decapodes.DecaExpr(judgements, vcat(op1s, op2s, sums))

Check warning on line 34 in src/colanguage.jl

View check run for this annotation

Codecov / codecov/patch

src/colanguage.jl#L34

Added line #L34 was not covered by tests
end

dexp = parse_decapode(quote
A::Form0{X}
B::Form1{X}
C::Form0{X}
D::Form0{X}

B == grad(A)
C == f(A,B)
∂ₜ(A) == C
∂ₜ(D) == C + D
end)

d = SummationDecapode(dexp)

dexpr′ = Term(d)
d′ = SummationDecapode(Term(d))

0 comments on commit a9561a1

Please sign in to comment.