Skip to content

Commit

Permalink
BUG: Don't assume colimit preserves order of states in oapply_typed.
Browse files Browse the repository at this point in the history
  • Loading branch information
epatters committed Jul 10, 2023
1 parent 0afbc1a commit 048b452
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/TypedPetri.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ colimiting the transitions together, and returns the ACSetTransformation
from that Petri net to the type system.
"""
function oapply_typed(type_system::LabelledPetriNet, uwd, tnames::Vector{Symbol})
junction(uwd, outer=true) == junctions(uwd) ||
error("Outer ports of UWD must coincide with junctions in `oapply_typed`")
type_system′ = PetriNet(type_system)
prim_cospan_data = Dict(
tname(type_system, t) => prim_cospan(type_system′, t)
Expand All @@ -74,12 +76,16 @@ function oapply_typed(type_system::LabelledPetriNet, uwd, tnames::Vector{Symbol}
colim,
Multicospan(
type_system′,
[prim_cospan_data[subpart(uwd, b, :name)][2] for b in 1:nboxes(uwd)]
[prim_cospan_data[uwd[b, :name]][2] for b in boxes(uwd)]
)
)
labelled_petri = LabelledPetriNet(unlabelled_map.dom, uwd[:variable], tnames)
state_labels = Vector{Symbol}(undef, njunctions(uwd))
for (j, leg) in zip(junctions(uwd), legs(petri))
state_labels[only(collect(leg[:S]))] = uwd[j, :variable]
end
labelled_petri = LabelledPetriNet(dom(unlabelled_map), state_labels, tnames)
LooseACSetTransformation(
unlabelled_map.components,
components(unlabelled_map),
(Name=x->nothing,),
labelled_petri,
type_system
Expand Down
4 changes: 2 additions & 2 deletions test/TypedPetri.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const infectious_ontology = LabelledPetriNet(
:strata=>(:Pop=>:Pop)
)

sird_uwd = @relation () where (S::Pop, I::Pop, R::Pop, D::Pop) begin
sird_uwd = @relation (S,I,R,D) where (S::Pop, I::Pop, R::Pop, D::Pop) begin
infect(S,I,I,I) # inf
disease(I,R) # recover
disease(I,D) # die
Expand All @@ -35,7 +35,7 @@ typed_sird = add_params(

# SIRD-with-quarantine model.

quarantine_uwd = @relation () where (Q::Pop, NQ::Pop) begin
quarantine_uwd = @relation (Q,NQ) where (Q::Pop, NQ::Pop) begin
strata(Q,NQ) # enter quarantine
strata(NQ,Q) # exit quarantine
end
Expand Down

0 comments on commit 048b452

Please sign in to comment.