taps.transformer¶
Transformer
¶
Bases: Protocol[IdentifierT]
Data transformer protocol.
A data transformer is used by the Engine
to
transform task parameters and results into alternative formats that are
more suitable for communication.
An object can be transformed using
transform()
which returns
an identifier. The identifier can then be provided to
resolve()
, the inverse of
transform()
, which returns
the original object.
Data transformer implementations can implement object identifiers in any manner, provided identifiers are serializable. For example, a simple identifier could be a UUID corresponding to a database entry containing the serialized object.
close
¶
Close the transformer.
The transformer is only closed by the client once the application has finished executing (or raised an exception).
transform
¶
Transform the object into an identifier.
Parameters:
-
obj
(T
) –Object to transform.
Returns:
-
IdentifierT
–Identifier object that can be used to resolve
obj
.
TransformerConfig
¶
PickleFileTransformer
¶
Pickle file object transformer.
Transforms objects by pickling the object and writing the pickled object to a file.
Parameters:
Source code in taps/transformer/_file.py
close
¶
is_identifier
¶
transform
¶
transform(obj: T) -> PickleFileIdentifier
Transform the object into an identifier.
Parameters:
-
obj
(T
) –Object to transform.
Returns:
-
PickleFileIdentifier
–Identifier object that can be used to resolve
obj
.
Source code in taps/transformer/_file.py
resolve
¶
resolve(identifier: PickleFileIdentifier) -> Any
Resolve an object from an identifier.
Parameters:
-
identifier
(PickleFileIdentifier
) –Identifier to an object.
Returns:
-
Any
–The resolved object.
Source code in taps/transformer/_file.py
PickleFileTransformerConfig
¶
Bases: TransformerConfig
PickleFileTransformer
plugin configuration.
Parameters:
get_transformer
¶
get_transformer() -> PickleFileTransformer
PickleFileIdentifier
¶
Bases: NamedTuple
Identifier type for the PickleFileTransformer
.
Parameters:
-
cache_dir
(ForwardRef('pathlib.Path')
, default:None
) – -
obj_id
(ForwardRef('uuid.UUID')
, default:None
) –
Attributes:
-
cache_dir
–Object directory.
-
obj_id
–Object ID.
ProxyTransformer
¶
ProxyTransformer(
store: Store[Any],
*,
async_resolve: bool = False,
extract_target: bool = False,
metrics_dir: str | None = None
)
Proxy object transformer.
Transforms objects into proxies which act as the identifier.
Parameters:
-
store
(Store[Any]
) –Store instance to use for proxying objects.
-
async_resolve
(bool
, default:False
) –Begin asynchronously resolving proxies when the transformer resolves a proxy (which is otherwise a no-op unless
extract_target=True
). Not compatible withextract_target=True
. -
extract_target
(bool
, default:False
) –When
True
, resolving an identifier (i.e., a proxy) will return the target object. Otherwise, the proxy is returned since a proxy can act as the target object. Not compatible withasync_resolve=True
. -
metrics_dir
(str | None
, default:None
) –If metrics recording on
store
isTrue
, then write the recorded metrics to this directory when this transformer is closed. Typically,close()
is only called on the transformer instance in the main TaPS process (i.e.,close()
is not called in worker processes) so only the metrics from the main process will be recorded.
Source code in taps/transformer/_proxy.py
close
¶
Close the transformer.
Source code in taps/transformer/_proxy.py
is_identifier
¶
transform
¶
transform(obj: T) -> Proxy[T]
Transform the object into an identifier.
Parameters:
-
obj
(T
) –Object to transform.
Returns:
-
Proxy[T]
–Identifier object that can be used to resolve
obj
.
resolve
¶
Resolve an object from an identifier.
Parameters:
-
identifier
(Proxy[T]
) –Identifier to an object.
Returns:
-
T | Proxy[T]
–The resolved object or a proxy of the resolved object depending on the setting of
extract_target
.
Source code in taps/transformer/_proxy.py
ProxyTransformerConfig
¶
Bases: TransformerConfig
ProxyTransformer
plugin configuration.
Parameters:
-
name
(Literal[str]
, default:'proxystore'
) –Transformer name.
-
connector
(ConnectorConfig
) –Connector configuration.
-
async_resolve
(bool
, default:False
) –Asynchronously resolve proxies. Not compatible with extract_target=True.
-
cache_size
(int
, default:16
) –cache size
-
extract_target
(bool
, default:False
) –Extract the target from the proxy when resolving the identifier. Not compatible with async_resolve=True.
-
metrics
(bool
, default:False
) –Enable recording operation metrics.
-
populate_target
(bool
, default:True
) –Populate target objects of newly created proxies.
Note
Extra arguments provided to this config will be passed as parameters
to the Store
.
get_transformer
¶
get_transformer() -> ProxyTransformer
Create a transformer from the configuration.