Skip to main content
https://img.shields.io/pypi/v/modularyze.svg https://img.shields.io/travis/jungerm2/modularyze.svg Documentation Status

Modularyze is a modular, composable and dynamic configuration engine that mixes the power of dynamic webpage rendering with that of YAML. It relies on Jinja and ruamel.yaml and inherits their flexibility.

Quick Start

Installation

To install the latest version of modularyze, run this command in your terminal:

$ pip install modularyze

Example

The Modularize package exposes one central config-builder class called ConfBuilder. Using this class you can register arbitrary constructors and callables, render templated multi-file and dynamic configs, instantiate them and compare configs by hash or their normalized form.

To use modularyze in a project simply import it, register any callables your config might be using and point it to your configuration file. From there you can simply call build to build the config.

A simple example where we instantiate a machine learning pipeline could look something like this:

# File: imagenet.yaml

{% set use_pretrained = use_pretrained | default(True) %}
{% set imagenet_root = imagenet_root | default('datasets/imagenet') %}

network: &network
    !torchvision.models.resnet18
    pretrained: {{ use_pretrained }}

val_transforms: &val_transforms
    !torchvision.transforms.Compose
    - !torchvision.transforms.Resize [256]
    - !torchvision.transforms.CenterCrop [224]
    - !torchvision.transforms.ToTensor

dataset: &dataset
    !torchvision.transforms.datasets.ImageNet
    args:
      - {{ imagenet_root }}
    kwargs:
      split: 'val'
      transforms: *val_transforms
import torchvision
from modularyze import ConfBuilder

builder = ConfBuilder()
builder.register_multi_constructors_from_modules(torchvision)
conf = builder.build('imagenet.yaml')

Now the conf object is a python dictionary containing a fully initialized model, dataset and validation transforms. What about if you want to change a parameter on the fly? Say the imagenet folder changes? Easy, simply pass in a context:

conf = builder.build('imagenet.yaml', context={"imagenet_root": "new/path/to/dataset"})

In this way ypu can easily parameterize you configuration files. The provided context is usually a dictionary but it can even be the path to a (non-parameterized/vanilla) YAML file.

What about if we have the configuration for a model trainer in a different file? Imagine the file trainer.yaml instantiates a neural network trainer instance, we can include it by adding the following line to the above config file:

{% include 'trainer.yaml' %}

There are many more neat things you can do when you combine the powers of YAML and Jinja, please refer to the documentation for more.

Metadata

Release files for modularyze 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modularyze 0.1.0
File Size Uploaded
modularyze-0.1.0.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for modularyze 0.1.0
File Interpreter ABI Platform
modularyze-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.7 kB

Release files / modularyze-0.1.0.tar.gz

Download URL modularyze-0.1.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1132b7b433c3d14ee1150b2cfe955b8b44a8486dbb1731853bb3175c81d9d9d6
BLAKE2b-256 checksum
How to use checksums
731ddc23c622cee45a38be9b18315039419f7209680c57ae99e93fc607e9e69e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.3 Windows/10

Release files / modularyze-0.1.0-py3-none-any.whl

Download URL modularyze-0.1.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
477a8e75676d9f338616d454ea1159eff0e7d3d0e22eeab08fd49adb0f3b9455
BLAKE2b-256 checksum
How to use checksums
999d38ad931fac912872fcea1659231feb3d59a466596ccc764703e72a34c669
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.3 Windows/10

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page