fluidml.storage¶
- class fluidml.storage.File(path, mode, save_fn, load_fn, open_fn=None, load_kwargs=None, **open_kwargs)[source]¶
Bases:
object
A file like wrapper class to support opening files using the
LocalFileStore
.- Parameters:
path (str) – The path to the file to open.
mode (str) – The open mode, e.g. “r”, “w”, etc.
save_fn (Callable) – A callable used for
file.save()
calls.load_fn (Callable) – A callable used for
file.load()
calls.open_fn (Optional[Callable]) – An optional callable used for file opening. The default is the inbuilt
open()
function.load_kwargs (Optional[Dict]) – Additional keyword arguments passed to the open function.
- property closed¶
- classmethod from_promise(promise)[source]¶
Creates a
File
object from a ´FilePromise`.- Parameters:
promise (FilePromise) –
- class fluidml.storage.FilePromise(name, path, save_fn, load_fn, open_fn=None, mode=None, load_kwargs=None, **open_kwargs)[source]¶
Bases:
Promise
- Parameters:
- class fluidml.storage.InMemoryStore(manager=None)[source]¶
Bases:
ResultsStore
An in-memory results store implemented using a dict.
When multiprocessing is used a
manager.dict()
is used for inter process communication. If no result store is provided toflow.run()
this in-memory store is the default.- Parameters:
manager (Optional[Manager]) –
- delete_run(task_name, task_unique_config)[source]¶
Method to delete all task results from a given run config
- get_context(task_name, task_unique_config)[source]¶
Wrapper to get store specific storage context, e.g. the current run directory for Local File Store
- Parameters:
- Returns:
The store context object holding information like the current run dir.
- Return type:
- class fluidml.storage.LazySweep(value, config)[source]¶
Bases:
object
A lazy variation of the
Sweep
class.- Parameters:
value (Promise) –
config (MetaDict) –
- config: MetaDict¶
The unique config of the object#s task.
- class fluidml.storage.LocalFileStore(base_dir)[source]¶
Bases:
ResultsStore
A local file store that allows to easily save and load task results to/from a base directory in a file system.
Out of the box the local file store supports three common file types, “json”, “pickle” and “text”. It can be easily extended to arbitrary file types by subclassing the LocalFileStore and registering new Types to the self._type_registry dictionary. A new type needs to register a load and save function using the
TypeInfo
data class.- Parameters:
base_dir (str) – The base directory that is used to store results from tasks.
- base_dir¶
The base directory that is used to store results from tasks.
- type_registry¶
The dictionary to register new types with a save and load function.
- delete(name, task_name, task_unique_config)[source]¶
Deletes an object from the local file store.
The object is deleted based on the name and the provided task name and unique task config.
- delete_run(task_name, task_unique_config)[source]¶
Deletes an entire task run directory from the local file store.
The run is deleted based on the task name and the unique task config.
- get_context(task_name, task_unique_config)[source]¶
Method to get the current task’s storage context.
E.g. the current run directory in case of LocalFileStore. Creates a new run dir if none exists.
- Parameters:
- Return type:
- load(name, task_name, task_unique_config, lazy=False, **kwargs)[source]¶
Loads an object from the local file store.
The object is retrieved based on the name and the provided task name and unique task config.
- Parameters:
name (str) – An unique name given to this object.
task_name (str) – Task name which saves the object.
task_unique_config (Dict) – Unique config which specifies the run of the object.
lazy (bool) – A boolean whether the object should be lazily loaded. If True, a
FilePromise
object will be returned, that can be loaded into memory on demand with thepromise.load()
function.**kwargs – Additional keyword arguments passed to the registered
load()
function.
- Returns:
The specified object if it is found.
- Return type:
- open(name=None, task_name=None, task_unique_config=None, mode=None, promise=None, type_=None, sub_dir=None, **open_kwargs)[source]¶
Wrapper to open a file from Local File Store (only available for Local File Store).
It returns a file like object that has additional
save()
andload()
methods that can be used to save/load objects with a registered type to/from the file store. TheFile
like object allows for an incremental write or read process of objects that for example don’t fit into memory.- Parameters:
task_name (Optional[str]) – Task name which saved the object.
task_unique_config (Optional[Dict]) – Unique config which specifies the run of the object.
promise (Optional[FilePromise]) – An optional
Promise
object used for creating the returned file like object.type_ (Optional[str]) – Additional type specification (e.g. json, which is to be passed to results store).
sub_dir (Optional[str]) – A path of a subdirectory used for opening the file.
**open_kwargs – Additional keyword arguments passed to the registered
open()
function.
- Returns:
A
File
object that wraps a file like object and enables incremental result store reading and writing.- Return type:
- property run_info¶
The current run info of a task, which is used for naming newly created directories.
- save(obj, name, type_, task_name, task_unique_config, sub_dir=None, mode=None, open_kwargs=None, load_kwargs=None, **kwargs)[source]¶
Saves an object to the local file store.
If no task and run directory for the provided unique config exists, a new directory will be created.
- Parameters:
obj (Any) – The object to save.
name (str) – An unique name given to this object.
type_ (str) – Additional type specification (e.g. json, which is to be passed to results store).
task_name (str) – Task name which saves the object.
task_unique_config (Dict) – Unique config which specifies the run of the object.
sub_dir (Optional[str]) – A path of a subdirectory used for saving the file.
mode (Optional[str]) – The mode to save the file, e.g. “w” or “wb”.
open_kwargs (Optional[Dict[str, Any]]) – Additional keyword arguments passed to the registered
open()
function.load_kwargs (Optional[Dict[str, Any]]) – Additional keyword arguments passed to the registered
load()
function.**kwargs – Additional keyword arguments passed to the registered
save()
function.
- class fluidml.storage.MongoDBStore(db, collection_name=None, host=None)[source]¶
Bases:
ResultsStore
A mongo db result store implementation.
- Parameters:
- delete(name, task_name, task_unique_config)[source]¶
Query method to delete an object based on its name, task_name and task_config if it exists
- delete_run(task_name, task_unique_config)[source]¶
Query method to delete a run document based on its task_name and task_config if it exists
- get_context(task_name, task_unique_config)[source]¶
Wrapper to get store specific storage context, e.g. the current run directory for Local File Store
- Parameters:
- Returns:
The store context object holding information like the current run dir.
- Return type:
- class fluidml.storage.Promise[source]¶
Bases:
ABC
An interface for future objects, that can be lazy loaded.
- class fluidml.storage.ResultsStore[source]¶
Bases:
ABC
The interface of a results store.
- abstract delete_run(task_name, task_unique_config)[source]¶
Method to delete all task results from a given run config
- abstract get_context(task_name, task_unique_config)[source]¶
Wrapper to get store specific storage context, e.g. the current run directory for Local File Store
- Parameters:
- Returns:
The store context object holding information like the current run dir.
- Return type:
- get_results(task_name, task_unique_config)[source]¶
Collects all saved results based that have been tracked when using
Task.save()
.
- abstract load(name, task_name, task_unique_config, **kwargs)[source]¶
Loads the given object from results store based on its name, task_name and task_config if it exists.
- Parameters:
- Returns:
The loaded object.
- Return type:
- property lock¶
- open(name=None, task_name=None, task_unique_config=None, mode=None, promise=None, type_=None, sub_dir=None, **open_kwargs)[source]¶
Method to open a file from Local File Store (only available for file stores).
- Parameters:
task_name (Optional[str]) – Task name which saved the object.
task_unique_config (Optional[Dict]) – Unique config which specifies the run of the object.
promise (Optional[Promise]) – An optional
Promise
object used for creating the returned file like object.type_ (Optional[str]) – Additional type specification (e.g. json, which is to be passed to results store).
sub_dir (Optional[str]) – A path of a subdirectory used for opening the file.
**open_kwargs – Additional keyword arguments passed to the registered
open()
function.
- Returns:
A
File
object that behaves like a file like object.
- abstract save(obj, name, type_, task_name, task_unique_config, **kwargs)[source]¶
Method to save/update any artifact.
- Parameters:
obj (Any) – The object to save/update
name (str) – The object name.
type_ (str) – The type of the object. Only required for file stores.
task_name (str) – The task name that saves/updates the object.
task_unique_config (Dict) – The unique config of that task.
**kwargs – Additional keyword arguments.
- class fluidml.storage.StoreContext(run_dir=None, sweep_counter=None)[source]¶
Bases:
object
The store context of the current task.
- class fluidml.storage.Sweep(value, config)[source]¶
Bases:
object
A sweep class holding the value and config of a specific task result.
List of Sweeps are the standard inputs for
reduce
tasks that gather results from grid search expanded tasks.- Parameters:
value (Any) –
config (MetaDict) –
- config: MetaDict¶
The unique config of the object#s task.
- class fluidml.storage.TypeInfo(save_fn, load_fn, extension=None, is_binary=None, open_fn=None, needs_path=False)[source]¶
Bases:
object
Initializes saving and loading information for a specific type.
- Parameters:
- needs_path: bool = False¶
false.
- Type:
Whether save and load fn should operate on path and not on file like object. Default