Backends#

Backends are responsible for storing and retrieving experiment data. A single backend is instantiated and associated with an experiment when it is created. By saving observations to disk, backends allow follow up experiments and anaylsis to be performed in future python sessions.

Available backends#

class digital_experiments.backends.PickleBackend(root: Path)#

The default backend for storing results.

Each observation is stored in <root>/<id>.pkl. The result and configuration of each observation can be (almost) any python object, provided it can be pickled.

class digital_experiments.backends.JSONBackend(root: Path)#

Each observation is stored in <root>/<id>.json. The result and configuration of each observation must be JSON-serializable to use this backend.

Select this backed using @experiment(backend="json").

class digital_experiments.backends.YAMLBackend(root: Path)#

Each observation is stored in <root>/<id>.yaml. The result and configuration of each observation must be YAML-serializable to use this backend.

Select this backed using @experiment(backend="yaml").

Creating your own backend#

Creating your own backend involves subclassing Backend, implementing the abstract methods, and registering your implementation so that you can subsequently use it by name.

digital_experiments.backends.register_backend(name: str)#

Use this decorator (along with subclassing Backend) to register a new custom backend.

Example

from digital_experiments import register_backend, Backend

@register_backend("my-backend")
class MyBackend(Backend):
    ...

@experiment(backend="my-backend")
def my_experiment():
    ...
class digital_experiments.backends.Backend(root: Path)#

Abstract base class for backends.

A backend is responsible for recording and loading Observation objects. All subclasses must override the record(), load(), and all_ids() methods.

Other methods are optional, but can be overridden to provide further custom behaviour.

abstract record(observation: Observation) None#

Record an Observation

abstract load(id: str) Observation#

Load an Observation by its id

abstract all_ids() list[str]#

Return a list of all ids currently stored in this backend

load_all() list[Observation]#

Load all Observation objects currently stored in this backend, sorted by id.

artefacts(id: str) list[Path]#

Get a list of artefacts associated with a particular observation.

Parameters:

id (str) – The id of the observation to get artefacts for