Skip to main content

Configuration primitives and utilities for Python projects

Project description

pconfigs

A Python library for reproducible research.

Most ML codebases are split into experiment code, main scripts, and config text files. As the codebase evolves, the experiment and main script code change, the config text drifts out of sync, and results become difficult to reproduce. New experiments can also be difficult to implement because the main script must anticipate future experiments; when the main script cannot express the next experiment, large parts of the system must be rewritten. In practice, rewrites are postponed with an unsustainable patchwork of defaults, overrides, and options. Meanwhile, config text is scattered across external file systems or servers, and the truth of what will run becomes difficult for humans and agents to infer. pconfigs solves these problems by replacing config text with Python config files that live in the repo alongside the code, and fully specify the experiment, main, and config together — they can be executed, constructed, printed to reveal the fully resolved configuration of every submodule, and tested to ensure they stay valid as the codebase evolves.

Documentation

Installation

pip install pconfigs

Example

from __future__ import annotations

from pconfigs import pconfig, pconfiged

@pconfiged(runnable=True)                # Runnable means this class will have a main().
class Trainer:
    config: TrainerConfig                # Typehint the config type for the class.

    def main(self, *args, **kwargs):
        print(self.config.message)       # The config is available at runtime.


@pconfig(constructs=Trainer)             # This config constructs a Trainer class.
class TrainerConfig:
    message: str                         # All config parameters are typehinted.
    lr: float


config = TrainerConfig(                  # Create an experiment.
    message="Hello, World!",
    lr=1e-5,
)

Run an experiment:

$ python -m pconfigs.run base.experiment.config

Derive a new experiment from an existing one:

from base.experiment import config as base

config = TrainerConfig(
    base,      # Auto-copy all parameters from base.
    lr=1e-4,   # Change only the learning rate.
)

Print the fully resolved config as Python code:

$ python -m pconfigs.print new.experiment.config > printed_config.py

See the quickstart for a complete walkthrough.

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pconfigs-0.1-py3-none-any.whl (170.4 kB view details)

Uploaded Python 3

File details

Details for the file pconfigs-0.1-py3-none-any.whl.

File metadata

  • Download URL: pconfigs-0.1-py3-none-any.whl
  • Upload date:
  • Size: 170.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pconfigs-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 333a35ef04431970d6f21eead528eaffbe5396ff5429ea564e77ad8bff777f95
MD5 77f67b2f020225e3c4681b1c639306d9
BLAKE2b-256 17a9afe0691af9321799b11b2aaaac8bd85dced41eedbbfd2c1275eeb86deec0

See more details on using hashes here.

Supported by

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