AlgebraicJulia / ASKEM-demos

6 stars 1 forks source link

JSON => MTK pipeline #15

Closed JeffBezanson closed 1 year ago

JeffBezanson commented 1 year ago

I'm trying to run the MTK integration example, but starting with the JSON representation of the model. Here are some things I've tried:

julia> sir = read_json_acset(LabelledReactionNet{Float64,Float64}, "data/SIR.json");

julia> apex(oapply_epi(sir))
ERROR: MethodError: no method matching oapply(::LabelledReactionNet{Float64, Float64}, ::Dict{Symbol, StructuredMulticospan{Catlab.CategoricalAlgebra.StructuredCospans.DiscreteACSet{AnonACSet{TypeLevelBasicSchema{Symbol, Tuple{:S}, Tuple{}, Tuple{:Name}, Tuple{(:sname, :S, :Name)}}, Tuple{Symbol}, Catlab.LVectors.LVector{Int64, (:S,)}, NamedTuple{(:sname,), Tuple{Catlab.ColumnImplementations.DenseAttr{Symbol}}}}, LabelledPetriNet}}})

julia> bnsir2 = LabelledBilayerNetwork();

julia> migrate!(bnsir2, sir)
ERROR: Length of object map Dict(:Wa => :O, :Win => :I, :Box => :T, :Qin => :S, :Qout => :S, :Wn => :I) does not match domain FinCat(Presentation{ThSchema, Symbol}(Catlab.Theories.FreeSchema, (Ob = Catlab.Theories.FreeSchema.Ob{:generator}[Qin, Qout, Win, Wn, Wa, Box], Hom = Catlab.Theories.FreeSchema.Hom{:generator}[arg, call, influx, infusion, efflux, effusion], AttrType = Catlab.Theories.FreeSchema.AttrType{:generator}[Name], Attr = Catlab.Theories.FreeSchema.Attr{:generator}[parameter, variable, tanvar]), Dict(:arg => (:Hom => 1), :tanvar => (:Attr => 3), :Box => (:Ob => 6), :Wn => (:Ob => 4), :parameter => (:Attr => 1), :influx => (:Hom => 3), :Qin => (:Ob => 1), :Qout => (:Ob => 2), :Wa => (:Ob => 5), :variable => (:Attr => 2), :efflux => (:Hom => 5), :effusion => (:Hom => 6), :call => (:Hom => 2), :Name => (:AttrType => 1), :infusion => (:Hom => 4), :Win => (:Ob => 3)), Pair[]))

Any help appreciated.

p-stokes commented 1 year ago

Hi Jeff. The sir in petri.jl of the demo is an UntypedUnnamedRelationDiagram, not a LabelledReactionNet. The call to apex(oapply_epi(sir)) takes that diagram and forms a LabelledPetriNet, psir, which can then be migrated into a LabelledBilayerNetwork. In your case, the sir being read in from the JSON is a LabelledReactionNet, so the apex(oapply_epi(sir)) is not appropriate. But it does need to be converted into a LabelledPetriNet. This can be done simply by calling LabelledPetriNet() on it, which strips away the concentration and rate information. So the following set of lines should work:

sir_lrxn = read_json_acset(LabelledReactionNet{Float64,Float64}, "data/SIR.json");
sir_lpn = LabelledPetriNet(sir_lrxn);
sir_lbln = LabelledBilayerNetwork();
migrate!(sir_lbln,sir_lpn);
JeffBezanson commented 1 year ago

Thank you.