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

Cannot run model without any Basins #1615

Open
Fati-Mon opened this issue Jul 8, 2024 · 4 comments
Open

Cannot run model without any Basins #1615

Fati-Mon opened this issue Jul 8, 2024 · 4 comments
Labels
core Issues related to the computational core in Julia

Comments

@Fati-Mon
Copy link
Collaborator

Fati-Mon commented Jul 8, 2024

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
Copy link
Member

visr commented Jul 8, 2024

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: #1263 (comment)

@visr visr added the bug label Jul 8, 2024
@visr visr changed the title Error description Cannot run model without any Basins Jul 8, 2024
@visr
Copy link
Member

visr commented Jul 15, 2024

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.

level_to_area = SmoothedLinearInterpolation.(area, level; extrapolate = true, λ = 0.01)

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
Copy link
Collaborator Author

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
Copy link
Member

visr commented Jul 23, 2024

Is it the way the subprocess run is called?

Indeed, this is improved in #1650.

For the error of #1615 (comment), I suggest we look again after #1649 is merged.

@SnippenE SnippenE added the v1.0 label Aug 21, 2024
@Jingru923 Jingru923 added enhancement core Issues related to the computational core in Julia and removed bug labels Aug 22, 2024
@visr visr removed the enhancement label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues related to the computational core in Julia
Projects
Status: To do
Development

No branches or pull requests

4 participants