Browse Source

Merge pull request #69 from tylerhanks/catlab_struct_acsets

Update to use struct acsets
pull/75/head
Andrew Baas 2 weeks ago
committed by GitHub
parent
commit
6fc1f2d3d5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .gitignore
  2. 3
      Project.toml
  3. 3
      examples/covid/chime/chime-cset.jl
  4. 2
      examples/covid/coexist/coexist.jl
  5. 2
      examples/enzymes/enzyme_reactions.jl
  6. 32
      src/AlgebraicPetri.jl
  7. 11
      src/BilayerNetworks.jl
  8. 4
      src/ModelComparison.jl
  9. 1
      test/Project.toml
  10. 1
      test/runtests.jl
  11. 5
      test/types.jl

3
.gitignore

@ -18,6 +18,9 @@ docs/build/
docs/site/
docs/src/examples
# Editor/IDE specific ignores
.vscode/
# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static

3
Project.toml

@ -14,7 +14,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
[compat]
AutoHashEquals = "^0.2.0"
Catlab = "0.12.7"
Catlab = "0.13"
LabelledArrays = "^1"
Requires = "^1"
StatsBase = "^0.33"
@ -22,3 +22,4 @@ julia = "1.6"
[extras]
Petri = "4259d249-1051-49fa-8328-3f8ab9391c33"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

3
examples/covid/chime/chime-cset.jl

@ -2,6 +2,7 @@ using AlgebraicPetri
using OrdinaryDiffEq
using Plots
using Catlab.Meta
using Catlab.CategoricalAlgebra
using JSON
import OrdinaryDiffEq: ODEProblem
@ -34,4 +35,4 @@ plot(sol)
## Getting Sharable JSON
sir_cset_string = LabelledReactionNet{String, Int}((:S=>990, :I=>10, :R=>0), (:inf, β_text)=>((:S, :I)=>(:I,:I)), (:rec, γ_text)=>(:I=>:R))
JSON.print(sir_cset_string.tables, 2)
JSON.print(tables(sir_cset_string), 2)

2
examples/covid/coexist/coexist.jl

@ -172,7 +172,7 @@ save_fig(Graph(threeNCoexist_algpetri), "3ncoexist_petri", "svg"); # hide
# We can JSON to convert this Petri net into an
# easily shareable format
JSON.print(threeNCoexist_algpetri.tables)
JSON.print(tables(threeNCoexist_algpetri), 2)
# We can now easily generate a solver for DifferentialEquations.jl
# because we encoded the intitial parameters and rates throughout

2
examples/enzymes/enzyme_reactions.jl

@ -193,7 +193,7 @@ functor(x) = oapply(x, Dict(
:catLsubG=>cat_sub(L,G)));
function enzyme_uwd(enzymes::Array{Symbol}, substrates::Array{Symbol})
rel = RelationDiagram{Symbol}(0)
rel = RelationDiagram(0)
chemicals = vcat(substrates, enzymes)

32
src/AlgebraicPetri.jl

