Skip to content

Commit 9b69a94

Browse files
committed
CLEANUP: changing tests
1 parent a6d30bf commit 9b69a94

20 files changed

Lines changed: 1236 additions & 253 deletions
Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,33 @@
11
module CatColabInterop
22

3+
import Base: run
4+
using JSON3
35
using MLStyle
46
using Reexport
57

6-
const Maybe{T} = Union{T, Nothing}
7-
8-
struct QualifiedName
9-
segments::Vector{String}
10-
QualifiedName() = new([])
11-
QualifiedName(str::String) = new([str])
12-
end
13-
14-
Base.isempty(name::QualifiedName) = isempty(name.segments)
15-
Base.join(name::QualifiedName) = join(name.segments, ".")
16-
Base.convert(::Type{QualifiedName}, str::String) = QualifiedName(str)
17-
18-
Core.Symbol(name::QualifiedName) = Symbol("$(String(name))")
19-
20-
struct QualifiedLabel
21-
segments::Vector{String}
22-
QualifiedLabel() = new([])
23-
QualifiedLabel(str::String) = new([str])
24-
QualifiedLabel(segments::Vector{String}) = new(segments)
25-
end
26-
27-
# I want to promote the qualified label to Maybe
28-
Core.String(name::QualifiedLabel) = join(name)
29-
Core.Symbol(name::QualifiedLabel) = Symbol("$(String(name))")
30-
31-
Base.isempty(name::QualifiedLabel) = isempty(name.segments)
32-
Base.join(name::QualifiedLabel) = join(name.segments, ".")
33-
34-
Base.convert(::Type{String}, name::QualifiedLabel) = join(name)
35-
Base.convert(::Type{QualifiedLabel}, data::T) where T<:AbstractVector = QualifiedLabel(String.(data))
36-
37-
38-
398
# this code tracks integrations and allows for basic theory/model-building code to dispatch from it.
409
# the intent is that this is an interface for AlgebraicJulia code to interoperate with CatColab
4110
abstract type AlgebraicJuliaIntegration end
4211

43-
"""
44-
Functions to build a dictionary associating ids in the theory to elements in the model
45-
"""
46-
function to_model end
47-
export to_model
48-
49-
abstract type AbstractAnalysis{T<:AlgebraicJuliaIntegration} end
50-
51-
# an analysis is something that we run
52-
function run(::AbstractAnalysis{T}) where T end
12+
#= These files are responsible for parsing the model and diagram in the CCL payload =#
13+
include("qualified_name.jl")
14+
include("model.jl")
15+
include("diagram.jl")
16+
include("payload.jl") # payload and analysis are here
5317

5418
struct ImplError <: Exception
5519
name::String
5620
end
5721
export ImplError
58-
5922
Base.showerror(io::IO, e::ImplError) = print(io, "$(e.name) not implemented")
6023

61-
# utility
62-
include("result.jl")
63-
64-
# kernel
65-
include("kernel/kernel_management.jl")
66-
include("kernel/kernel_support.jl")
67-
68-
# ccl
69-
include("model.jl")
70-
include("diagram.jl")
71-
include("payload.jl")
72-
# this is actually the analysis
73-
24+
# Kernel utilities
25+
include("kernel/KernelUtility.jl")
7426

27+
#= The Decapodes service contains an analysis =#
7528
include("decapodes-service/DecapodesService.jl")
7629

30+
@reexport using .KernelUtility
7731
@reexport using .DecapodesService
7832

7933
end

packages/algjulia-interop/src/decapodes-service/DecapodesService.jl

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,37 @@ using Distributions # for initial conditions
1717
# meshing
1818
using CoordRefSystems
1919
using GeometryBasics: Point2, Point3
20-
Point3D = Point3{Float64};
20+
Point3D = Point3{Float64}
2121

2222
# simulation
2323
using OrdinaryDiffEq
2424

2525
using ..CatColabInterop
2626
using ..CatColabInterop: AlgebraicJuliaIntegration, AbstractDiagram, AbstractAnalysis
27-
import ..CatColabInterop: Model, to_model, ObGenerator, MorGenerator, DiagramObGenerator, DiagramMorGenerator
27+
import ..CatColabInterop: Model, ObGenerator, MorGenerator, DiagramObGenerator, DiagramMorGenerator
2828

