Skip to content

Don't require unique node IDs#1513

Merged
evetion merged 10 commits intomainfrom
unique
Jun 5, 2024
Merged

Don't require unique node IDs#1513
evetion merged 10 commits intomainfrom
unique

Conversation

@visr
Copy link
Copy Markdown
Member

@visr visr commented May 30, 2024

Fixes #1318
Fixes #1256

@evetion I didn't touch the Delwaq node_lookup. If only Basins are in the graph, then you can still use an ID as a unique index.

The #1256 fix in 72dcf24 is not tested, since Ribasim-Python stops us from creating such an invalid model. I manually confirmed it works by duplicating rows in QGIS.

The main methods were needed to fix pixi run ribasim-core.

Copy link
Copy Markdown
Member

@evetion evetion left a comment

Choose a reason for hiding this comment

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

LGTM, some nitpicks. This will break the current assumptions in the Delwaq coupling scripts, so maybe not merge just yet?

@evetion
Copy link
Copy Markdown
Member

evetion commented Jun 4, 2024

I'll make the changes so the coupling can handle the non-uniqueness. Would be good to also create a new coupling test that takes a horribly non-unique model to convert.

edit: Done, back to you @visr (feel free to review my changes)

@evetion evetion merged commit 89b8574 into main Jun 5, 2024
@evetion evetion deleted the unique branch June 5, 2024 09:08
Jingru923 pushed a commit that referenced this pull request Aug 13, 2024
Fixes #1690 as a 🎁 for @deltamarnix when he is back from holiday.

Triggered by #1648, which seems very hard to do in QGIS as it doesn't
support compound indexes and we dislike a separate global unique id. In
a discussion with @visr he mentioned most people don't use the
non-global unique id feature (yet).

Reverts #1513. Partially reverts #1690 as the `NodeID` changes are not
reverted, as it is quite useful to know the node_type in several parts
of the code (instead of only a node_id). Therefore, I've added a new
`NodeID` constructor and joined the Edge table with the Node table.

I had to change the node_ids of several new test models created by
@SouthEndMusic, bit of a pain, but the tests seem to pass still.

Furthermore, I changed the `node.add` functionality to *return* the
`NodeData`, which should make the `edge.add` more straightforward (and
pave the way for automatic id numbering in the future). So this:

```julia
model.terminal.add(Node(terminal_id, Point(500, 200)))
model.tabulated_rating_curve.add(
    Node(6, Point(450, 200)),
    [tabulated_rating_curve.Static(level=[0.0, 1.0], flow_rate=[0.0, 10 / 86400])],
)

model.edge.add(
    model.basin[6],
    model.tabulated_rating_curve[6],
)
model.edge.add(
    model.tabulated_rating_curve[6],
    model.terminal[terminal_id],
)
```
becomes this:

```julia
term = model.terminal.add(Node(terminal_id, Point(500, 200)))
trc0 = model.tabulated_rating_curve.add(
    Node(0, Point(450, 200)),
    [tabulated_rating_curve.Static(level=[0.0, 1.0], flow_rate=[0.0, 10 / 86400])],
)

model.edge.add(
    basin6,
    trc0,
)
model.edge.add(trc0, term)
```

I've made this change in a single Python test model, and in the first
model of the examples notebook. We could gradually change this further
over time.

---------

Co-authored-by: Martijn Visser <mgvisser@gmail.com>
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.

Stop requiring globally unique node ids Validate uniqueness of Node table in core

2 participants