Skip to main content

A small library for managing deep learning models, hyper parameters and datasets

Project description

Zookeeper

GitHub Actions Codecov PyPI - Python Version PyPI PyPI - License Code style: black Join the community on Spectrum

A small library for configuring modular applications.

Installation

pip install zookeeper

Components

The fundamental building block of Zookeeper is a Component. Component subclasses can have configurable parameters, which are declared using class-level type annotations (in a similar way to Python dataclasses). These parameters can be Python objects or nested sub-components, and need not be set with a default value.

For example:

from zookeeper import Component

class ChildComponent(Component):
    a: int                  # An `int` parameter, with no default set
    b: str = "foo"          # A `str` parameter, which by default will be `foo`

class ParentComponent(Component):
    a: int                  # The same `int` parameter as the child
    child: ChildComponent   # A nested component parameter, of type `ChildComponent`

After instantiation, components can be 'configured' with a configuration dictionary, containing values for a tree of nested parameters. This process automatically injects the correct values into each parameter.

If a child sub-component declares a parameter which already exists in some containing parent, then it will pick up the value that's set on the parent, unless a 'scoped' value is set on the child.

For example:

p = ParentComponent()

p.configure({
    "a": 5,
    "child.a": 4,
})

>>> 'ChildComponent' is the only concrete component class that satisfies the type
>>> of the annotated parameter 'ParentComponent.child'. Using an instance of this
>>> class by default.

print(p)

>>> ParentComponent(
>>>     a = 5,
>>>     child = ChildComponent(
>>>         a = 4,
>>>         b = "foo"
>>>     )
>>> )

Tasks and the CLI

The best way to define runnable tasks with Zookeeper is to subclass Task and override the run method.

Zookeeper provides a small mechanism to run tasks from a CLI, using the decorator @add_task_to_cli. The CLI will automatically instantiate the task and call configure(), passing in configuration parsed from command line arguments.

For example:

from zookeeper import Task
from zookeeper.cli import add_task_to_cli, cli

@add_task_to_cli
class UseChildA(Task):
    parent: ParentComponent

    def run(self):
        print(self.parent.child.a)

@add_task_to_cli
class UseParentA(UseChildA):
    def run(self):
        print(self.parent.a)

if __name__ == "__main__":
    cli()

Running the above file then gives a nice CLI interface:

python test.py use_child_a
>>> ValueError: No configuration value found for annotated parameter 'UseChildA.parent.a' of type 'int'.

python test.py use_child_a a=5
>>> 5

python test.py use_child_a a=5 child.a=3
>>> 3

python test.py use_parent_a a=5 child.a=3
>>> 5

Using Zookeeper to define Larq or Keras experiments

See examples/larq_experiment.py for an example of how to use Zookeeper to define all the necessary components (dataset, preprocessing, and model) of a Larq experiment: training a BinaryNet on CIFAR-10. This example can be easily adapted to other Larq or Keras models and other datasets.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zookeeper-1.0.dev5.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

zookeeper-1.0.dev5-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file zookeeper-1.0.dev5.tar.gz.

File metadata

  • Download URL: zookeeper-1.0.dev5.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.5

File hashes

Hashes for zookeeper-1.0.dev5.tar.gz
Algorithm Hash digest
SHA256 9c65a4c95cc87ae591d49b8cc67d8b280b527a1817aa1d84d6204fdb6c9bddda
MD5 30dfb659ab4206856a9cb3ae7325f18d
BLAKE2b-256 c7d1fc3c4a9f11f86cdb9ff7d3fa953e2dab3f72bbdcdd6a8f2a5ac3e45be169

See more details on using hashes here.

File details

Details for the file zookeeper-1.0.dev5-py3-none-any.whl.

File metadata

  • Download URL: zookeeper-1.0.dev5-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.5

File hashes

Hashes for zookeeper-1.0.dev5-py3-none-any.whl
Algorithm Hash digest
SHA256 2836e483dba9959700fdc04972675c00b017ada360177b503aef477f919ed65d
MD5 a09653f7b34c0ed0f23c039c73822d2e
BLAKE2b-256 89ba1703b6a19ba25f92892d3dea3effd3539e2ef06bec4049d3fb8ba7e047ee

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page