2929
# necessary to export
30-
export infer_types!, evalsim, default_dec_generate, default_dec_matrix_generate,
31-
DiagonalHodge, ComponentArray
30+
export infer_types!, evalsim, default_dec_generate, default_dec_matrix_generate, DiagonalHodge, ComponentArray
3231

3332
struct ThDecapode <: AlgebraicJuliaIntegration end
3433
export ThDecapode
3534

36-
struct ObTag end
37-
struct HomTag end
38-
39-
# # funcitons for geometry and initial conditions
35+
# functions for geometry and initial conditions
4036
include("geometry.jl")
41-
include("model.jl") ## model-building
42-
include("diagram.jl") ## diagram-building
43-
include("analysis/Analysis.jl")
37+
38+
# responsible for constructing a valid model
39+
include("model.jl")
40+
41+
# helper functions for Navier-Stokes
42+
include("ns_helper.jl")
43+
44+
# constructing initial conditions
45+
include("initial_conditions.jl")
46+
47+
# parses a payload to a valid analysis
48+
include("parse.jl")
49+
50+
# executes the analysis
51+
include("execute.jl")
4452

4553
end

packages/algjulia-interop/src/decapodes-service/diagram.jl

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/algjulia-interop/src/decapodes-service/analysis/simulation.jl renamed to packages/algjulia-interop/src/decapodes-service/execute.jl

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
""" DecapodeSimulation
2+
3+
This analysis contains the data necessary to execute a simulation.
4+
"""
15
struct DecapodeSimulation <: AbstractAnalysis{ThDecapode}
26
diagram::ModelDiagramPresentation{ThDecapode}
37
model::Model{ThDecapode}
@@ -10,12 +14,9 @@ function DecapodeSimulation(path::String; hodge=GeometricHodge())
1014
DecapodeSimulation(payload)
1115
end
1216

13-
#=
14-
Simulation: Payload => Analysis
15-
=#
1617
function DecapodeSimulation(payload::Payload; hodge=GeometricHodge())
1718
pode = DecapodeDiagram(payload)
18-
plotVars = @match payload.data[:plotVariables] begin
19+
plotVars = @match payload[:plotVariables] begin
1920
vars::AbstractArray => Dict{String, Bool}(key => key vars for key keys(pode.vars))
2021
vars => Dict{String, Bool}( "$key" => var for (key, var) in vars)
2122
end
@@ -46,11 +47,12 @@ function DecapodeSimulation(payload::Payload; hodge=GeometricHodge())
4647
return (args...) -> op(args...)
4748
end
4849
#
49-
u0 = initial_conditions(payload.data[:initialConditions], geometry, uuid2symb)
50+
u0 = initial_conditions(payload[:initialConditions], geometry, uuid2symb)
5051

5152
# reversing `uuid2symb` into `symbol => uuid.` we need this to reassociate the var to its UUID
5253
symb2uuid = Dict([v => k for (k,v) in pairs(uuid2symb)])
5354

55+
# TODO what is anons doing here?
5456
anons = Dict{Symbol, Any}()
5557
data = Dict(
5658
:pode => pode.pode,
@@ -60,17 +62,23 @@ function DecapodeSimulation(payload::Payload; hodge=GeometricHodge())
6062
:init => u0,
6163
:generate => sys_generate,
6264
:uuiddict => symb2uuid,
63-
:duration => payload.data[:duration])
65+
:duration => payload[:duration])
6466
return DecapodeSimulation(payload.diagram, payload.model, data)
6567
end
6668

67-
Base.show(io::IO, system::DecapodeSimulation) = println(io, system.data[:pode])
69+
Base.show(io::IO, system::DecapodeSimulation) = println(io, system[:pode])
70+
71+
Base.getindex(system::DecapodeSimulation, field::Symbol) = system.data[field]
72+
73+
points(system::DecapodeSimulation) = collect(values(system[:geometry].dualmesh.subparts.point.m))
74+
indexing_bounds(system::DecapodeSimulation) = indexing_bounds(system[:geometry].domain)
6875

69-
points(system::DecapodeSimulation) = collect(values(system.data[:geometry].dualmesh.subparts.point.m))
70-
indexing_bounds(system::DecapodeSimulation) = indexing_bounds(system.data[:geometry].domain)
76+
import Base: run
7177

72-
function Base.run(fm, u0, t0, constparam)
73-
prob = ODEProblem(fm, u0, (0, t0), constparam)
78+
"""
79+
"""
80+
function Base.run(fm, sim::DecapodeSimulation, constparam)
81+
prob = ODEProblem(fm, sim[:init], sim[:duration], constparam)
7482
solve(prob, Tsit5(), saveat=0.01)
7583
end
7684
export run

packages/algjulia-interop/src/decapodes-service/analysis/initial_conditions.jl renamed to packages/algjulia-interop/src/decapodes-service/initial_conditions.jl

File renamed without changes.

packages/algjulia-interop/src/decapodes-service/model.jl

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
1-
# Build the model
2-
3-
export Model
4-
5-
# """
6-
# A model for the Decapodes integration is the same as the default Model method.
7-
# A dictionary mapping UUID strings with ModelElements is instantiated.
8-
# """
9-
# Model(::ThDecapode) = Model{ThDecapode}(Dict{String, ModelElement}())
1+
#= Build the model
102
3+
A model for the Decapodes integration is the same as the default Model method.
4+
A dictionary mapping UUID strings with ModelElements is instantiated.
5+
=#
116
function ObGenerator(::ThDecapode, obgen::AbstractDict)
127
ObGenerator(obgen[:id], ob_name(ThDecapode(), obgen[:label]), obgen[:obType])
138
end
149
export ObGenerator
1510

16-
# XXX the use of an `only` here means we're being hostile to multiarrows
17-
function MorGenerator(::ThDecapode, ob_generators::Vector{ObGenerator}, morgen::AbstractDict)
18-
dom = only(filter(ob -> ob.id == morgen[:dom][:content], ob_generators))
19-
cod = only(filter(ob -> ob.id == morgen[:cod][:content], ob_generators))
20-
MorGenerator(morgen[:id], mor_name(ThDecapode(), morgen[:label]), morgen[:morType], dom, cod)
21-
end
22-
export MorGenerator
23-
2411
""" Helper function to convert CatColab values (Obs) in Decapodes """
25-
function ob_name(model::ThDecapode, name::String)
12+
function ob_name(model::ThDecapode, name::String)
2613
@match lowercase(name) begin
2714
"0-form" => :Form0
2815
"1-form" => :Form1
@@ -36,11 +23,20 @@ function ob_name(model::ThDecapode, name::String)
3623
x => throw(ImplError(x))
3724
end
3825
end
39-
ob_name(model::ThDecapode, name::AbstractVector) =
40-
ob_name(model, join(String.(name), ""))
26+
export ob_name
27+
28+
ob_name(model::ThDecapode, name::AbstractVector) = ob_name(model, join(String.(name), ""))
29+
30+
# XXX the use of an `only` here means we're being hostile to multiarrows
31+
function MorGenerator(::ThDecapode, ob_generators::Vector{ObGenerator}, morgen::AbstractDict)
32+
dom = only(filter(ob -> ob.id == morgen[:dom][:content], ob_generators))
33+
cod = only(filter(ob -> ob.id == morgen[:cod][:content], ob_generators))
34+
MorGenerator(morgen[:id], mor_name(ThDecapode(), morgen[:label]), morgen[:morType], dom, cod)
35+
end
36+
export MorGenerator
4137

4238
""" Helper function to convert CatColab values (Homs) in Decapodes """
43-
function mor_name(model::ThDecapode, name::String)
39+
function mor_name(model::ThDecapode, name::String)
4440
@match replace(name," " => "") begin
4541
"∂t" || "∂ₜ" => :∂ₜ
4642
"Δ" =>
@@ -58,6 +54,7 @@ function mor_name(model::ThDecapode, name::String)
5854
x => throw(ImplError(x))
5955
end
6056
end
57+
export mor_name
6158

6259
mor_name(model::ThDecapode, name::AbstractVector) = mor_name(model, join(String.(name), ""))
6360

packages/algjulia-interop/src/decapodes-service/analysis/ns_helper.jl renamed to packages/algjulia-interop/src/decapodes-service/ns_helper.jl

File renamed without changes.

packages/algjulia-interop/src/decapodes-service/analysis/Analysis.jl renamed to packages/algjulia-interop/src/decapodes-service/parse.jl

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
include("ns_helper.jl")
2-
include("initial_conditions.jl")
1+
2+
function uuid_to_symb(decapode::SummationDecapode, vars::Dict{String, Int})
3+
Dict([key => (subpart(decapode, vars[key], :name)) for key keys(vars)])
4+
end
35

46
#=
57
We produce a ModelDiagramPresentation and Analysis data from the CCL payload.
@@ -56,31 +58,6 @@ function DecapodeDiagram(payload::Payload)
5658
return pode
5759
end
5860

59-
# TODO move to diagram
60-
function Base.nameof(model::Model, ob::DiagramObGenerator)
61-
if isnothing(ob.over)
62-
:no_name
63-
else
64-
nameof(model.ob_generators[ob.over.content])
65-
end
66-
end
67-
68-
function Base.nameof(model::Model, mor::DiagramMorGenerator)
69-
if isnothing(mor.over)
70-
:no_name
71-
else
72-
nameof(model.mor_generators[mor.over.content])
73-
end
74-
end
75-
76-
function Base.nameof(model::Model, content::AbstractDict)
77-
if isnothing(content[:over])
78-
:no_name
79-
else
80-
Symbol(model.data[content[:over][:content]].name)
81-
end
82-
end
83-
8461
# endpoint being `dom` or `codom`
8562
function check_endpoint!(diagram::DecapodeDiagram, endpoint::DiagramObGenerator)
8663
if haskey(diagram.vars, endpoint.id)
@@ -99,4 +76,3 @@ function check_endpoint!(diagram::DecapodeDiagram, endpoint::DiagramObGenerator)
9976
end
10077
end
10178

102-
include("simulation.jl")

packages/algjulia-interop/src/diagram.jl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ function DiagramObGenerator(data::AbstractDict)
1717
end
1818

1919
Base.nameof(ob::DiagramObGenerator) = ob.label
20-
21-
Base.getindex(obs::Vector{MorGenerator}, id::String) =
22-
only(filter(ob -> ob.id == id, obs))
20+
function Base.nameof(model::Model, ob::DiagramObGenerator)
21+
if isnothing(ob.over)
22+
:no_name
23+
else
24+
nameof(model.ob_generators[ob.over.content])
25+
end
26+
end
27+
Base.getindex(obs::Vector{MorGenerator}, id::String) = only(filter(ob -> ob.id == id, obs))
2328

2429
""" Struct defining an morphism generator """
2530
struct DiagramMorGenerator
@@ -40,10 +45,14 @@ function DiagramMorGenerator(data::AbstractDict; obs::Vector{DiagramObGenerator}
4045
end
4146

4247
Base.nameof(mor::DiagramMorGenerator) = mor.label
43-
44-
Base.getindex(mors::Vector{MorGenerator}, id::String) =
45-
only(filter(mor -> mor.id == id, mors))
46-
48+
function Base.nameof(model::Model, mor::DiagramMorGenerator)
49+
if isnothing(mor.over)
50+
:no_name
51+
else
52+
nameof(model.mor_generators[mor.over.content])
53+
end
54+
end
55+
Base.getindex(mors::Vector{MorGenerator}, id::String) = only(filter(mor -> mor.id == id, mors))
4756

4857
""" Struct wrapping a dictionary """
4958
struct ModelDiagramPresentation{T<:AlgebraicJuliaIntegration}
@@ -54,7 +63,7 @@ struct ModelDiagramPresentation{T<:AlgebraicJuliaIntegration}
5463
end
5564
export ModelDiagramPresentation
5665

57-
function ModelDiagramPresentation(::T, data::JSON3.Object) where T
66+
function ModelDiagramPresentation(::T, data::AbstractDict) where T
5867
ob_generators = DiagramObGenerator.(data[:obGenerators])
5968
mor_generators = DiagramMorGenerator.(data[:morGenerators]; obs=ob_generators)
6069
ModelDiagramPresentation(T(), ob_generators, mor_generators)

0 commit comments

Comments
 (0)