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

Priority parameter should be non-optional #1732

Closed
Jingru923 opened this issue Aug 16, 2024 · 7 comments · Fixed by #1745
Closed

Priority parameter should be non-optional #1732

Jingru923 opened this issue Aug 16, 2024 · 7 comments · Fixed by #1745
Assignees
Labels
core Issues related to the computational core in Julia validation Related to model validation

Comments

@Jingru923
Copy link
Contributor

What
Recently in solving issue #1724 , it has come to me that even thought the priority of user demand is not given, the whole program can still be run.

As this is not a desire behavior, investigation into the reason is needed.

@Jingru923 Jingru923 added core Issues related to the computational core in Julia validation Related to model validation labels Aug 16, 2024
@github-project-automation github-project-automation bot moved this to To do in Ribasim Aug 16, 2024
@gijsber
Copy link
Contributor

gijsber commented Aug 16, 2024

Priority paramneter is only required when use_allocation=true. If you do not use allocation, the priority parameter can be optional.

@Jingru923
Copy link
Contributor Author

Thanks @gijsber . In this case the documentation should be updated since it gave not only me but also other user and developer some confusion.

However, if I run models with allocation active and user demand node without specifying priority, the model can still be run. This is the same situation even for the models with main network. This should still be looked into.

@gijsber
Copy link
Contributor

gijsber commented Aug 16, 2024

if you have a model with allocation active and user demand node without specifying priority, you should get a validation error

@Jingru923
Copy link
Contributor Author

I agree with you @gijsber . An error should be given in this case.

What worried me is that the model can still run even though the mode has such error. This mean that in the current implementation, priority parameter is not needed. We should change the implementation into one that actually make use of the priority, then give an error if priority is missing.

@Jingru923 Jingru923 moved this from To do to 🏗 In progress in Ribasim Aug 16, 2024
@Jingru923
Copy link
Contributor Author

A finding on this issue. When reading the demand nodes into geodata based, a column "priority" is created and all the values inside this column are initialized as 0. Therefore, even if no priority parameter are given to the demand nodes, the model can still run. The nodes would have priorities of 0.

To avoid that, I wrote a validation function for all the demand nodes. If allocation is active, priorities is a mandatory field. If priority is given but allocation is not active, a warning message will be display but the program will still run

@SouthEndMusic
Copy link
Collaborator

SouthEndMusic commented Aug 18, 2024

We don't have warning messages thus far, because @visr is not a fan of them. I think the priorities not being used when allocation is not active does belong in the documentation but does not need the warning message.

Note that the priority is mandatory in the core:

Ribasim/core/src/schema.jl

Lines 278 to 294 in 98df891

@version UserDemandStaticV1 begin
node_id::Int32
active::Union{Missing, Bool}
demand::Union{Missing, Float64}
return_factor::Float64
min_level::Float64
priority::Int32
end
@version UserDemandTimeV1 begin
node_id::Int32
time::DateTime
demand::Float64
return_factor::Float64
min_level::Float64
priority::Int32
end

The default value of 0 I think comes from here:

class UserDemandStaticSchema(_BaseSchema):
node_id: Series[Int32] = pa.Field(nullable=False, default=0)
active: Series[pa.BOOL] = pa.Field(nullable=True)
demand: Series[float] = pa.Field(nullable=True)
return_factor: Series[float] = pa.Field(nullable=False)
min_level: Series[float] = pa.Field(nullable=False)
priority: Series[Int32] = pa.Field(nullable=False, default=0)
class UserDemandTimeSchema(_BaseSchema):
node_id: Series[Int32] = pa.Field(nullable=False, default=0)
time: Series[Timestamp] = pa.Field(nullable=False)
demand: Series[float] = pa.Field(nullable=False)
return_factor: Series[float] = pa.Field(nullable=False)
min_level: Series[float] = pa.Field(nullable=False)
priority: Series[Int32] = pa.Field(nullable=False, default=0)

Not sure how that ends up in that automatically generated file, maybe it's standard for Int32 parameters.

Currently priorities < 1 are accepted in the core. That's quite a handy design, because then you don't have to shift all other priorities if you want to add a new most important priority level. A downside of this is that the default priority = 0 is accepted as a valid priority.

I think the best way to solve this is as follows:

  • make priority for UserDemand optional and get rid of the default value of 0;
  • throw an error in the core if allocation is active and priority is not specified.

@Jingru923 Jingru923 self-assigned this Aug 19, 2024
@Jingru923
Copy link
Contributor Author

It is easier to do validation with the default value. I suggest that we keep it for now.

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 validation Related to model validation
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants