Attributes
Parameter
A wrapper for pipeline parameters that can be loaded from and saved to YAML files.
This class is meant to be used to create class-level attributes of your Pipe subclass (see example below).
When used in this way, Parameter objects can be treated syntactically like the value that they contain.
Examples:
Example
class A(Pipe):
p = Parameter('pname', default=0)
def run(self) -> None:
# `p` can be used like a regular class attribute.
print(self.p)
self.p += 1
print(self.p)
__init__(self, name, **kwargs)
special
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str |
Identifier for the parameter. If loading the value from a YAML config file, this needs to match the corresponding field name. |
required |
default |
( The type of this value must be serializable to a YAML file -- it cannot be a function or a class. An error will be raised if the type is not allowed. |
required |
Product
A wrapper for the inputs/outputs of Pipe subclasses.
The saving/loading behavior is altered by passing various flags to __init__.
By default, products passed into @produces will be pickled to the WARP cache location
associated with the active session at runtime.
Similarly, products passed into @dependencies will be unpickled
Custom saving/loading functions can be attached to a Product if pickling is not desired.
Note
The topology of the Graph is implicitly defined by passing Product instances to the
@dependencies and @produces decorators in the
Pipe declaration.
Tip
Product provides the custom syntax <<<, which is shorthand for assigning a value to the Product.value attribute.
Example
p = Product('p')
p << 0
p.value = 0 # equivalent
Info
Product contains the following class-level attributes that change the behavior of
Workspace.build.
__source__: The name of the pipe that produced this product.__static__: Specifies whether or not to cache the product statically.__external__: Specifies whether or not to cache the product externally.__save__: Specifies whether to cache the product or to leave it in working memory.
path: str
property
readonly
The correctly resolved path to the Product based on the state of the __external__ and __static__ attributes.
Warning
The correct WARP cache location for the current session must still be resolved, which can be done via
path.format(warp.globals.product_dir()).
__init__(self, path, *, static=False, external=False, save=None, load=None)
special
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str |
The relative path to save the product value to after the By default, this path will be appended to the path corresponding to the current WARP session directory in the WARP cache.
Both
|
required |
static |
bool |
Flag to mark this product as static, meaning that this product will be visible to other sessions.
Unless |
False |
external |
bool |
Flag to mark this product as external, meaning that its InfoThis flag is used by the implementation of |
False |
save |
Union[bool, function] |
|
None |
load |
Optional[function] |
|
None |
ParameterFile
A wrapper for declaring a config file to load Parameter values from.
This config file should contain at least one field that corresponds to a parameter of the pipe in which this config is used.
This should be used as a class-level attribute of your Pipe subclass.
Examples:
class A(Pipe):
# Must have a field `p_field` e.g. `p_field: 0`
config = ParameterFile('../configs/A.yml')
p = Parameter('p_field')
def run(self) -> None:
# The value from the config file.
# In this case, the output will be `p value 0`.
print('p value: ', p)
__init__(self, path, multi_use=False)
special
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str |
File path to a valid YAML file with fields matching |
required |
multi_use |
bool |
Flag to allow a config file to be used by more than just this pipe. In such cases, each pipe declaring this config file must use this flag. |
False |