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

Fix Decapodes for DiagX Operator Types #277

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/bsh/budyko_sellers_halfar.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ We can perform type inference to determine what kind of differential form each o

``` @example DEC
budyko_sellers_halfar = expand_operators(budyko_sellers_halfar)
infer_types!(budyko_sellers_halfar, op1_inf_rules_1D, op2_inf_rules_1D)
resolve_overloads!(budyko_sellers_halfar, op1_res_rules_1D, op2_res_rules_1D)
infer_types!(budyko_sellers_halfar, dim=1)
resolve_overloads!(budyko_sellers_halfar, dim=1)
to_graphviz(budyko_sellers_halfar)
```

Expand Down
4 changes: 2 additions & 2 deletions docs/src/ice_dynamics/ice_dynamics.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ To interpret our composed Decapode, we need to specify what Discrete Exterior Ca

``` @example DEC
ice_dynamics1D = expand_operators(ice_dynamics)
infer_types!(ice_dynamics1D, op1_inf_rules_1D, op2_inf_rules_1D)
resolve_overloads!(ice_dynamics1D, op1_res_rules_1D, op2_res_rules_1D)
infer_types!(ice_dynamics1D, dim=1)
resolve_overloads!(ice_dynamics1D, dim=1)

to_graphviz(ice_dynamics1D)
```
Expand Down
1 change: 1 addition & 0 deletions docs/src/klausmeier/klausmeier.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function generate(sd, my_symbol; hodge=DiagonalHodge())
:Δ => x -> begin
lap_mat * x
end
_ => default_dec_matrix_generate(sd, my_symbol, hodge)
end
return (args...) -> op(args...)
end
Expand Down
8 changes: 4 additions & 4 deletions docs/src/poiseuille/poiseuille.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Poise = @decapode begin
end

Poise = expand_operators(Poise)
infer_types!(Poise, op1_inf_rules_1D, op2_inf_rules_1D)
resolve_overloads!(Poise, op1_res_rules_1D, op2_res_rules_1D)
infer_types!(Poise, dim=1)
resolve_overloads!(Poise, dim=1)
to_graphviz(Poise)
```

Expand Down Expand Up @@ -210,8 +210,8 @@ Poise = @decapode begin
end

Poise = expand_operators(Poise)
infer_types!(Poise, op1_inf_rules_1D, op2_inf_rules_1D)
resolve_overloads!(Poise, op1_res_rules_1D, op2_res_rules_1D)
infer_types!(Poise, dim=1)
resolve_overloads!(Poise, dim=1)
to_graphviz(Poise)
```

Expand Down
18 changes: 9 additions & 9 deletions examples/climate/budyko_sellers.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Import Dependencies
# Import Dependencies

# AlgebraicJulia Dependencies
using Catlab
Expand All @@ -20,7 +20,7 @@ using JLD2
using GeometryBasics: Point2
Point2D = Point2{Float64}

# Define the model
# Define the model

# ϕ := Latitude
# Tₛ(ϕ,t) := Surface temperature
Expand All @@ -35,7 +35,7 @@ energy_balance = @decapode begin
(Tₛ, ASR, OLR, HT)::Form0
(C)::Constant

Tₛ̇ == ∂ₜ(Tₛ)
Tₛ̇ == ∂ₜ(Tₛ)

