Browse Source

Update to use struct acsets

structacsets
Tyler Hanks 2 months ago
parent
commit
9390c4f6fe
  1. 3
      .gitignore
  2. 32
      src/AlgebraicPetri.jl
  3. 11
      src/BilayerNetworks.jl
  4. 4
      src/ModelComparison.jl
  5. 1
      test/Project.toml
  6. 1
      test/runtests.jl
  7. 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

32
src/AlgebraicPetri.jl

@ -45,8 +45,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)
@ -278,14 +278,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}
@ -334,19 +334,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}
@ -389,21 +389,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