-
Notifications
You must be signed in to change notification settings - Fork 57
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
Add functionality for input based model options #1270
Changes from 3 commits
484d794
8025547
cad4228
a52e35d
43d7f39
356031c
1bc3ab8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,8 +197,10 @@ | |
display_name: str = None | ||
description: str = None | ||
display_values: List[Any] = [] | ||
values_allowed: List[Any] = [] | ||
values_allowed: Union[str, List[Any]] | ||
value: Any = None | ||
min_val: Union[None, int, float] = None | ||
max_val: Union[None, int, float] = None | ||
|
||
@validator("display_name", always=True) | ||
@classmethod | ||
|
@@ -218,11 +220,29 @@ | |
@classmethod | ||
def validate_value(cls, v, values): | ||
allowed = values.get("values_allowed", None) | ||
# allowed = list(allowed.keys()) | ||
if v in allowed: | ||
return v | ||
# check if values allowed is int or float and ensure valid value | ||
if allowed == "int": | ||
if isinstance(v, int): | ||
return v | ||
else: | ||
raise ValueError(f"'value' ({v}) not a valid integer") | ||
elif allowed == "float": | ||
if isinstance(v, int) or isinstance(v, float): | ||
return v | ||
else: | ||
raise ValueError(f"'value' ({v}) not a valid float") | ||
# check if values allowed is string | ||
elif allowed == "string": | ||
if isinstance(v, str): | ||
return v | ||
else: | ||
raise ValueError(f"'value' ({v}) not a valid string") | ||
# values_allowed is a list. make sure v is in the list of values allowed | ||
else: | ||
raise ValueError(f"'value' ({v}) not in allowed values: {allowed}") | ||
if v in allowed: | ||
return v | ||
else: | ||
raise ValueError(f"'value' ({v}) not in allowed values: {allowed}") | ||
|
||
|
||
class FlowsheetExport(BaseModel): | ||
|
@@ -611,6 +631,14 @@ | |
self.add_action("diagram", None) | ||
|
||
self._actions["custom_do_param_sweep_kwargs"] = custom_do_param_sweep_kwargs | ||
self.fs_exp.add_option( | ||
name="NumParallelWorkers", | ||
display_name="Number of multi-processing workers", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be more clear to say "Number of multi-processing workers for sensitivity analysis" right now when there are build options, we don't have a way to do any groupings. Might be nice if we had a groups for build options like we do for flowsheet inputs (e.g. flowsheet model build options, analysis options etc..) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @MichaelPesce mentioned that he would exclude this bit from the PR |
||
values_allowed="int", | ||
value=1, | ||
max_val=16, | ||
min_val=1, | ||
) | ||
|
||
def build(self, **kwargs): | ||
"""Build flowsheet | ||
|
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.
If I read this right, we can allow users select an option from a list, or enter a string, int or float?
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 true according to @MichaelPesce