Skip to content

Commit

Permalink
Parse FinFunctions of domain 0
Browse files Browse the repository at this point in the history
  • Loading branch information
lukem12345 committed Oct 31, 2023
1 parent 8ff21ea commit a02baa5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/categorical_algebra/JSONCSetTransformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Inverse to [`parse_json_fin_function`](@ref).
"""
function generate_json_fin_function(F::FinFunction)
OrderedDict{Symbol,Any}(
:dom => dom( F),
:codom => codom( F),
:map => collect(F))
:dom => dom(F),
:codom => codom(F),
:map => collect(F))
end

""" Serialize a FinFunction object to a JSON file.
Expand All @@ -37,8 +37,8 @@ end

function parse_json_fin_function(input::AbstractDict)
FinFunction(
Int.(input["map"]),
input["dom"]["n"],
input["dom"]["n"] != 0 ? Int.(input["map"]) : 1:0,
input["dom"]["n"],
input["codom"]["n"])
end

Expand Down
57 changes: 57 additions & 0 deletions test/categorical_algebra/JSONCSetTransformations.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module TestJSONCSetTransformations
using Test

using Catlab.CategoricalAlgebra, Catlab.Graphs

# FinFunction serialization
###########################
function roundtrip_json_fin_function(f::T) where T <: FinFunction
Expand Down Expand Up @@ -31,3 +36,55 @@ h = path_graph(WeightedGraph{Float64}, 4, E=(weight=[1,2,3],))
α = ACSetTransformation((V=[2,3], E=[2]), g, h)
@test roundtrip_json_acset_transformation(α, WeightedGraph{Float64}) == α

@present SchFalseDecapode(FreeSchema) begin
(Var, TVar, Op1, Op2)::Ob
(Type, Operator)::AttrType
src::Hom(Op1, Var)
tgt::Hom(Op1, Var)
proj1::Hom(Op2, Var)
proj2::Hom(Op2, Var)
res::Hom(Op2, Var)
incl::Hom(TVar, Var)

op1::Attr(Op1, Operator)
op2::Attr(Op2, Operator)
type::Attr(Var, Type)

Name::AttrType
name::Attr(Var, Name)

(Σ, Summand)::Ob
summand::Hom(Summand, Var)
summation::Hom(Summand, Σ)
sum::Hom(Σ, Var)
end

@acset_type FalseDecapode(SchFalseDecapode,
index=[:src, :tgt, :res, :incl, :op1, :op2, :type])

dynamics = @acset FalseDecapode{Symbol,Symbol,Symbol} begin
Var = 2
name = [:Q, :Qᵤ]
type = [:Form0, :Form0]
Op1 = 2
src = [1,1]
tgt = [2,2]
op1 = [:dt,]
TVar = 1
incl = [2]
end
boundaries = @acset FalseDecapode{Symbol,Symbol,Symbol} begin
Var = 1
name = [:Q]
type = [:Form0]
end

boundary_conditions = ACSetTransformation(
(Var=[1],),
boundaries, dynamics)

@test roundtrip_json_acset_transformation(boundary_conditions,
FalseDecapode{Symbol,Symbol,Symbol}()) == boundary_conditions

end

0 comments on commit a02baa5

Please sign in to comment.