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

Validation of input for allocation #710

Closed
4 tasks done
SouthEndMusic opened this issue Oct 27, 2023 · 0 comments · Fixed by #972
Closed
4 tasks done

Validation of input for allocation #710

SouthEndMusic opened this issue Oct 27, 2023 · 0 comments · Fixed by #972
Assignees
Labels
allocation Allocation layer validation Related to model validation

Comments

@SouthEndMusic
Copy link
Collaborator

SouthEndMusic commented Oct 27, 2023

What
The input data for allocation must be validated:

  • The set of nodes for a subnetwork should be directly connected, that is: there should be a path, not taking edge directions into account, between each pair of nodes in the allocation graph that only goes via nodes that are also in the same allocation graph. This requires some graph processing: perhaps the best way to do this is by starting a flood fill at a random point in the subnetwork and see whether you can cover the whole subnetwork from there. Some good things to know:

  • In the Julia core, node IDs are not just integers: each node ID is an integer wrapped in the NodeID type.

  • I use the terms subnetwork and allocation network. Let's say a subnetwork consists of all the nodes with the same allocation_network_id in the model input. The allocation network consists of the nodes which are selected from the subnetwork to be part of the network that is used for optimization. This information can be found in the node metadata, see below.

  • The set of nodes used for allocation optimization in a subnetwork are stored in p.graph[].node_ids[allocation_network_id];

  • To get the in-neighbors and out-neighbors of a node, use the functions inflow_ids_allocation and outflow_ids_allocation.

  • You do need to check for every node whether it is in the allocation network you are considering, which you can test by looking up the nodes' metadata by graph[node_id]. For the metadata fields see struct NodeMetadata.

  • The best way to apply this validation is just after the allocation network is initialized, which is in the function AllocationModel after allocation_graph is called.

  • The source edges should end in a node of the allocation network the source edge is associated with. This can be added to an already existing validation function for source edges: function valid_sources. Source edges can be found in graph[].edges_source[allocation_network_id].
    Edit: this point can be skipped because the mentioned validation function is being updated in the main_network_allocation_main feature branch.

  • Demands should be non-negative. Some good things to know:

  • Demands are stored as (time) interpolation objects in the User node type. Node types are initialized in create.jl in functions with the same name as the node type.

  • There are several ways to implement validation. One of them is to first initialize an object and then run validation on its fields. Another way is to incorporate the validation into the inner constructor of an object, which I think is the best way to go here. See here for an example of this in our codebase.

  • Allocation network IDs is must be positive integers. A good place to check this is in function generate_allocation_models!.

Why
So that modelers get comprehensive error messages if the input is not as expected, instead of incomprehensible error messages or malfunctioning code.

How
This can be done analogously to existing validation and tests thereof. See:

  • The functions valid_* in validation.jl
  • The invalid models in invalid.py
  • The validation error tests in validation_test.jl
@SouthEndMusic SouthEndMusic added allocation Allocation layer validation Related to model validation labels Oct 27, 2023
@github-project-automation github-project-automation bot moved this to To do in Ribasim Oct 27, 2023
@visr visr moved this from To do to Sprint backlog in Ribasim Jan 8, 2024
@visr visr moved this from Sprint backlog to To do in Ribasim Jan 8, 2024
@Jingru923 Jingru923 moved this from To do to 🏗 In progress in Ribasim Jan 12, 2024
@Jingru923 Jingru923 self-assigned this Jan 12, 2024
@Jingru923 Jingru923 linked a pull request Jan 19, 2024 that will close this issue
@Jingru923 Jingru923 moved this from 🏗 In progress to 👀 In review in Ribasim Feb 1, 2024
Jingru923 added a commit that referenced this issue Feb 1, 2024
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Ribasim Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
allocation Allocation layer validation Related to model validation
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants