Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

induced subnet #119

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

induced subnet #119

wants to merge 5 commits into from

Conversation

slwu89
Copy link
Member

@slwu89 slwu89 commented Mar 28, 2023

Sometimes when dealing with big petri nets it's useful to grab the "induced subnet", that is, given some transition(s) we grab the net consisting of the transition(s), and the arcs and places incident to them. The name comes from the induced_subgraph method in Catlab.BasicGraphs.

@slwu89 slwu89 marked this pull request as ready for review March 28, 2023 01:51
Copy link
Member

@jpfairbanks jpfairbanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It think there is a much slicker way to do this with the logic of subobjects.

https://blog.algebraicjulia.org/post/2021/09/cset-graphs-4/#using-the-logic-of-subgraphs

if A is the Petri net with only the transitions in tt, then \neg(\tilde(A)) is the induced sub-petri-net that you want.

output_places = [subpart(p, output_i, :os) for output_i in output_arcs]

subnet = T()
copy_parts!(subnet, p, T=t, I=vcat(input_arcs...), O=vcat(output_arcs...), S=union(input_places..., output_places...))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@epatters, this is done with the subpart and incident API. Would you prefer if this used the Topos logic operations? Is not(negation(tt)) equivalent to this formulation?

@slwu89
Copy link
Member Author

slwu89 commented Mar 28, 2023

It think there is a much slicker way to do this with the logic of subobjects.

https://blog.algebraicjulia.org/post/2021/09/cset-graphs-4/#using-the-logic-of-subgraphs

if A is the Petri net with only the transitions in tt, then \neg(\tilde(A)) is the induced sub-petri-net that you want.

If there's a slicker way to do it, let's just abandon the more complex approach and do that. I'll read the blog post tonight.

@slwu89
Copy link
Member Author

slwu89 commented Mar 29, 2023

@jpfairbanks not sure if I'm using the subobject interface wrong, I'm not getting the subnet I expected (i.e. the one with 2 places and 1 transition)

julia> sir_petri = PetriNet(3, ((1, 2), (2, 2)), (2, 3))
PetriNet with elements T = 1:2, S = 1:3, I = 1:3, O = 1:3
┌───┬────┬────┐
│ I │ it │ is │
├───┼────┼────┤
│ 111 │
│ 212 │
│ 322 │
└───┴────┴────┘
┌───┬────┬────┐
│ O │ ot │ os │
├───┼────┼────┤
│ 112 │
│ 212 │
│ 323 │
└───┴────┴────┘


julia> dom(hom(¬(~Subobject(sir_petri, T=[1]))))
PetriNet with elements T = 1:0, S = 1:0, I = 1:0, O = 1:0

@slwu89
Copy link
Member Author

slwu89 commented Aug 25, 2023

@mehalter I think I've addressed (finally) James' comments locally but I'm not sure how to best pull the updates from main on AlgJulia into this branch on my fork. Can you help give me some advice? I've already messed it up twice and reverted.

@mehalter mehalter changed the base branch from master to main August 28, 2023 12:50
@mehalter mehalter force-pushed the slwu89/subnet branch 2 times, most recently from 3e26195 to 46f5943 Compare August 28, 2023 13:00
@mehalter
Copy link
Member

@slwu89 sure, have you pushed these local changes here? Could you push it here building on these changes and then I can help you out with the rebase. Or, does this PR already contain the new changes to address the requests?

@slwu89
Copy link
Member Author

slwu89 commented Aug 29, 2023

Thanks @mehalter, I ended up just rebasing this branch onto main to grab the latest changes. This branch was made pre Catlab v0.15 so it had the old using for each module. I'll go ahead and make changes to address @jpfairbanks's comments from here, which will take a bit more time. Using the subobject interface in lieu of the "imperative" interface is giving some errors on certain types of nets, so I'll need to look into that when I have time.

@mehalter
Copy link
Member

Awesome @slwu89 ! One recommendation is you should reword the first commit since it's not actually doing a rebase. It's adding the initial implementation of induced subnet

@slwu89
Copy link
Member Author

slwu89 commented Aug 29, 2023

Whoops, thanks. Still not gittin it.

@slwu89 slwu89 requested a review from jpfairbanks May 4, 2024 23:25

function induced_subnet(p::T, t::AbstractVector{Int}) where {T <: AbstractPetriNet}
subnet = Subobject(p, T=t)
return dom(hom(~(¬subnet)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return the Subobject and have the caller call dom if they want just the domain?

We could add overloads for Subobject -> PetriNet so that they can call PetriNet(induced_subnet(g)) if they don't want the morphism?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpfairbanks those all sound like good ideas, but I don't know how we'd want to implement the overload for PetriNet to pull the domain subobject out. PetriNet is a specific type made by calling the @acset_type macro, it's plausible a user would want to get the domain petri net out of a subobject where the petri nets in question are of a different type, like a labelled petri net. How should the overload work in that case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would T(p::Subobject{T}) where T<:AbstractPetriNet = dom(p) work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants