-
Notifications
You must be signed in to change notification settings - Fork 235
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
Fix nested flowsheet time domain construction #1495
base: main
Are you sure you want to change the base?
Conversation
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.
This looks like a good start - I only had a few minor comments.
WE should also check the documentation to make sure that what we say there is correct.
idaes/core/base/flowsheet_model.py
Outdated
@@ -342,35 +367,24 @@ def _setup_dynamics(self): | |||
"{} was set as a dynamic flowsheet, but time domain " | |||
"provided was not a ContinuousSet.".format(self.name) | |||
) | |||
|
|||
if self.config.dynamic is False and not isinstance( |
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.
- Is this check actually necessary? This would appear to preclude putting steady-state flowsheets inside dynamic flowsheets.
if self.config.dynamic is False
can be written asif not self.config.dynamic
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.
That's exactly what it was checking for. Since we don't want to allow adding a nested dynamic flowsheet inside a parent steady-state flowsheet, I will remove this check from this PR.
# Set time config argument as reference to time domain | ||
self.config.time = self._time | ||
_create_time_domain() | ||
elif self.config.time_set is not None: |
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.
I think this is enough, but just to check is there any additional validation we should do here? Also, an in-line comment to explain what this case is (sub-flowsheet with user-provided time domain).
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.
Based on my testing I think this should be good enough. The _create_time_domain
method makes sure that the specified time_set
list is of the right length. So the same checks that apply for time domain construction in a parent flowsheet should apply to the nested flowsheet.
@dallan-keylogic could Are there any edge cases I am overlooking?
m.fs.sub = FlowsheetBlock(dynamic=True, time=m.s2, time_units=units.s) | ||
|
||
assert m.fs.sub.config.dynamic is True | ||
assert isinstance(m.fs.sub.time, ContinuousSet) |
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.
Here you should do assert m.fs.time is m.s2
. - i.e. check that the time domain is the correct set, not just the correct type.
|
||
assert m.fs.sub.config.dynamic is False | ||
assert isinstance(m.fs.sub.time, Set) | ||
assert m.fs.sub.time_units == units.dimensionless |
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.
As above.
def test_dynamic_parent_time_indexed_ss_child(self): | ||
m = ConcreteModel() | ||
m.fs = FlowsheetBlock(dynamic=True, time_set = [1,2,3], time_units=units.s) | ||
m.fs.sub = FlowsheetBlock(dynamic=False, time_set = [0, 1], time_units=units.dimensionless) |
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.
Time should not be dimensionless - it does not matter for the test, but we should not accidentally encourage people to think this is OK.
@NishantGiridhar any update on this? |
@NishantGiridhar You need to run |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1495 +/- ##
==========================================
- Coverage 77.05% 77.05% -0.01%
==========================================
Files 384 384
Lines 62335 62341 +6
Branches 10222 10224 +2
==========================================
+ Hits 48031 48034 +3
- Misses 11875 11879 +4
+ Partials 2429 2428 -1 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
idaes/core/base/flowsheet_model.py
Outdated
self.config.time = self._time | ||
_create_time_domain() | ||
# Creates a new time domain for a sub-flowsheet with user provided time domain | ||
elif self.config.time_set not in [None, [0]]: |
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.
Why is the [0]
here? I would have thought that if we are handed an argument we should use it. To put it another way, if the user provides [0]
as an argument we will ignore it without saying why.
Fixes
Summary/Motivation:
In the current implementation of FlowsheetBlock, nested flowsheets with a time domain can only inherit time from the parent flowsheet.
Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I agree to the following terms and conditions for my contribution: