You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -17,14 +17,95 @@
from .workflow_inputs import EnumWorkflowInput, ObjectRefWorkflowInput
class ScriptTypeEnum(Enum):
PyScript = 1
Notebook = 2
+class VisualEnum(Enum):+ Enabled = 1+ Visible = 2++class ObjectRefStateEnum(Enum):+ Selected = 1+ NotSelected = 2++class ParameterRef():+ """A reference to a parameter in a workflow description.+ """+ def __init__(self, name: str, workflow_input: BaseWorkflowInput):+ self.name = name+ self.workflow_input = workflow_input++ def is_valid_state(self, state):+ if self.workflow_input.get_type() == "bool":+ if not isinstance(state, bool):+ return (False, "state must be a bool")+ elif self.workflow_input.get_type() == "enum":+ if not isinstance(state, int):+ return (False, "state must be an int")+ if state not in self.workflow_input._options.keys():+ return (False, "state must be a valid option")+ elif self.workflow_input.get_type() == "object_ref":+ if not isinstance(state, ObjectRefStateEnum):+ return (False, "state must be an ObjectRefStateEnum")+ return (True, "")++ def state_as_string(self, state):+ if self.workflow_input.get_type() == "bool":+ return str(state)+ elif self.workflow_input.get_type() == "enum":+ return str(state)+ elif self.workflow_input.get_type() == "object_ref":+ return str(state.name)++class ParameterState():+ """A class to define a desired parameter state.+ Used as the key in the linked_visual_parameters dictionary when add_*_parameter is called on the WorkflowDescription object. The ParameterState links the visual state of a parameter to the state of another parameter.++ **Example**: ++ Add an integer parameter that is only enabled in the UI when the linked boolean reference is True (Integer value can only be set when checkbox is checked):++ .. code-block:: python+ linked_bool_ref = pwr_description.add_boolean_parameter(name="linked_bool", label="linked_bool", description="linked_bool", default_value=False)+ linked_visual_parameters = {ParameterState(linked_bool_ref, True): VisualEnum.Enabled}+ pwr_description.add_integer_parameter(name="int", label="int", description="int", default_value=0, linked_visual_parameters=linked_visual_parameters)++ **Example**:++ Add an object reference parameter that is only visible in the UI when the linked enum reference is set to a specific value (Well selector only shows when the enum drop-down is set to Value3):++ .. code-block:: python+ linked_enum_ref = pwr_description.add_enum_parameter(name="enum1", label="enum1", description="enum1", options={1:"Value1", 2:"Value2", 3:"Value3"}, default_value=1)+ linked_visual_parameters = {ParameterState(linked_enum_ref, 3): VisualEnum.Visible}+ pwr_description.add_object_ref_parameter(name='well', label='well_selector', description='well_selector', object_type=DomainObjectsEnum.Well, select_multiple=False, linked_visual_parameters=linked_visual_parameters)++ **Example**:++ Add a float parameter that is only enabled in the UI when the linked object reference parameter has a selection (Float value can only be set when a well is selected):++ .. code-block:: python+ linked_object_ref = pwr_description.add_object_ref_parameter(name='well', label='well_selector', description='well_selector', object_type=DomainObjectsEnum.Well, select_multiple=False)+ linked_visual_parameters = {ParameterState(linked_object_ref, ObjectRefStateEnum.Selected): VisualEnum.Enabled}+ pwr_description.add_float_parameter(name="float", label="float", description="float", default_value=0.0, linked_visual_parameters=linked_visual_parameters)++ """+ def __init__(self, parameter_ref: ParameterRef, state):+ self.parameter_ref = parameter_ref+ self.state = state++ def is_valid(self):+ if self.parameter_ref is None:+ return (False, "parameter_ref must be defined")+ return self.parameter_ref.is_valid_state(self.state)++ def as_string(self):+ state_as_string = self.parameter_ref.state_as_string(self.state)+ return f"{self.parameter_ref.name}:{state_as_string}"
class WorkflowDescription():
def __init__(self, name: str, category: str, description: str, authors: str, version: str):
"""
Describes a PWR workflow
@@ -96,64 +177,113 @@
def _get_error_message(self) -> str:
return self._error_message
def _set_error_message(self, error_message: str):
self._error_message = error_message
self._is_valid = False
- def add_boolean_parameter(self, name: str, label: str, description: str, default_value: bool):+ def add_boolean_parameter(self, name: str, label: str, description: str, default_value: bool,+ linked_visual_parameters: Dict[ParameterState, VisualEnum] = None):
"""
Adds a boolean parameter to the workflow description.
This will generate a checkbox in the workflow UI.
+ **Example**:++ Add a boolean parameter:++ .. code-block:: python+ pwr_description.add_boolean_parameter(name='bool', label='bool_input', description='bool_input', default_value=False)++ **Example**:++ Add a boolean parameter that is only visible in the UI when the linked enum reference is set to a specific value (Checkbox only shows when the enum drop-down is set to Value3):++ .. code-block:: python+ linked_enum_ref = pwr_description.add_enum_parameter(name="enum1", label="enum1", description="enum1", options={1:"Value1", 2:"Value2", 3:"Value3"}, default_value=1)+ linked_visual_parameters = {ParameterState(linked_enum_ref, 3): VisualEnum.Visible}+ pwr_description.add_boolean_parameter(name='bool', label='bool_input', description='bool_input', default_value=False, linked_visual_parameters=linked_visual_parameters)+
Args:
name (str): The name of the object created the parameters dictionary. This name must be unique within the workflow.
label (str): The label text that will be displayed next to the checkbox in the workflow UI.
description (str): A description of what the parameter represents. This description will be shown in the tooltip next to the checkbox in the workflow UI.
default_value (bool): The default value to be assigned to the parameter.
+ linked_visual_parameters (Dict[ParameterState, VisualEnum], optional): Use this to specify a link between another boolean, enum or object_ref parameter state and this parameter's visual state.+ If the linked visual parameter have correct state the parameter will be enabled/visible accordingly.+ If adding multiple linked visual parameters, all must be true for the parameter to be enabled/visible.+ Defaults to None.+ Returns:+ ParameterRef: a reference to the parameter that was added+
Raises:
ValueError: If the name is already used in the workflow.
"""
- valid = self._is_common_parameters_valid(name, label, description)+ valid = self._is_common_parameters_valid(name, label, description, linked_visual_parameters)
if not valid[0]:
self._is_valid = False
self._error_message = valid[1]
raise ValueError(self._error_message)
if not isinstance(default_value, bool):
self._is_valid = False
self._error_message = f"Parameter {name}: default_value must be a bool"
raise ValueError(self._error_message)
-- self._parameters.append(BooleanWorkflowInput(name, label, description, default_value))- return self++ workflow_input = BooleanWorkflowInput(name, label, description, default_value, linked_visual_parameters)+ self._parameters.append(workflow_input)+ return ParameterRef(name, workflow_input)
def add_integer_parameter(self, name: str, label: str, description: str, default_value: int = 0,
- minimum_value: int = None, maximum_value: int = None):+ minimum_value: int = None, maximum_value: int = None,+ linked_visual_parameters: Dict[ParameterState, VisualEnum] = None):
"""
Adds a integer parameter to the workflow description.
This will generate an integer number field in the workflow UI.
+ **Example**:++ Add an integer parameter:++ .. code-block:: python+ pwr_description.add_integer_parameter(name='int', label='int_input', description='int_input', default_value=0)++ **Example**:++ Add an integer parameter that is only visible in the UI when the linked boolean reference is set to True:++ .. code-block:: python+ linked_bool_ref = pwr_description.add_boolean_parameter(name="linked_bool", label="linked_bool", description="linked_bool", default_value=False)+ linked_visual_parameters = {ParameterState(linked_bool_ref, True): VisualEnum.Visible}+ pwr_description.add_integer_parameter(name='int', label='int_input', description='int_input', default_value=0, linked_visual_parameters=linked_visual_parameters)+
Args:
name (str): The name of the object created the parameters dictionary. This name must be unique within the workflow.
label (str): The label text that will be displayed next to the field in the workflow UI.
description (str): A description of what the parameter represents. This description will be shown in the tooltip next to the field in the workflow UI.
default_value (int, optional): If defined this specifies the default value to be assigned to the parameter. Defaults to 0.
minimum_value (int, optional): If defined this specifies the lowest value the field can accept. Defaults to None.
maximum_value (int, optional): If defined this specifies the highest value the field can accept. Defaults to None.
+ linked_visual_parameters (Dict[ParameterState, VisualEnum], optional): Use this to specify a link between another boolean, enum or object_ref parameter state and this parameter's visual state.+ If the linked visual parameter have correct state the parameter will be enabled/visible accordingly.+ If adding multiple linked visual parameters, all must be true for the parameter to be enabled/visible.+ Defaults to None.++ Returns:+ ParameterRef: a reference to the parameter that was added
Raises:
ValueError: If the name is already used in the workflow.
"""
- valid = self._is_common_parameters_valid(name, label, description)+ valid = self._is_common_parameters_valid(name, label, description, linked_visual_parameters)
if not valid[0]:
self._is_valid = False
self._error_message = valid[1]
raise ValueError(self._error_message)
if not isinstance(default_value, int):
self._is_valid = False
@@ -164,44 +294,68 @@
self._error_message = f"Parameter {name}: default_value must be a int or None"
raise ValueError(self._error_message)
if maximum_value and not isinstance(maximum_value, int):
self._is_valid = False
self._error_message = f"Parameter {name}: maximum_value must be a int or None"
raise ValueError(self._error_message)
- self._parameters.append(IntegerWorkflowInput(name, label, description, default_value,- minimum_value, maximum_value))- return self+ workflow_input = IntegerWorkflowInput(name, label, description, default_value, minimum_value, maximum_value, linked_visual_parameters)+ self._parameters.append(workflow_input)+ return ParameterRef(name, workflow_input)
def add_float_parameter(self, name: str, label: str, description: str, default_value: float = 0.0,
minimum_value: float = None, maximum_value: float = None,
measurement_type: Union[MeasurementNamesEnum, str] = None,
- display_symbol: str = None):+ display_symbol: str = None,+ linked_visual_parameters: Dict[ParameterState, VisualEnum] = None):
"""Adds a float parameter to the workflow description.
This will generate an float number field in the workflow UI.
+ **Example**:++ Add a float parameter:++ .. code-block:: python+ pwr_description.add_float_parameter(name='float', label='float_input', description='float_input', default_value=0.0)++ **Example**:++ Add a float parameter that is only visible in the UI when the linked boolean reference is set to True:++ .. code-block:: python+ linked_bool_ref = pwr_description.add_boolean_parameter(name="linked_bool", label="linked_bool", description="linked_bool", default_value=False)+ linked_visual_parameters = {ParameterState(linked_bool_ref, True): VisualEnum.Visible}+ pwr_description.add_float_parameter(name='float', label='float_input', description='float_input', default_value=0.0, linked_visual_parameters=linked_visual_parameters)+
Args:
name (str): The name of the object created the parameters dictionary. This name must be unique within the workflow.
label (str): The label text that will be displayed next to the field in the workflow UI.
description (str): A description of what the parameter represents. This text will be shown in the tooltip next to the field in the workflow UI.
default_value (float, optional): If defined this specifies the default value to be assigned to the parameter. Defaults to 0.
minimum_value (float, optional): If defined this specifies the lowest value the field can accept. Defaults to None.
maximum_value (float, optional): If defined this specifies the highest value the field can accept. Defaults to None.
measurement_type (Union[MeasurementNamesEnum, str], optional): If defined this specifies the measurement type of the parameter. Defaults to None.
display_symbol (str, optional): If defined this specifies the units of the supplied parameter.
This allows the workflow to ensure that the parameter will be in the given units irrespective of the display units in the Petrel project.
Defaults to None.
-+ linked_visual_parameters (Dict[ParameterState, VisualEnum], optional): Use this to specify a link between another boolean, enum or object_ref parameter state and this parameter's visual state.+ If the linked visual parameter have correct state the parameter will be enabled/visible accordingly.+ If adding multiple linked visual parameters, all must be true for the parameter to be enabled/visible.+ Defaults to None.++ Returns:+ ParameterRef: a reference to the parameter that was added+
Raises:
ValueError: If the name is already used in the workflow.
ValueError: If the measurement_type is not MeasurementNamesEnum or a str
"""
- valid = self._is_common_parameters_valid(name, label, description)+ valid = self._is_common_parameters_valid(name, label, description, linked_visual_parameters)
if not valid[0]:
self._is_valid = False
self._error_message = valid[1]
raise ValueError(self._error_message)
if not isinstance(default_value, float) and not isinstance(default_value, int):
self._is_valid = False
@@ -251,68 +405,117 @@
if minimum_value is not None:
_minimum_value = float(minimum_value)
_maximum_value = None
if maximum_value is not None:
_maximum_value = float(maximum_value)
- self._parameters.append(DoubleWorkflowInput(name, label, description, _default_value,- _minimum_value, _maximum_value,- measurement_name,- display_symbol))- return self+ workflow_input = DoubleWorkflowInput(name, label, description, _default_value,+ _minimum_value, _maximum_value,+ measurement_name,+ display_symbol,+ linked_visual_parameters)+ self._parameters.append(workflow_input)+ return ParameterRef(name, workflow_input)- def add_string_parameter(self, name: str, label: str, description: str, default_value: str = ""):+ def add_string_parameter(self, name: str, label: str, description: str, default_value: str = "", linked_visual_parameters: Dict[ParameterState, VisualEnum] = None):
"""
Adds a string parameter to the workflow description.
This will generate a text field in the workflow UI.
+ **Example**:++ Add a string parameter to input a string:++ .. code-block:: python+ pwr_description.add_string_parameter(name='string', label='string_input', description='string_input', default_value='Please type someting here')++ **Example**:++ Add a string parameter that is only enabled in the UI when the linked boolean reference is set to True:++ .. code-block:: python+ linked_bool_ref = pwr_description.add_boolean_parameter(name="linked_bool", label="linked_bool", description="linked_bool", default_value=False)+ linked_visual_parameters = {ParameterState(linked_bool_ref, True): VisualEnum.Enabled}+ pwr_description.add_string_parameter(name='string', label='string_input', description='string_input', default_value='You can only type here after checking the checkbox', linked_visual_parameters=linked_visual_parameters)+
Args:
name (str): The name of the object created the parameters dictionary. This name must be unique within the workflow.
label (str): The label text that will be displayed next to the text field in the workflow UI.
description (str): A description of what the parameter is used for. This description will be shown in the tooltip next to the text field in the workflow UI.
default_value (str, optional): The default value to be assigned to the parameter.
+ linked_visual_parameters (Dict[ParameterState, VisualEnum], optional): Use this to specify a link between another boolean, enum or object_ref parameter state and this parameter's visual state.+ If the linked visual parameter have correct state the parameter will be enabled/visible accordingly.+ If adding multiple linked visual parameters, all must be true for the parameter to be enabled/visible.+ Defaults to None.++ Returns:+ ParameterRef: a reference to the parameter that was added
Raises:
ValueError: If the name is already used in the workflow.
"""
- valid = self._is_common_parameters_valid(name, label, description)+ valid = self._is_common_parameters_valid(name, label, description, linked_visual_parameters)
if not valid[0]:
self._is_valid = False
self._error_message = valid[1]
raise ValueError(self._error_message)
if not isinstance(default_value, str):
self._is_valid = False
self._error_message = f"Parameter {name}: default_value must be a str"
raise ValueError(self._error_message)
- self._parameters.append(StringWorkflowInput(name, label, description, default_value))- return self+ workflow_input = StringWorkflowInput(name, label, description, default_value, linked_visual_parameters)+ self._parameters.append(workflow_input)+ return ParameterRef(name, workflow_input)- def add_enum_parameter(self, name: str, label: str, description: str, options: Dict[int, str], default_value: int = None):+ def add_enum_parameter(self, name: str, label: str, description: str, options: Dict[int, str], default_value: int = None, linked_visual_parameters: Dict[ParameterState, VisualEnum] = None):
"""
Adds a enum parameter to the workflow description.
This will generate a combobox in the workflow UI.
+ **Example**:++ Add an enum parameter to select between three options:++ .. code-block:: python+ pwr_description.add_enum_parameter(name='enum', label='enum_selector', description='enum_selector', options={1:"Option1", 2:"Option2", 3:"Option3"})++ **Example**:++ Add an enum parameter to select between three options that is only enabled in the UI when the linked boolean reference is set to True:++ .. code-block:: python+ linked_bool_ref = pwr_description.add_boolean_parameter(name="linked_bool", label="linked_bool", description="linked_bool", default_value=False)+ linked_visual_parameters = {ParameterState(linked_bool_ref, True): VisualEnum.Enabled}+ pwr_description.add_enum_parameter(name='enum', label='enum_selector', description='enum_selector', options={1:"Option1", 2:"Option2", 3:"Option3"}, linked_visual_parameters=linked_visual_parameters)+
Args:
name (str): The name of the object created the parameters dictionary. This name must be unique within the workflow.
label (str): The label text that will be displayed next to the text field in the workflow UI.
description (str): A description of what the parameter is used for. This description will be shown in the tooltip next to the combobox in the workflow UI.
options (Dict[int, str]): A dictionary of options where each option is described by a value and the text to be shown for it.
default_value (int, optional): The default value to be assigned to the parameter.
+ linked_visual_parameters (Dict[ParameterState, VisualEnum], optional): Use this to specify a link between another boolean, enum or object_ref parameter state and this parameter's visual state.+ If the linked visual parameter have correct state the parameter will be enabled/visible accordingly.+ If adding multiple linked visual parameters, all must be true for the parameter to be enabled/visible.+ Defaults to None.+ Returns:+ ParameterRef: a reference to the parameter that was added+
Raises:
ValueError: If the name is already used in the workflow.
"""
- valid = self._is_common_parameters_valid(name, label, description)+ valid = self._is_common_parameters_valid(name, label, description, linked_visual_parameters)
if not valid[0]:
self._is_valid = False
self._error_message = valid[1]
raise ValueError(self._error_message)
if not isinstance(options, dict):
self._is_valid = False
@@ -348,35 +551,59 @@
self._error_message = f"Parameter {name}: default_value must be a int"
raise ValueError(self._error_message)
if default_value not in valid_options.keys():
self._is_valid = False
self._error_message = f"Parameter {name}: default_value must be a defined option"
raise ValueError(self._error_message)
- self._parameters.append(EnumWorkflowInput(name, label, description, options, default_value))- return self+ workflow_input = EnumWorkflowInput(name, label, description, valid_options, default_value, linked_visual_parameters)+ self._parameters.append(workflow_input)+ return ParameterRef(name, workflow_input)- def add_file_parameter(self, name: str, label: str, description: str, file_extensions: str, select_multiple: bool = False):+ def add_file_parameter(self, name: str, label: str, description: str, file_extensions: str, select_multiple: bool = False, linked_visual_parameters: Dict[ParameterState, VisualEnum] = None):
"""
Adds a file parameter to the workflow description.
This will generate a file selection in the workflow UI.
+ **Example**:++ Add a file parameter to select a file:++ .. code-block:: python+ pwr_description.add_file_parameter(name='file', label='file_selector', description='file_selector', file_extensions='*.txt')++ **Example**:++ Add a file parameter to select multiple files that is only enabled in the UI when the linked boolean reference is set to True:++ .. code-block:: python+ linked_bool_ref = pwr_description.add_boolean_parameter(name="linked_bool", label="linked_bool", description="linked_bool", default_value=False)+ linked_visual_parameters = {ParameterState(linked_bool_ref, True): VisualEnum.Enabled}+ pwr_description.add_file_parameter(name='file', label='file_selector', description='file_selector', file_extensions='*.txt', select_multiple=True, linked_visual_parameters=linked_visual_parameters)+
Args:
name (str): The name of the object created the parameters dictionary. This name must be unique within the workflow.
label (str): The label text that will be displayed next to the text field in the workflow UI.
description (str): A description of what the parameter is used for. This description will be shown in the tooltip next to the text field in the workflow UI.
file_extensions (str): The file extensions supported.
select_multiple (bool, optional): Specifies if the parameter can contain multiple values. Defaults to False.
+ linked_visual_parameters (Dict[ParameterState, VisualEnum], optional): Use this to specify a link between another boolean, enum or object_ref parameter state and this parameter's visual state.+ If the linked visual parameter have correct state the parameter will be enabled/visible accordingly.+ If adding multiple linked visual parameters, all must be true for the parameter to be enabled/visible.+ Defaults to None.+ Returns:+ ParameterRef: a reference to the parameter that was added+
Raises:
ValueError: If the name is already used in the workflow.
"""
- valid = self._is_common_parameters_valid(name, label, description)+ valid = self._is_common_parameters_valid(name, label, description, linked_visual_parameters)
if not valid[0]:
self._is_valid = False
self._error_message = valid[1]
raise ValueError(self._error_message)
if not isinstance(file_extensions, str):
self._is_valid = False
@@ -384,75 +611,126 @@
raise ValueError(self._error_message)
if not isinstance(select_multiple, bool):
self._is_valid = False
self._error_message = f"Parameter {name}: select_multiple must be a bool"
raise ValueError(self._error_message)
- self._parameters.append(FileWorkflowInput(name, label, description, file_extensions, select_multiple))- return self+ workflow_input = FileWorkflowInput(name, label, description, file_extensions, linked_visual_parameters, select_multiple)+ self._parameters.append(workflow_input)+ return ParameterRef(name, workflow_input)- def add_folder_parameter(self, name: str, label: str, description: str):+ def add_folder_parameter(self, name: str, label: str, description: str, linked_visual_parameters: Dict[ParameterState, VisualEnum] = None):
"""
Adds a folder parameter to the workflow description.
This will generate a folder selection in the workflow UI.
+ **Example**:++ Add a folder parameter to select a folder:++ .. code-block:: python+ pwr_description.add_folder_parameter(name='folder', label='folder_selector', description='folder_selector')++ **Example**:++ Add a folder parameter to select a folder that is only enabled in the UI when the linked enum reference is set to "Value3":++ .. code-block:: python+ linked_enum_ref = pwr_description.add_enum_parameter(name="enum1", label="enum1", description="enum1", options={1:"Value1", 2:"Value2", 3:"Value3"}, default_value=1)+ linked_visual_parameters = {ParameterState(linked_enum_ref, 3): VisualEnum.Enabled}+ pwr_description.add_folder_parameter(name='folder', label='folder_selector', description='folder_selector', linked_visual_parameters=linked_visual_parameters)+
Args:
name (str): The name of the object created the parameters dictionary. This name must be unique within the workflow.
label (str): The label text that will be displayed next to the text field in the workflow UI.
description (str): A description of what the parameter is used for. This description will be shown in the tooltip next to the text field in the workflow UI.
+ linked_visual_parameters (Dict[ParameterState, VisualEnum], optional): Use this to specify a link between another boolean, enum or object_ref parameter state and this parameter's visual state.+ If the linked visual parameter have correct state the parameter will be enabled/visible accordingly.+ If adding multiple linked visual parameters, all must be true for the parameter to be enabled/visible.+ Defaults to None.++ Returns:+ ParameterRef: a reference to the parameter that was added
Raises:
ValueError: If the name is already used in the workflow.
"""
- valid = self._is_common_parameters_valid(name, label, description)+ valid = self._is_common_parameters_valid(name, label, description, linked_visual_parameters)
if not valid[0]:
self._is_valid = False
self._error_message = valid[1]
raise ValueError(self._error_message)
- self._parameters.append(FolderWorkflowInput(name, label, description))- return self++ workflow_input = FolderWorkflowInput(name, label, description, linked_visual_parameters)+ self._parameters.append(workflow_input)+ return ParameterRef(name, workflow_input)
def add_object_ref_parameter(self, name: str, label: str, description: str,
object_type: Union[DomainObjectsEnum, str],
template_type: Union[Iterable[Union[TemplateNamesEnum, str]], TemplateNamesEnum, str] = None,
measurement_type: Union[MeasurementNamesEnum, str] = None,
select_multiple: bool = False,
- linked_input_name: str = None):+ linked_input_name: str = None,+ linked_visual_parameters: Dict[ParameterState, VisualEnum] = None):
"""
Adds a string parameter to the workflow description.
This will generate a domain object selector (blue arrow control) in the workflow UI.
Note: If select_multiple is False then the parameter value will be set to the DROID of the selected domain object.
If select_multiple is True then the parameter value will be a list of DROIDs for the selected domain objects.
+ **Example**:++ Add a single object reference parameter to select a well object:++ .. code-block:: python+ pwr_description.add_object_ref_parameter(name='well', label='well_selector', description='well_selector', object_type=DomainObjectsEnum.Well)++ **Example**:++ Add two object reference parameters to select a well object and then select multiple well continuous log objects for the selected well. Both drop-downs are only set to be visible when the linked boolean parameter is set to True:++ .. code-block:: python+ linked_bool_ref = pwr_description.add_boolean_parameter(name="linked_bool", label="linked_bool", description="linked_bool", default_value=False)+ linked_visual_parameters = {ParameterState(linked_bool_ref, True): VisualEnum.Visible}+ well_ref = pwr_description.add_object_ref_parameter(name='well', label='well_selector', description='well_selector', object_type=DomainObjectsEnum.Well, select_multiple=False, linked_visual_parameters=linked_visual_parameters)+ well_log_ref = pwr_description.add_object_ref_parameter(name='well_log', label='well_log_selector', description='well_log_selector', object_type=DomainObjectsEnum.WellContinuousLog, select_multiple=True, linked_input_name='well')+
Args:
name (str): The name of the object created the parameters dictionary. This name must be unique within the workflow.
label (str): The label text that will be displayed next to the dropbox in the workflow UI.
description (str): A description of what the parameter is used for. This description will be shown in the tooltip next to the text field in the workflow UI.
object_type (Union[DomainObjectsEnum, str]): The domain object type that must be supplied for this parameter.
The workflow UI will limit the user to selecting only domain objects for this type.
template_type (Union[Iterable[Union[TemplateNamesEnum, str]], TemplateNamesEnum, str], optional): If defined this specifies the template types accepted for the parameter. Defaults to None.
measurement_type (Union[MeasurementNamesEnum, str], optional): If defined this specifies the measurement type accepted for the parameter. Defaults to None.
select_multiple (bool, optional): Specifies if the parameter can contain multiple values. Defaults to False.
linked_input_name (str, optional): If defined this specifies the name of another parameter defined in the workflow which must be specified to enable this parameter in the workflow UI.
Defaults to None.
+ linked_visual_parameters (Dict[ParameterState, VisualEnum], optional): Use this to specify a link between another boolean, enum or object_ref parameter state and this parameter's visual state.+ If the linked visual parameter have correct state the parameter will be enabled/visible accordingly.+ If adding multiple linked visual parameters, all must be true for the parameter to be enabled/visible.+ Defaults to None.++ Returns:+ ParameterRef: a reference to the parameter that was added
Raises:
ValueError: If the name is already used in the workflow.
ValueError: If the object_type is not DomainObjectsEnum or a str
ValueError: If the template_type is not Iterable[TemplateNamesEnum] or a Iterable[str] or TemplateNamesEnum or a str
ValueError: If the measurement_type is not MeasurementNamesEnum or a str
"""
- valid = self._is_common_parameters_valid(name, label, description)+ valid = self._is_common_parameters_valid(name, label, description, linked_visual_parameters)
if not valid[0]:
self._is_valid = False
self._error_message = valid[1]
raise ValueError(self._error_message)
object_name = None
if isinstance(object_type, DomainObjectsEnum):
@@ -514,42 +792,42 @@
if linked_input_name:
if not isinstance(linked_input_name, str):
self._is_valid = False
self._error_message = f"Parameter {name}: linked_input_name must be a str"
raise ValueError(self._error_message)
- self._parameters.append(ObjectRefWorkflowInput(name, label, description,- object_name,- template_names,- measurement_name,- select_multiple,- linked_input_name))- return self+ workflow_input = ObjectRefWorkflowInput(name, label, description, object_name, template_names, measurement_name, select_multiple, linked_input_name, linked_visual_parameters)+ self._parameters.append(workflow_input)+ return ParameterRef(name, workflow_input)
def is_valid(self) -> bool:
"""Returns a bool indicating if the workflow is valid
Returns:
bool: Indicates the if the workflow is valid
"""
if not self._is_valid:
return False
linked_names_valid = self._linked_names_valid()
if not linked_names_valid[0]:
raise ValueError(linked_names_valid[1])
++ linked_visual_parameters_valid = self._linked_visual_parameters_valid()+ if not linked_visual_parameters_valid[0]:+ raise ValueError(linked_visual_parameters_valid[1])
return True
def get_default_parameters(self) -> Dict[str, object]:
"""
Returns a dictionary of the default values for parameters required by the workflow.
- THis is useful when testing the workflow outside of PWR.+ This is useful when testing the workflow outside of PWR.
Returns:
Dict[str, object]: _description_
"""
try:
if not self.is_valid():
return None
@@ -565,15 +843,16 @@
if not isinstance(name, str):
raise ValueError(f"Parameter {name}: name must be a str")
item = next((x for x in self._parameters if x.get_name() == name), None)
if item is None:
raise ValueError(f"Parameter {name}: No parameter defined with '{name}'")
return item.get_label()
- def _is_common_parameters_valid(self, name: str, label: str, description: str) -> Tuple[bool, str]:++ def _is_common_parameters_valid(self, name: str, label: str, description: str, linked_visual_parameters) -> Tuple[bool, str]:
if not isinstance(name, str):
return (False, f"Parameter {name}: name must be a str")
item = next((x for x in self._parameters if x.get_name() == name), None)
if item is not None:
return (False, f"Parameter {name}: Parameter already defined with '{name}'")
elif name.lower() != name:
return (False, f"Parameter {name}: name must be lowercase")
@@ -586,30 +865,57 @@
raise ValueError(self._error_message)
if not isinstance(description, str):
self._is_valid = False
self._error_message = f"Parameter {name}: description must be a str"
raise ValueError(self._error_message)
+ if linked_visual_parameters:+ if not isinstance(linked_visual_parameters, dict):+ self._is_valid = False+ self._error_message = f"Parameter {name}: linked_visual_parameters must be a dict"+ raise ValueError(self._error_message)+ for key,value in linked_visual_parameters.items():+ if not isinstance(key, ParameterState):+ self._is_valid = False+ self._error_message = f"Parameter {name}: linked_visual_parameters dict key must be a ParameterState object"+ raise ValueError(self._error_message)+ if not isinstance(value, VisualEnum):+ self._is_valid = False+ self._error_message = f"Parameter {name}: linked_visual_parameters dict value must be a valid VisualEnum"+ raise ValueError(self._error_message)
return (True, "")
def _linked_names_valid(self) -> Tuple[bool, str]:
for parameter in self._parameters:
if isinstance(parameter, ObjectRefWorkflowInput):
linked_input_name = parameter.get_linked_input_name()
if linked_input_name:
if linked_input_name == parameter.get_name():
- return (False, f"Parameter '{parameter.get_name()}': cannot be is linked to itself in workflow {self._get_filepath()}")+ return (False, f"Parameter '{parameter.get_name()}': cannot be is linked to itself")
linked_parameter = next((x for x in self._parameters if x.get_name() == linked_input_name), None)
if linked_parameter is None:
- return (False, f"Parameter '{parameter.get_name()}': linked parameter '{linked_input_name}' is not defined in the workflow {self._get_filepath()}")+ return (False, f"Parameter '{parameter.get_name()}': linked parameter '{linked_input_name}' is not defined in the workflow")+ return (True, "")++ def _linked_visual_parameters_valid(self) -> Tuple[bool, str]:+ for parameter in self._parameters:+ linked_visual_parameters_dict = parameter.get_linked_visual_parameters()+ if not linked_visual_parameters_dict:+ continue+ for param_state in linked_visual_parameters_dict.keys():+ linked_param_name = param_state.parameter_ref.name+ if not linked_param_name in [x.get_name() for x in self._parameters]:+ return (False, f"Parameter '{parameter.get_name()}': linked visual parameter '{linked_param_name}' is not defined in the workflow")+ is_valid = param_state.is_valid()+ if not is_valid[0]:+ return (False, f"Parameter '{parameter.get_name()}': linked visual parameter key '{param_state}' is not valid in the workflow {self._get_filepath()}. {is_valid[1]}")
return (True, "")
-
class WorkflowInfo():
def __init__(self, description: WorkflowDescription):
self.is_valid = description.is_valid()
self.script_type = description._get_script_type()
self.filepath = description._get_filepath()
self.name = description._get_name()
- self.working_path = os.environ['pwr_working_path']+ self.working_path = os.environ['CEGAL_PWR_TASK_WORKING_PATH']