zetta_utils.builder

Overview

zu.builder provides machinery to represent layers, datasets, or any other registered components as dictionaries. This can be used to pass in flexible parameters to CLI tools and to allow flexible, readable specifications of training and inference workflow through json/yaml/cue fields.

Use builder.register() to make a callable accessibule with zu.builder:

>>> from zetta_utils import builder
>>> @builder.register("MyClass")
... class MyClass:
...    def __init__(self, a):
...       self.a = a

After a callable is registered, you can represent them as dictionaries by including the matching @type key and providing the initialization parameters:

>>> spec = {
...    "@type": "MyClass",
...    "a": 100
... }
>>> obj = builder.build(spec)
>>> print (type(obj))
<class 'MyClass'>
>>> print (obj.a)
100

All user-facing zetta_utils objects are all registered with zu.builder. You can check out the state of the current registry by inspecting zu.builder.REGISTRY

API reference

zetta_utils.builder.register(name, allow_partial=True, allow_parallel=True, versions='>=0.0.0')[source]

Decorator for registering classes to be buildable.

Parameters
  • name (str) – Name which will be used for to indicate an object of the decorated type.

  • allow_partial (bool) – Whether to allow @mode: "partial".

Return type

Callable[[~T], ~T]

zetta_utils.builder.get_matching_entry(name, version='0.0.0')[source]
Return type

RegistryEntry

zetta_utils.builder.unregister(name, fn, allow_partial=True, allow_parallel=True, versions='>=0.0.0')[source]
zetta_utils.builder.build(spec=None, path=None, parallel=False)[source]

Build an object from the given spec.

Parameters

spec (UnionType[dict, list, None]) – Input dictionary.

Return type

Any

Returns

Object build according to the specification.