-
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
Support list as pipeline parameter expression #147
Changes from all commits
fe50028
f7a084c
3965ef9
ca128bf
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from typing import Any, Dict, List, TypedDict, Union | ||
from typing import Any, Dict, List, Optional, TypedDict, Union | ||
|
||
from valohai_yaml.objs import ( | ||
Config, | ||
|
@@ -14,6 +14,16 @@ | |
ConvertedObject = Dict[str, Any] | ||
|
||
|
||
class VariantExpression(TypedDict): | ||
"""Variant expression template.""" | ||
|
||
style: str | ||
rules: Dict[str, Any] | ||
|
||
|
||
ExpressionValue = Union[str, int, bool, float, VariantExpression] | ||
|
||
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. How would this 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. Backend accepts variant expressions as parameter values, and it is the only way it accepts list parameters. The format works for all parameter value types though. Valohai-utils is not involved in this part of the process at all. We pass a list in structured format to backend, and backend receives a list in structured format and keeps it as a list. When the execution is prepared by backend, if you pass a list parameter as a command line parameter and parse command line parameters in a Python script using You can also use file based configuration to read the structured list parameter as JSON ( |
||
|
||
class ConvertedPipeline(TypedDict): | ||
"""TypedDict for converted Pipeline object.""" | ||
|
||
|
@@ -30,9 +40,11 @@ def __init__( | |
*, | ||
config: Config, | ||
commit_identifier: str, | ||
parameter_arguments: Optional[Dict[str, Union[str, list]]] = None, | ||
) -> None: | ||
self.config = config | ||
self.commit_identifier = commit_identifier | ||
self.parameter_arguments = parameter_arguments or {} | ||
|
||
def convert_pipeline(self, pipeline: Pipeline) -> ConvertedPipeline: | ||
return { | ||
|
@@ -43,9 +55,17 @@ def convert_pipeline(self, pipeline: Pipeline) -> ConvertedPipeline: | |
|
||
def convert_parameter(self, parameter: PipelineParameter) -> ConvertedObject: | ||
"""Convert a pipeline parameter to a config-expression payload.""" | ||
param_value: Union[ExpressionValue, List[str]] | ||
if parameter.name in self.parameter_arguments: | ||
param_value = self.parameter_arguments[parameter.name] | ||
elif parameter.default is not None: | ||
param_value = parameter.default | ||
else: | ||
param_value = "" | ||
|
||
return { | ||
"config": {**parameter.serialize()}, | ||
"expression": parameter.default if parameter.default is not None else "", | ||
"expression": self.convert_expression(param_value), | ||
} | ||
|
||
def convert_node(self, node: Node) -> ConvertedObject: | ||
|
@@ -102,3 +122,11 @@ def convert_executionlike_node( | |
} | ||
|
||
return node_data | ||
|
||
def convert_expression(self, expression: Union[ExpressionValue, list]) -> ExpressionValue: | ||
if isinstance(expression, list): | ||
return VariantExpression( | ||
style="single", | ||
rules={"value": expression}, | ||
) | ||
return expression |
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.
where does this come from in practice?
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 added pipeline argument parsing when converting for a future CLI enhancement. This PR lets you send lists as pipeline parameters if you make the values you want default in YAML config, but CLI needs some extra stuff to let you specify what you want to send and override the defaults. That extra stuff should also get converted right away, so we don't need to reimplement the conversion on CLI end.