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

A small library for configuring modular applications.

Installation

pip install zookeeper

Components

The fundamental building blocks of Zookeeper are components. The @component decorator is used to turn classes into components. These component classes can have configurable fields, which are declared with the Field constructor and class-level type annotations. Fields can be created with or without default values. Components can also be nested, with ComponentFields, such that child componenents can access the field values defined on their parents.

For example:

from zookeeper import component

@component
class ChildComponent:
    a: int = Field()                          # An `int` field with no default set
    b: str = Field("foo")                     # A `str` field with default value `"foo"`

@component
class ParentComponent:
    a: int = Field()                          # The same `int` field as the child
    child: ChildComponent = ComponentField()  # A nested component field, of type `ChildComponent`

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

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

For example:

from zookeeper import configure

p = ParentComponent()

configure(
    p,
    {
        "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 @task decorator is used to define Zookeeper tasks and can be applied to any class that implements an argument-less run method. Such tasks can be run through the Zookeeper CLI, with parameter values passed in through CLI arguments (configure is implicitly called).

For example:

from zookeeper import cli, task

@task
class UseChildA:
    parent: ParentComponent = ComponentField()
    def run(self):
        print(self.parent.child.a)

@task
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 MNIST. 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.3.1.tar.gz (36.3 kB view details)

Uploaded Source

Built Distribution

zookeeper-1.3.1-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

Details for the file zookeeper-1.3.1.tar.gz.

File metadata

  • Download URL: zookeeper-1.3.1.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for zookeeper-1.3.1.tar.gz
Algorithm Hash digest
SHA256 8478bc807997d614ff3d5dca82e8e3a9ae6efaa93276ff18ed9db722e8e7fdaa
MD5 74b407fac20dd789da57400049c036e9
BLAKE2b-256 f3d2fc934aced97d478fd1714eef53fdc2e13c3c7f4e520eb4bf405732af9535

See more details on using hashes here.

File details

Details for the file zookeeper-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: zookeeper-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 43.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for zookeeper-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d69470caeaab8cf1509a6bed97c031bff163a4295a2b3abfbd8147b2c7c5c5e8
MD5 033bd40a85a8b8b06e260314e8bc3ed7
BLAKE2b-256 2ae33cdb2e4f90b975135b2338f4ba1dfacf0f89e3c275aa447fcf0cf3a3774c

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