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

Meta-issue: Use MetaGraphsNext.jl for graphs with node and edge IDs #732

Closed
SouthEndMusic opened this issue Nov 3, 2023 · 5 comments
Closed
Labels
allocation Allocation layer

Comments

@SouthEndMusic
Copy link
Collaborator

See here for a motivating discussion.

@github-project-automation github-project-automation bot moved this to To do in Ribasim Nov 3, 2023
@SouthEndMusic SouthEndMusic changed the title Use a MetaGraphsNext.jl to represent the Ribasim graph with subnetworks Use MetaGraphsNext.jl to represent the Ribasim graph with subnetworks Nov 3, 2023
@visr visr changed the title Use MetaGraphsNext.jl to represent the Ribasim graph with subnetworks Use MetaGraphsNext.jl for graphs with node IDs Nov 3, 2023
@visr visr changed the title Use MetaGraphsNext.jl for graphs with node IDs Use MetaGraphsNext.jl for graphs with node and edge IDs Nov 3, 2023
@visr
Copy link
Member

visr commented Nov 3, 2023

Generalized the issue a bit so it is not only about the allocation graph, but all graphs. And if we can store any metadata on our graphs, we can put node IDs on vertices, edge IDs on edges. Perhaps other metadata like name and node type can also help with simplifying the code, avoiding extra mappings.

https://juliagraphs.org/MetaGraphsNext.jl/stable/tutorial/1_basics/

@SouthEndMusic SouthEndMusic moved this from To do to What's next in Ribasim Nov 8, 2023
@SouthEndMusic
Copy link
Collaborator Author

It looks very promising, I think this can really clean up the allocation code and maybe more. What do you think about creating new objects for vertex and edge metadata? Example:

struct VertexMetadata
    type::Symbol # Could replace Parameters.lookup
    data_index::Int # The index of this node in the node data
    state_index::Int # If the node is a basin or PID controller, this is the index of the associated state variable
    subnetwork_id::Int

end

struct EdgeMetadata
    flow::Bool # Is it a flow edge?
    control::Bool # Is it a control edge?
    allocation::Bool # Is it an edge that is part of an allocation graph?
end

It would make sense to me that the vertex labels are the non-consecutive node IDs (although that is discouraged in the link you sent). We also have to think about the construction of the metagraph; I think the metadata must be in some mutable object so that it can be altered after construction. I suppose metadata will not be altered during simulation.

Regarding allocation:

  • There is no need to make separate graphs for allocation networks, this can be put in the metadata (note that allocation graphs can have 'shortcut edges' that are not part of the flow graph);
  • Thus there is no longer need for mapping between node IDs of allocation graphs and the main flow graph.

@visr
Copy link
Member

visr commented Nov 8, 2023

Yes adding structs for this makes sense to me. I know it's only an example, but to comment on it already:

  • Shall we stick to using Node rather than Vertex?
  • Instead of a Symbol for type, we could perhaps start using e.g. EnumX.jl instead. That probably also goes for other places in the code.
  • Rather than both flow::Bool and control::Bool, here an enum might make more sense as well, so it is always either x or y.

It would make sense to me that the vertex labels are the non-consecutive node IDs (although that is discouraged in the link you sent).

Indeed, this is the mentioned text:

The label_type argument defines how vertices will be referred to, it can be anything you want (although integer types are generally discouraged, to avoid confusion with the vertex codes used by Graphs.jl).

That doesn't mean we shouldn't, but confusing id::Int and index::Int is real. Perhaps we should consider typing our IDs:

struct ID  # or rather, NodeID and EdgeID
    id::Int
end

That means we can dispatch on it, and we don't want to do any arithmetic on ID anyway.

@visr visr moved this from What's next to Sprint backlog in Ribasim Nov 9, 2023
@SouthEndMusic SouthEndMusic added epic needs-refinement Issues that are too large and need refinement labels Nov 14, 2023
@SouthEndMusic
Copy link
Collaborator Author

SouthEndMusic commented Nov 14, 2023

Sub-issues for using MetaGraphsNext.jl:

@SouthEndMusic SouthEndMusic removed the needs-refinement Issues that are too large and need refinement label Nov 14, 2023
@SouthEndMusic SouthEndMusic moved this from Sprint backlog to What's next in Ribasim Nov 14, 2023
@SouthEndMusic SouthEndMusic changed the title Use MetaGraphsNext.jl for graphs with node and edge IDs Meta-issue: Use MetaGraphsNext.jl for graphs with node and edge IDs Nov 14, 2023
@SouthEndMusic
Copy link
Collaborator Author

Closed as fixed by #789, #807, #828, #830, #850.

@github-project-automation github-project-automation bot moved this from What's next to ✅ Done in Ribasim Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
allocation Allocation layer
Projects
Archived in project
Development

No branches or pull requests

2 participants