Skip to content

Commit

Permalink
Merge branch 'main' into let_solver_integrate_flows
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed May 6, 2024
2 parents f9632d6 + 158fd05 commit ea696b2
Show file tree
Hide file tree
Showing 8 changed files with 1,918 additions and 3,607 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/core_testmodels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- x64
steps:
- uses: actions/checkout@v4
- uses: julia-actions/cache@v1
- uses: julia-actions/cache@v2
with:
cache-compiled: "true"
cache-registries: "true"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/core_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- x64
steps:
- uses: actions/checkout@v4
- uses: julia-actions/cache@v1
- uses: julia-actions/cache@v2
with:
cache-compiled: "true"
cache-registries: "true"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
contents: write
steps:
- uses: actions/checkout@v4
- uses: julia-actions/cache@v1
- uses: julia-actions/cache@v2
with:
cache-compiled: "true"
cache-registries: "true"
Expand Down
5,477 changes: 1,908 additions & 3,569 deletions pixi.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions python/ribasim/ribasim/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pandas as pd
import pydantic
from geopandas import GeoDataFrame
from pydantic import ConfigDict, Field, model_validator
from pydantic import ConfigDict, Field, NonNegativeInt, model_validator
from shapely.geometry import Point

from ribasim.geometry import BasinAreaSchema, NodeTable
Expand Down Expand Up @@ -87,7 +87,7 @@ class Logging(ChildModel):


class Node(pydantic.BaseModel):
node_id: int
node_id: NonNegativeInt
geometry: Point
name: str = ""
subnetwork_id: int | None = None
Expand Down
2 changes: 1 addition & 1 deletion python/ribasim/ribasim/geometry/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class NodeSchema(pa.SchemaModel):
node_id: Series[Int32]
node_id: Series[Int32] = pa.Field(ge=0)
name: Series[str] = pa.Field(default="")
node_type: Series[str] = pa.Field(default="")
subnetwork_id: Series[pd.Int32Dtype] = pa.Field(
Expand Down
17 changes: 0 additions & 17 deletions python/ribasim/ribasim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,6 @@ def _children(self):
if isinstance(getattr(self, k), ChildModel)
}

def validate_model_node_field_ids(self):
raise NotImplementedError()

def validate_model_node_ids(self):
raise NotImplementedError()

def validate_model(self):
"""Validate the model.
Checks:
- Whether the node IDs of the node_type fields are valid
- Whether the node IDs in the node field correspond to the node IDs on the node type fields
"""

self.validate_model_node_field_ids()
self.validate_model_node_ids()

@classmethod
def read(cls, filepath: str | PathLike[str]) -> "Model":
"""Read model from TOML file."""
Expand Down
19 changes: 4 additions & 15 deletions python/ribasim/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import xugrid
from pydantic import ValidationError
from pyproj import CRS
from ribasim import Node
from ribasim.config import Solver
from ribasim.geometry.edge import NodeData
from ribasim.input_base import esc_id
Expand Down Expand Up @@ -65,24 +66,12 @@ def test_exclude_unset(basic):
assert d["solver"]["saveat"] == 86400.0


@pytest.mark.xfail(reason="Needs implementation")
def test_invalid_node_id(basic):
model = basic

# Add entry with invalid node ID
df = model.pump.static.df._append(
{"flow_rate": 1, "node_id": -1, "active": True},
ignore_index=True,
)
# Currently can't handle mixed NaN and None in a DataFrame
df = df.where(pd.notna(df), None)
model.pump.static.df = df

def test_invalid_node_id():
with pytest.raises(
ValueError,
match=re.escape("Node IDs must be non-negative integers, got [-1]."),
match=r".* Input should be greater than or equal to 0 .*",
):
model.validate_model_node_field_ids()
Node(-1, Point(7.0, 7.0))


@pytest.mark.xfail(reason="Should be reimplemented by the .add() API.")
Expand Down

0 comments on commit ea696b2

Please sign in to comment.