-
Notifications
You must be signed in to change notification settings - Fork 4
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
Refactor parameters into General, Simple and Constant #194
Conversation
GeneralParameter contains compute and after methods, Parameter contains the others.
This is designed as an alternative to #192. The high level idea is the solve the circular parameter issue with initial volumes by recognising that some parameters do not vary in time and/or depend no node state. We introduce the General, Simple and Constant parameters as new traits: - `GeneralParameter` - rename of the current implementation. - `SimpleParameter` - Parameters that only depend on other Simple or Constant parameters, but do vary in time. - `ConstantParameter` - Parameters that only depend on other Constant parameters, and do *not* vary in time. Simple parameters are evaluated before general and `.before` methods each time-step. This allows them to vary in time, but means that can't depend on network or general parameter values. This is most relevant for profiles which have no dependencies but do vary in time. Constant parameters would be evaluated at the beginning of the simulation only. NB, this is not yet implemented. Some parameters can potentially implement one or more of these traits. For example, the AggregatedParameter is implemented for General and Simple depending on whether it is aggregating over MetricF64 or SimpleMetricF64. This allows the user to use an aggregated parameter as a simple parameter provided it is only aggregating over simple parameters. From the schema point of view there is no difference. When added to the core model it attempts to add it as a simplified version if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From an initial read through, this feels like a better solution than #192
One issue I did find when testing using the delay parameter as a simple parameter is that the after
method is not currently called simple parameters.
)); | ||
} | ||
|
||
match parameter.try_into_simple() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a bit of explanation here in a comment? Potentially the function name could be updated to reflect the fact that a simple parameter could be added instead of a general one.
MultiParameterValue((ParameterIndex<MultiValue>, String)), | ||
ParameterValue(GeneralParameterIndex<f64>), | ||
IndexParameterValue(GeneralParameterIndex<usize>), | ||
MultiParameterValue((GeneralParameterIndex<MultiValue>, String)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor point but should these 3 variants be put into a nest enum to be consistent with the simple params?
Final parameter variant that is computed only at the beginning of a model.
This is now fixed. It's ready for a final review. |
pywr-core/src/parameters/mod.rs
Outdated
&mut self, | ||
parameter: Box<dyn SimpleParameter<usize>>, | ||
) -> Result<SimpleParameterIndex<usize>, PywrError> { | ||
// TODO Fix this check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be fixed in this PR?
pywr-core/src/parameters/mod.rs
Outdated
&mut self, | ||
parameter: Box<dyn SimpleParameter<MultiValue>>, | ||
) -> Result<SimpleParameterIndex<MultiValue>, PywrError> { | ||
// TODO Fix this check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
Implements the same API for all 3 types. Adds checks to ensure names are unique across all parameter variants.
This has been merged with master and the above issues addressed. |
This is designed as an alternative to #192.
The high level idea is the solve the circular parameter issue with initial volumes by recognising that some parameters
do not vary in time and/or depend no node state.
We introduce the General, Simple and Constant parameters as new traits:
GeneralParameter
- rename of the current implementation.SimpleParameter
- Parameters that only depend on other Simple or Constant parameters, but do vary in time.ConstantParameter
- Parameters that only depend on other Constant parameters, and do not vary in time.Simple parameters are evaluated before general and
.before
methods each time-step. This allows them to vary in time, but means that can't depend on network or general parameter values. This is most relevant for profiles which have no dependencies but do vary in time.Constant parameters would be evaluated at the beginning of the simulation only. NB, this is not yet implemented.
Some parameters can potentially implement one or more of these traits. For example, the AggregatedParameter is implemented for General and Simple depending on whether it is aggregating over MetricF64 or SimpleMetricF64. This allows the user to use an aggregated parameter as a simple parameter provided it is only aggregating over simple parameters. From the schema point of view there is no difference. When added to the core model it attempts to add it as a simplified version if possible.
@Batch21 @s-simoncelli @laurenpetch any thoughts on this vs #192 ? Sorry, it's a big refactor / change this one.