Deltares / Ribasim

Water resources modeling
https://ribasim.org/
MIT License
39 stars 5 forks source link

Cannot run model without any Basins #1615

Open Fati-Mon opened 2 months ago

Fati-Mon commented 2 months ago

What If a user wants to model a simple system with no storage, the following error is shown:

  Cell In[2], line 6
    subprocess.run([rib_path, toml_path], check=True)

  File C:\Ribasim9\.pixi\envs\default\Lib\subprocess.py:571 in run
    raise CalledProcessError(retcode, process.args,

CalledProcessError: Command '[WindowsPath('c:/Ribasim9/ribasim_windows/ribasim.exe'), WindowsPath('c:/Ribasim9/data/basic/ribasim.toml')]' returned non-zero exit status 1.

Why

Not clear that a basin node is needed to be able to run the model. image How Mention in the error that the user needs to add a basin for the model to run or describe that certain nodes cannot be directly linked (in this case flow boundaries directly linked with a terminal)

visr commented 2 months ago

Thanks for the report. Could you add the Python script you have for writing the model, and the error message that Ribasim gives?

EDIT: The Python script is here: https://github.com/Deltares/Ribasim/issues/1263#issuecomment-2213567653

visr commented 1 month ago

The error itself comes from here, where area and level are both typed empty arrays Float64[] and the resulting level_to_area is an Any[] which causes dispatch issues.

https://github.com/Deltares/Ribasim/blob/eadc057aec2d1513fe702c122d222755ef64a23d/core/src/read.jl#L603

Not sure how many issues hide behind this one though. If it isn't easy to support, with correct results, we should error early with a clear message.

Fati-Mon commented 1 month ago

Even after adding a Basin I get the same problem:

import subprocess  # for running the model
import shutil
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from ribasim import Allocation, Model, Node
from ribasim.nodes import (
    flow_boundary,
    basin,
    terminal
)
from shapely.geometry import Point

base_dir = Path("c:/Ribasim9")
model_dir = base_dir / "Virgin"
flows_path = model_dir / "input/ACTINFLW.csv"

starttime = "2023-01-01"
endtime = "2024-01-01"
model = Model(
    starttime=starttime,
    endtime=endtime,
    crs="EPSG:4326",
)

#%% FLOW BOUNDARY

# FLOW BOUNDARY
flows = pd.read_csv(flows_path, sep=";")

model.flow_boundary.add(
    Node(1, Point(0.0, 0.0), name='Main'), 
    [flow_boundary.Time(time=flows.time, flow_rate=flows.main, #name="Main"
    )]
)

model.flow_boundary.add(
    Node(2, Point(-3.0, 0.0), name='Minor'), 
    [flow_boundary.Time(time=flows.time, flow_rate=flows.minor, #name="Main"
    )]
)

# BASIN (confluence)

model.basin.add(
    Node(3, Point(-1.5, -1), name='Conf'),
    [
        basin.Profile(area=[1000.0, 1000.0], level=[0.0, 1.0]),
        basin.State(level=[20.0]),
        basin.Time(time=[starttime, endtime], precipitation=[0.0, 3e-6]),
    ],
)

# TERMINAL

model.terminal.add(Node(4, Point(-1.5, -3.0), name="Terminal"))

# EDGES

model.edge.add(model.flow_boundary[1], model.basin[3])
model.edge.add(model.flow_boundary[2], model.basin[3])
model.edge.add(model.basin[3], model.terminal[4])

# SCHEMATIZATION

model.plot()

datadir = Path("data")
toml_path = datadir / "basic/ribasim.toml"
model.write(toml_path)
rib_path = base_dir / "ribasim_windows/ribasim.exe"

subprocess.run([rib_path, toml_path], check=True)

Is it the way the subprocess run is called?

visr commented 1 month ago

Is it the way the subprocess run is called?

Indeed, this is improved in #1650.

For the error of https://github.com/Deltares/Ribasim/issues/1615#issuecomment-2228671453, I suggest we look again after #1649 is merged.