Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #978 +/- ##
==========================================
- Coverage 84.01% 83.95% -0.07%
==========================================
Files 50 50
Lines 5682 5696 +14
Branches 5682 5696 +14
==========================================
+ Hits 4774 4782 +8
- Misses 679 685 +6
Partials 229 229 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tsmbland
left a comment
There was a problem hiding this comment.
There seems to be a bit of inconsistency about when to treat zero flows as inputs vs outputs. I don't have all the answers myself, but I think this requires some thought, or at least some of the reasoning here needs more explanation.
If this was me, I might have done this by writing a FlowDirection enum (with values Input, Output and Zero), then replace the is_input()/is_output()/is_zero() methods with a single direction() method. Then, we could use match arms to explicitly deal with the three scenarios where appropriate, and we're not going to inadvertently assume that is_input() -> false necessarily means its an output flow.
If in some circumstances we want zero flows to behave both like inputs and outputs (e.g. validate_secondary_flows), then we could do this by writing a custom Eq implementation for FlowDirection. There could be some unintended consequences of that though, not sure
src/input/process/flow.rs
Outdated
| .iter() | ||
| .filter_map(|(commodity_id, flow)| flow.is_output().then_some(commodity_id)); | ||
| let mut iter = map.iter().filter_map(|(commodity_id, flow)| { | ||
| (flow.is_output() || flow.is_zero()).then_some(commodity_id) |
There was a problem hiding this comment.
I wouldn't consider zero flows here. If a flow has a coefficient of zero then it shouldn't be a primary output
src/input/process/flow.rs
Outdated
|
|
||
| ensure!( | ||
| flow.is_output(), | ||
| flow.is_output() || flow.is_zero(), |
src/input/process/flow.rs
Outdated
| .then_some(((commodity_id.clone(), region_id.clone()), flow.is_input())) | ||
| (Some(commodity_id) != process.primary_output.as_ref()).then_some(( | ||
| (commodity_id.clone(), region_id.clone()), | ||
| flow.is_input() || flow.is_zero(), |
There was a problem hiding this comment.
Here you're treating zero flows as like inputs. So it will be ok if a flow is negative some years and zero other years, but not ok if it's positive some years and zero other years?
I don't really understand the reasoning for this. I think probably either both scenarios or neither scenarios should be accepted
src/process.rs
Outdated
| /// | ||
| /// Positive value indicates flow out and negative value indicates flow in. | ||
| /// Positive value indicates flow out and negative value indicates flow in. A value of zero is | ||
| /// both input and output. |
There was a problem hiding this comment.
Is this true? At least not according to is_input and is_output
|
I see your point. I'll revisit using the Having said that, I think we need to clarify when we want to allow zero coeff. For your comments, |
It's not necessarily a problem, it might not break anything, although it means that process will never be invested in. I can maybe see a use case for this in wanting to temporarily "silence" a process. That said, I don't think we should infer commodities with zero coeff as the primary output, so this means changing
Probably fine, but that process is essentially a null process. I think in a final model it would be better for users not to include a process like this, but I can see that it could be useful during debugging to temporarily turn off flows, as above. The graph validation excludes zero flows (as it should), so hopefully if zero coeffs make the model infeasible then it should be picked up at that stage |
tsmbland
left a comment
There was a problem hiding this comment.
I think this is better, more explicit at least
Co-authored-by: Tom Bland <t.bland@imperial.ac.uk>
Description
The approach has been to make another check
is_zeroand use it in combination withis_inputandis_outputwhere relevant, in particular when validating the inputs.I've play around changing to zero several inputs and outputs in the examples and, obviously, sometimes we end up with an unfeasible problem because there's no production to fulfill the demand, but that is the expected behaviour in those cases, not an error.
I've not implemented any validation that flows are not zero for all years since I feel users might want to do that on some scenarios - eg. disabling a particular process to see what happens without having to re-do the input files entirely.
Fixes #928
Type of change
Key checklist
$ cargo test$ cargo docFurther checks