Tₛ̇ == (ASR - OLR + HT) ./ C
end
Expand Down Expand Up @@ -94,10 +94,10 @@ budyko_sellers_cospan = oapply(budyko_sellers_composition_diagram,
budyko_sellers = apex(budyko_sellers_cospan)
to_graphviz(budyko_sellers)

infer_types!(budyko_sellers, op1_inf_rules_1D, op2_inf_rules_1D)
infer_types!(budyko_sellers, dim = 1)
to_graphviz(budyko_sellers)

resolve_overloads!(budyko_sellers, op1_res_rules_1D, op2_res_rules_1D)
resolve_overloads!(budyko_sellers, dim = 1)
to_graphviz(budyko_sellers)

# Demonstrate storing as JSON
Expand All @@ -116,7 +116,7 @@ orient!(s′)
s = EmbeddedDeltaDualComplex1D{Bool, Float64, Point2D}(s′)
subdivide_duals!(s, Circumcenter())

# Define constants, parameters, and initial conditions
# Define constants, parameters, and initial conditions

# This is a primal 0-form, with values at vertices.
cosϕᵖ = map(x -> cos(x[1]), point(s′))
Expand Down Expand Up @@ -162,13 +162,13 @@ constants_and_parameters = (
cosϕᵖ = cosϕᵖ,
diffusion_cosϕᵈ = cosϕᵈ)

# Define how symbols map to Julia functions
# Define how symbols map to Julia functions

# In this example, all operators come from the Discrete Exterior Calculus module
# from CombinatorialSpaces.
function generate(sd, my_symbol; hodge=GeometricHodge()) end

# Generate simulation
# Generate simulation

sim = eval(gensim(budyko_sellers, dimension=1))
fₘ = sim(s, generate)
Expand All @@ -193,7 +193,7 @@ soln = solve(prob, Tsit5())

soln = solve(prob, FBDF())

# Visualize
# Visualize

lines(map(x -> x[1], point(s′)), soln(0.0).Tₛ)
lines(map(x -> x[1], point(s′)), soln(tₑ).Tₛ)
Expand Down
14 changes: 7 additions & 7 deletions examples/climate/budyko_sellers_halfar.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Import Dependencies
# Import Dependencies

# AlgebraicJulia Dependencies
using Catlab
Expand All @@ -19,7 +19,7 @@ using GeometryBasics: Point2
using ComponentArray
Point2D = Point2{Float64}

# Import prior models
# Import prior models
## If the Budyko-Sellers and Halfar models are not already created, they can be
## with these scripts:
## include("budyko_sellers.jl")
Expand Down Expand Up @@ -62,10 +62,10 @@ budyko_sellers_halfar = apex(budyko_sellers_halfar_cospan)
to_graphviz(budyko_sellers_halfar)

budyko_sellers_halfar = expand_operators(budyko_sellers_halfar)
infer_types!(budyko_sellers_halfar, op1_inf_rules_1D, op2_inf_rules_1D)
infer_types!(budyko_sellers_halfar, dim=1)
to_graphviz(budyko_sellers_halfar)

resolve_overloads!(budyko_sellers_halfar, op1_res_rules_1D, op2_res_rules_1D)
resolve_overloads!(budyko_sellers_halfar, dim=1)
to_graphviz(budyko_sellers_halfar)

## Define the mesh
Expand Down Expand Up @@ -170,12 +170,12 @@ function generate(sd, my_symbol; hodge=GeometricHodge())
return (args...) -> op(args...)
end

## Generate simulation
## Generate simulation

sim = eval(gensim(budyko_sellers_halfar, dimension=1))
fₘ = sim(s, generate)

## Run simulation
## Run simulation

tₑ = 1e6
#tₑ = 5e13
Expand All @@ -199,7 +199,7 @@ extrema(soln(tₑ).halfar_h)

@save "budyko_sellers_halfar.jld2" soln

# Visualize
# Visualize

lines(map(x -> x[1], point(s′)), soln(0.0).Tₛ)
lines(map(x -> x[1], point(s′)), soln(tₑ).Tₛ)
Expand Down
4 changes: 2 additions & 2 deletions examples/diff_adv/burger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ Burger = apex(Burger_cospan)
# Specify semantics of the 1D DEC.
# i.e. Declare these dynamics are happening on a line.
Burger = expand_operators(Burger)
infer_types!(Burger, op1_inf_rules_1D, op2_inf_rules_1D)
resolve_overloads!(Burger, op1_res_rules_1D, op2_res_rules_1D)
infer_types!(Burger, dim=1)
resolve_overloads!(Burger, dim=1)

to_graphviz(Burger)

Expand Down
17 changes: 6 additions & 11 deletions src/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -587,13 +587,8 @@ end
A combined `infer_types` and `resolve_overloads` pipeline with default DEC rules.
"""
function infer_overload_compiler!(d::SummationDecapode, dimension::Int)
if dimension == 1
infer_types!(d, op1_inf_rules_1D, op2_inf_rules_1D)
resolve_overloads!(d, op1_res_rules_1D, op2_res_rules_1D)
elseif dimension == 2
infer_types!(d, op1_inf_rules_2D, op2_inf_rules_2D)
resolve_overloads!(d, op1_res_rules_2D, op2_res_rules_2D)
end
infer_types!(d, dim = dimension)
resolve_overloads!(d, dim = dimension)
end

"""
Expand Down Expand Up @@ -681,12 +676,12 @@ Base.showerror(io::IO, e::UnsupportedStateeltypeException) = print(io, "Decapode
"""
gensim(user_d::SummationDecapode, input_vars::Vector{Symbol}; dimension::Int=2, stateeltype::DataType = Float64, code_target::AbstractGenerationTarget = CPUTarget(), preallocate::Bool = true)

Generates the entire code body for the simulation function. The returned simulation function can then be combined with a mesh, provided by `CombinatorialSpaces`, and a function describing symbol
Generates the entire code body for the simulation function. The returned simulation function can then be combined with a mesh, provided by `CombinatorialSpaces`, and a function describing symbol
to operator mappings to return a simulator that can be used to solve the represented equations given initial conditions.

**Arguments:**
`user_d`: The user passed Decapode for which simulation code will be generated. (This is not modified)

`user_d`: The user passed Decapode for which simulation code will be generated. (This is not modified)

`input_vars` is the collection of variables whose values are known at the beginning of the simulation. (Defaults to all state variables and literals in the Decapode)

Expand Down
9 changes: 4 additions & 5 deletions test/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ end

Tₛ̇ == (ASR - OLR + HT) ./ C
end
infer_types!(budyko_sellers, op1_inf_rules_1D, op2_inf_rules_1D)
resolve_overloads!(budyko_sellers, op1_res_rules_1D, op2_res_rules_1D)
infer_types!(budyko_sellers, dim=1)
resolve_overloads!(budyko_sellers, dim=1)

# This test ensures that the next one does not break, since it depends on
# arbitrary internal variable naming.
Expand Down Expand Up @@ -482,7 +482,7 @@ end
constants_and_parameters = ()
f(du, u, constants_and_parameters, 0)

@test du.A == d(0, earth) * A
@test du.A == CombinatorialSpaces.DiscreteExteriorCalculus.d(0, earth) * A

# Testing no contraction of unallowed operators
no_unallowed = @decapode begin
Expand Down Expand Up @@ -510,7 +510,7 @@ end
constants_and_parameters = ()
f(du, u, constants_and_parameters, 0)

@test du.A == d(0, earth) * 20 * A
@test du.A == CombinatorialSpaces.DiscreteExteriorCalculus.d(0, earth) * 20 * A

# Testing wedge 01 operators function
wedges01 = @decapode begin
Expand Down Expand Up @@ -829,4 +829,3 @@ haystack = string(gensim(LargeSum))
@test occursin(needle, haystack)

end

Loading