@ -46,8 +46,8 @@ See Catlab.jl documentation for description of the @present syntax.
os::Hom(O,S)
end
const AbstractPetriNet = AbstractACSetType(TheoryPetriNet)
const PetriNet = CSetType(TheoryPetriNet,index=[:it,:is,:ot,:os])
@abstract_acset_type AbstractPetriNet
@acset_type PetriNet(TheoryPetriNet,index=[:it,:is,:ot,:os]) <: AbstractPetriNet
const OpenPetriNetOb, OpenPetriNet = OpenCSetTypes(PetriNet,:S)
""" Open(p::AbstractPetriNet)
@ -284,14 +284,14 @@ end
See Catlab.jl documentation for description of the @present syntax.
"""
@present TheoryLabelledPetriNet <: TheoryPetriNet begin
Name::Data
Name::AttrType
tname::Attr(T, Name)
sname::Attr(S, Name)
end
const AbstractLabelledPetriNet = AbstractACSetType(TheoryLabelledPetriNet)
const LabelledPetriNetUntyped = ACSetType(TheoryLabelledPetriNet, index=[:it,:is,:ot,:os])
@abstract_acset_type AbstractLabelledPetriNet <: AbstractPetriNet
@acset_type LabelledPetriNetUntyped(TheoryLabelledPetriNet, index=[:it,:is,:ot,:os]) <: AbstractLabelledPetriNet
const LabelledPetriNet = LabelledPetriNetUntyped{Symbol}
const OpenLabelledPetriNetObUntyped, OpenLabelledPetriNetUntyped = OpenACSetTypes(LabelledPetriNetUntyped,:S)
const OpenLabelledPetriNetOb, OpenLabelledPetriNet = OpenLabelledPetriNetObUntyped{Symbol}, OpenLabelledPetriNetUntyped{Symbol}
@ -340,19 +340,19 @@ concentrations on states.
See Catlab.jl documentation for description of the @present syntax.
"""
@present TheoryReactionNet <: TheoryPetriNet begin
Rate::Data
Concentration::Data
Rate::AttrType
Concentration::AttrType
rate::Attr(T, Rate)
concentration::Attr(S, Concentration)
end
const AbstractReactionNet = AbstractACSetType(TheoryReactionNet)
const ReactionNet = ACSetType(TheoryReactionNet, index=[:it,:is,:ot,:os])
@abstract_acset_type AbstractReactionNet <: AbstractPetriNet
@acset_type ReactionNet(TheoryReactionNet, index=[:it,:is,:ot,:os]) <: AbstractReactionNet
const OpenReactionNetOb, OpenReactionNet = OpenACSetTypes(ReactionNet,:S)
Open(p::AbstractReactionNet{R,C}) where {R,C} = OpenReactionNet{R,C}(p, map(x->FinFunction([x], ns(p)), 1:ns(p))...)
Open(p::AbstractReactionNet{R,C}, legs...) where {R,C} = OpenReactionNet{R,C}(p, map(l->FinFunction(l, ns(p)), legs)...)
Open(p::ReactionNet{R,C}) where {R,C} = OpenReactionNet{R,C}(p, map(x->FinFunction([x], ns(p)), 1:ns(p))...)
Open(p::ReactionNet{R,C}, legs...) where {R,C} = OpenReactionNet{R,C}(p, map(l->FinFunction(l, ns(p)), legs)...)
Open(n, p::AbstractReactionNet, m) = Open(p, n, m)
""" ReactionNet{R,C}(n, ts::Vararg{Union{Pair,Tuple}}) where {R,C}
@ -395,21 +395,21 @@ rates(p::AbstractReactionNet) = map(t->rate(p, t), 1:nt(p))
See Catlab.jl documentation for description of the @present syntax.
"""
@present TheoryLabelledReactionNet <: TheoryReactionNet begin
Name::Data
Name::AttrType
tname::Attr(T, Name)
sname::Attr(S, Name)
end
const AbstractLabelledReactionNet = AbstractACSetType(TheoryLabelledReactionNet)
const LabelledReactionNetUntyped = ACSetType(TheoryLabelledReactionNet, index=[:it,:is,:ot,:os])
@abstract_acset_type AbstractLabelledReactionNet <: AbstractPetriNet
@acset_type LabelledReactionNetUntyped(TheoryLabelledReactionNet, index=[:it,:is,:ot,:os]) <: AbstractLabelledReactionNet
const LabelledReactionNet{R,C} = LabelledReactionNetUntyped{R,C,Symbol}
const OpenLabelledReactionNetObUntyped, OpenLabelledReactionNetUntyped = OpenACSetTypes(LabelledReactionNetUntyped,:S)
const OpenLabelledReactionNetOb{R,C} = OpenLabelledReactionNetObUntyped{R,C,Symbol}
const OpenLabelledReactionNet{R,C} = OpenLabelledReactionNetUntyped{R,C,Symbol}
Open(p::AbstractLabelledReactionNet{R,C}) where {R,C} = OpenLabelledReactionNet{R,C}(p, map(x->FinFunction([x], ns(p)), 1:ns(p))...)
Open(p::AbstractLabelledReactionNet{R,C}, legs...) where {R,C} = begin
Open(p::LabelledReactionNet{R,C}) where {R,C} = OpenLabelledReactionNet{R,C}(p, map(x->FinFunction([x], ns(p)), 1:ns(p))...)
Open(p::LabelledReactionNet{R,C}, legs...) where {R,C} = begin
s_idx = Dict(sname(p, s)=>s for s in 1:ns(p))
OpenLabelledReactionNet{R,C}(p, map(l->FinFunction(map(i->s_idx[i], l), ns(p)), legs)...)
end

11
src/BilayerNetworks.jl

@ -20,18 +20,19 @@ export ThBilayerNetwork, AbstractBilayerNetwork, BilayerNetwork,
end
@present ThLabelledBilayerNetwork <: ThBilayerNetwork begin
Name::Data
Name::AttrType
parameter::Attr(Box, Name)
variable::Attr(Qin, Name)
tanvar::Attr(Qout, Name)
end
const AbstractBilayerNetwork = AbstractACSetType(ThBilayerNetwork)
const BilayerNetwork = ACSetType(ThBilayerNetwork)
@abstract_acset_type AbstractBilayerNetwork
@acset_type BilayerNetwork(ThBilayerNetwork) <: AbstractBilayerNetwork
const AbstractLabelledBilayerNetwork = AbstractACSetType(ThLabelledBilayerNetwork)
const LabelledBilayerNetwork = ACSetType(ThLabelledBilayerNetwork){Symbol}
@abstract_acset_type AbstractLabelledBilayerNetwork <: AbstractBilayerNetwork
@acset_type LabelledBilayerNetworkUntyped(ThLabelledBilayerNetwork) <: AbstractLabelledBilayerNetwork
const LabelledBilayerNetwork = LabelledBilayerNetworkUntyped{Symbol}
function balance!(bn::AbstractBilayerNetwork)
for t in 1:nparts(bn, :Box)

4
src/ModelComparison.jl

@ -18,8 +18,8 @@ NOTE:
This function does restrict to homomorphisms which preserve the transition
signatures (number of input/output wires).
"""
function petri_homomorphisms(p1::T, p2::T; kw...) where {CD, AD, T <: AbstractACSet{CD,AD}}
results = ACSetTransformation{CD,AD}[]
function petri_homomorphisms(p1::AbstractPetriNet, p2::AbstractPetriNet; kw...)
results = ACSetTransformation[]
sigsTS = Set{Vector{Int64}}()
homomorphisms(PetriNet(p1), PetriNet(p2); kw...) do transform
if all([length(inputs(p1, t)) == length(inputs(p2, transform.components[:T](t))) &&

1
test/Project.toml

@ -4,4 +4,5 @@ Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
Petri = "4259d249-1051-49fa-8328-3f8ab9391c33"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

1
test/runtests.jl

@ -1,6 +1,5 @@
using Test
import Petri
using LabelledArrays
using AlgebraicPetri
using AlgebraicPetri.Epidemiology

5
test/types.jl

@ -1,3 +1,6 @@
using Tables
import Petri
sir_petri = PetriNet(3, ((1, 2), (2, 2)), (2, 3))
sir_lpetri = LabelledPetriNet([:S, :I, :R], :inf=>((:S, :I), (:I, :I)), :rec=>(:I, :R))
sir_rxn = ReactionNet{Number, Int}([990, 10, 0], (.001, ((1, 2)=>(2,2))), (.25, (2=>3)))
@ -70,7 +73,7 @@ open_sir_lrxn = Open([:S,:I], sir_lrxn, [:R])
@test concentrations(sir_lrxn) == LVector(S=990, I=10, R=0)
@test rates(sir_lrxn) == LVector(inf=.001, rec=.25)
@test length(dom(open_sir_rxn).ob.tables.S) == length(dom(open_sir_lrxn).ob.tables.S)
@test length(Tables.rows(tables(dom(open_sir_rxn).ob).S)) == length(Tables.rows(tables(dom(open_sir_lrxn).ob).S))
du = [0.0, 0.0, 0.0]
out = vectorfield(sir_rxn)(du, concentrations(sir_rxn), rates(sir_rxn), 0.01)

Loading…
Cancel
Save