Skip to content

proxystore.factory

Factory implementations.

Factories are callable classes that wrap up the functionality needed to resolve a proxy, where resolving is the process of retrieving the object from wherever it is stored such that the proxy can act as the object.

Factory

Factory()

Bases: Generic[T]

Abstract Factory Class.

A factory is a callable object that when called, returns an object. The Proxy constructor takes an instance of a factory and calls the factory when the proxy does its just-in-time resolution.

Note

If a custom factory is not-pickleable, __getnewargs_ex__ may need to be implemented. Writing custom pickling functions is also beneifical to ensure that a pickled factory does not contain the object itself, just what is needed to resolve the object to keep the final pickled factory as small as possible.

Source code in proxystore/factory.py
def __init__(self) -> None:
    raise NotImplementedError

__call__

__call__() -> T

Alias Factory.resolve().

Source code in proxystore/factory.py
def __call__(self) -> T:
    """Alias [`Factory.resolve()`][proxystore.factory.Factory.resolve]."""
    return self.resolve()

resolve

resolve() -> T

Resolve and return object.

Source code in proxystore/factory.py
def resolve(self) -> T:
    """Resolve and return object."""
    raise NotImplementedError

SimpleFactory

SimpleFactory(obj: T)

Bases: Factory[T]

Simple Factory that stores object as class attribute.

Parameters:

  • obj (T) –

    Object to produce when factory is called.

Source code in proxystore/factory.py
def __init__(self, obj: T) -> None:
    self._obj = obj

__call__

__call__() -> T

Alias Factory.resolve().

Source code in proxystore/factory.py
def __call__(self) -> T:
    """Alias [`Factory.resolve()`][proxystore.factory.Factory.resolve]."""
    return self.resolve()

resolve

resolve() -> T

Return the object.

Source code in proxystore/factory.py
def resolve(self) -> T:
    """Return the object."""
    return self._obj

LambdaFactory

LambdaFactory(
    target: Callable[..., T], *args: Any, **kwargs: Any
)

Bases: Factory[T]

Factory that takes any callable object.

Parameters:

  • target (Callable[..., T]) –

    Callable object (function, class, lambda) to be invoked when the factory is resolved.

  • args (Any, default: () ) –

    Argument tuple for target invocation.

  • kwargs (Any, default: {} ) –

    Dictionary of keyword arguments for target invocation.

Source code in proxystore/factory.py
def __init__(
    self,
    target: Callable[..., T],
    *args: Any,
    **kwargs: Any,
) -> None:
    self._target = target
    self._args = args
    self._kwargs = kwargs

__call__

__call__() -> T

Alias Factory.resolve().

Source code in proxystore/factory.py
def __call__(self) -> T:
    """Alias [`Factory.resolve()`][proxystore.factory.Factory.resolve]."""
    return self.resolve()

resolve

resolve() -> T

Return the target object.

Source code in proxystore/factory.py
def resolve(self) -> T:
    """Return the target object."""
    return self._target(*self._args, **self._kwargs)