proxystore.store.base
Base Store Abstract Class.
StoreFactory ¶
StoreFactory(
key: KeyT,
store_type: type[Store[KeyT]],
store_name: str,
store_kwargs: dict[str, Any] | None = None,
*,
evict: bool = False,
deserializer: DeserializerT | None = None
) -> None
Bases: Factory[T]
, Generic[KeyT, T]
Base Factory for Stores.
Adds support for asynchronously retrieving objects from a
Store
.
The factory takes the store_type
and store_kwargs
parameters that are
used to reinitialize the store if the factory is sent to a remote
process where the store has not already been initialized.
Parameters:
-
key
(
KeyT
) –Key corresponding to object in store.
-
store_type
(
type[Store[KeyT]]
) –Type of store this factory will resolve an object from.
-
store_name
(
str
) –Name of store.
-
store_kwargs
(
dict[str, Any] | None
) –Optional keyword arguments used to reinitialize store.
-
evict
(
bool
) –If True, evict the object from the store once
resolve()
is called. -
deserializer
(
DeserializerT | None
) –Optional callable used to deserialize the byte string. If
None
, the default deserializer (deserialize()
) will be used.
Source code in proxystore/store/base.py
get_store ¶
Get store and reinitialize if necessary.
Raises:
-
ValueError
–If the type of the returned store does not match the expected store type passed to the factory constructor.
Source code in proxystore/store/base.py
resolve ¶
Get object associated with key from store.
Raises:
-
ProxyResolveMissingKeyError
–If the key associated with this factory does not exist in the store.
Source code in proxystore/store/base.py
resolve_async ¶
Store ¶
Store(
name: str,
*,
cache_size: int = 16,
stats: bool = False,
kwargs: dict[str, Any] | None
) -> None
Bases: Generic[KeyT]
Key-value store interface.
Provides base functionality for interaction with an object store including serialization and caching.
Subclasses of Store
must implement
create_key()
,
evict()
,
exists()
,
get_bytes()
, and
set_bytes()
. Subclasses may
implement close()
if needed.
The Store
handles caching and stores all
objects as key-bytestring pairs, i.e., objects passed to
get()
or
set()
will be
appropriately (de)serialized before being passed to
get_bytes()
or
set_bytes()
, respectively.
Parameters:
-
name
(
str
) –Name of the store instance.
-
cache_size
(
int
) –Size of LRU cache (in # of objects). If 0, the cache is disabled. The cache is local to the Python process.
-
stats
(
bool
) –Collect stats on store operations.
-
kwargs
(
dict[str, Any] | None
) –Additional keyword arguments to return from
Store.kwargs
. I.e., the additional keyword arguments needed to reinitialize this store.
Raises:
-
ValueError
–If
cache_size
is less than zero.
Source code in proxystore/store/base.py
close ¶
Cleanup any objects associated with the store.
Many Store
types do not have any
objects that requiring cleaning up so this method a no-op by default
unless overridden.
Warning
This method should only be called at the end of the program when the store will no longer be used, for example once all proxies have been resolved.
Source code in proxystore/store/base.py
create_key ¶
Create key for the object.
Parameters:
-
obj
(
Any
) –Object to be placed in store.
Returns:
-
KeyT
–A key.
evict
abstractmethod
¶
Evict object associated with key.
Parameters:
-
key
(
KeyT
) –The key corresponding to object in store to evict.
exists
abstractmethod
¶
Check if key exists.
Parameters:
-
key
(
KeyT
) –The key to check.
Returns:
-
bool
–If the key exists in the store.
get ¶
get(
key: KeyT,
*,
deserializer: DeserializerT | None = None,
default: object | None = None
) -> Any | None
Return object associated with key.
Parameters:
-
key
(
KeyT
) –The key corresponding to object.
-
deserializer
(
DeserializerT | None
) –Optional callable used to deserialize the byte string. If
None
, the default deserializer (deserialize()
) will be used. -
default
(
object | None
) –Optionally provide value to be returned if an object associated with the key does not exist.
Returns:
-
Any | None
–The object associated with key or
default
if key does not exist.
Source code in proxystore/store/base.py
get_bytes
abstractmethod
¶
Get serialized object from remote store.
Parameters:
-
key
(
KeyT
) –The key corresponding to the object.
Returns:
-
bytes | None
–The serialized object or
None
if it does not exist.
Source code in proxystore/store/base.py
is_cached ¶
Check if object is cached locally.
Parameters:
-
key
(
KeyT
) –The key corresponding to the object.
Returns:
-
bool
–If the object associated with the key is cached.
proxy ¶
proxy(
obj: T,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
**kwargs: Any
) -> Proxy[T]
Create a proxy that will resolve to an object in the store.
Warning
If the factory requires reinstantiating the store to correctly
resolve the object, the factory should reinstantiate the store
with the same arguments used to instantiate the store that
created the proxy/factory. I.e. the :func:proxy()
function
should pass any arguments given to :func:Store.__init__()
along to the factory so the factory can correctly recreate the
store if the factory is resolved in a different Python process.
Parameters:
-
obj
(
T
) –The object to place in store and return proxy for.
-
serializer
(
SerializerT | None
) –Optional callable which serializes the object. If
None
, the default serializer (serialize()
) will be used. -
deserializer
(
DeserializerT | None
) –Optional callable used by the factory to deserialize the byte string. If
None
, the default deserializer (deserialize()
) will be used. -
kwargs
(
Any
) –Additional arguments to pass to the Factory.
Returns:
-
Proxy[T]
–A proxy of the object.
Source code in proxystore/store/base.py
proxy_batch ¶
proxy_batch(
objs: Sequence[T],
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
**kwargs: Any
) -> list[Proxy[T]]
Create proxies for batch of objects in the store.
See Store.proxy()
for more
details.
Parameters:
-
objs
(
Sequence[T]
) –The objects to place in store and return proxies for.
-
serializer
(
SerializerT | None
) –Optional callable which serializes the object. If
None
, the default serializer (serialize()
) will be used. -
deserializer
(
DeserializerT | None
) –Optional callable used by the factory to deserialize the byte string. If
None
, the default deserializer (deserialize()
) will be used. -
kwargs
(
Any
) –additional arguments to pass to the Factory.
Returns:
Source code in proxystore/store/base.py
proxy_from_key ¶
Create a proxy to an object already in the store.
Note
This method will not verify that the key is valid so an error will not be raised until the returned proxy is resolved.
Parameters:
-
key
(
KeyT
) –The key corresponding to an object already in the store that will be the target object of the returned proxy.
-
deserializer
(
DeserializerT | None
) –Optional callable used by the factory to deserialize the byte string. If
None
, the default deserializer (deserialize()
) will be used. -
kwargs
(
Any
) –Additional arguments to pass to the Factory.
Returns:
-
Proxy[T]
–A proxy.
Source code in proxystore/store/base.py
locked_proxy ¶
locked_proxy(
obj: T,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
**kwargs: Any
) -> ProxyLocker[T]
Create a proxy locker that will prevent resolution.
Parameters:
-
obj
(
T
) –The object to place in store and create proxy of.
-
serializer
(
SerializerT | None
) –Optional callable which serializes the object. If
None
, the default serializer (serialize()
) will be used. -
deserializer
(
DeserializerT | None
) –Optional callable used by the factory to deserialize the byte string. If
None
, the default deserializer (deserialize()
) will be used. -
kwargs
(
Any
) –Additional arguments to pass to the Factory.
Returns:
-
ProxyLocker[T]
–A proxy wrapped in a
ProxyLocker
.
Source code in proxystore/store/base.py
set ¶
Set key-object pair in store.
Parameters:
-
obj
(
Any
) –The object to be placed in the store.
-
serializer
(
SerializerT | None
) –Optional callable which serializes the object. If
None
, the default serializer (serialize()
) will be used.
Returns:
-
KeyT
–A key that can be used to retrieve the object.
Raises:
-
TypeError
–If the output of
serializer
is not bytes.
Source code in proxystore/store/base.py
set_batch ¶
Set objects in store.
Parameters:
-
objs
(
Sequence[Any]
) –Iterable of objects to be placed in the store.
-
serializer
(
SerializerT | None
) –Optional callable which serializes the object. If
None
, the default serializer (serialize()
) will be used.
Returns:
-
list[KeyT]
–List of keys that can be used to retrieve the objects.
Raises:
-
TypeError
–If the output of
serializer
is not bytes.
Source code in proxystore/store/base.py
set_bytes
abstractmethod
¶
Set serialized object in remote store with key.
Parameters:
-
key
(
KeyT
) –The key corresponding to the object.
-
data
(
bytes
) –The serialized object.
Source code in proxystore/store/base.py
stats ¶
Get stats on the store.
Parameters:
-
key_or_proxy
(
KeyT | Proxy[T]
) –A key to get stats for or a proxy to extract the key from.
Returns:
-
dict[str, TimeStats]
–A dict with keys corresponding to method names and values which are
TimeStats
instances with the statistics for calls to the corresponding method with the specified key.
Example
Raises:
-
ValueError
–If
self
was initialized withstats=False
.