Ornamentalist
Ornamentalist is a tiny library for configuring functions with fixed hyperparameters in Python. The goal is to allow research code to be more flexible and hackable, without losing readability.
The core thing ornamentalist does is it allows you to specify the parameters of a function as Configurable. You can then use the ornamentalist.configure() decorator to replace the function with a partial version of itself. The new partial function has all configurable parameters fixed to values supplied by you at the start of the program. This pattern allows you to avoid the work of plumbing hyperparameters around your code, without resorting to global variables or config God-objects.
You can use ornamentalist alongside your favourite configuration libraries like argparse or hydra. We also provide the optional ornamentalist.cli() feature, which automatically generates a CLI for your program.
I encourage you to read the short blog post to better understand the motivation behind this libary and why I think ornamentalist is a good solution. For worked examples of how to use ornamentalist with other tools such as hydra, argparse, or submitit, check out the examples/ directory.
You can install ornamentalist with pip:
pip install ornamentalist
Ornamentalist is only 1-file, so feel free to copy-paste it into your projects if you prefer.
Usage
Using ornamentalist is straightforward:
- Mark hyperparameters as configurable by setting their default value to
ornamentalist.Configurable. - Decorate the function with
@ornamentalist.configure(). - Create a config dictionary at the start of your program (either with
ornamentalist.cli()or your favourite configuration tool). - Call
ornamentalist.setup(config)before running any configurable functions.
Quickstart
Tip: You can find this file in examples/basics.py. Download and play with it to get a feel for ornamentalist :).
import ornamentalist
from ornamentalist import Configurable
# basic usage of ornamentalist...
# setting verbose=True is useful for debugging
@ornamentalist.configure(verbose=True)
def add_n(x: int, n: int = Configurable):
print(x + n)
# by default, ornamentalist looks for parameters
# in CONFIG_DICT[func.__name__],
# you can override this with a custom key like so
@ornamentalist.configure(name="greeting_config")
def greet(name: str = Configurable):
print(f"Hello, {name}")
# you can even use ornamentalist on classes!
class MyClass:
# you probably want to give constructors custom
# names, else they will just be "__init__"
@ornamentalist.configure(name="myclass.init")
def __init__(self, a: float = Configurable):
print(a)
if __name__ == "__main__":
# you can manually supply config with argparse, hydra etc.
# we also provide ornamentalist.cli() to automatically
# generate a basic CLI.
# But we will hardcode it for this example...
config = {
"add_n": {"n": 5},
# greeting_config and myclass_init are the
# custom names we specified earlier
"greeting_config": {"name": "Alice"},
"myclass.init": {"a": 4.5},
}
ornamentalist.setup(config)
add_n(10)
greet()
MyClass()
# you can access the config dict anywhere in your program
# through `ornamentalist.get_config()`
assert ornamentalist.get_config() == config
Examples
Ornamentalist is a simple library! You can learn the whole thing by reading through these examples:
examples/basics.pyteaches you the basic usage of ornamentalist (as seen above).examples/submitit_basic.pyshows you a simple pattern for launching ornamentalist jobs with submitit.examples/cli.pydemonstrates how to use the automatic CLI generation feature (with example outputs).examples/diffusion_transformeris an example of a full research codebase using ornamentalist.
Release files for ornamentalist 2.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ornamentalist-2.2.0.tar.gz | 6.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ornamentalist-2.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.0 kB
Release files / ornamentalist-2.2.0.tar.gz
| Download URL | ornamentalist-2.2.0.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a42debd32461fd354df75920c22f0dcbc1888e4d1a66dddf74b3d6a584bbe65
|
|
BLAKE2b-256 checksum How to use checksums |
7fc448773de9a8fb88d5c635274aa4f73db4a3ac1056dae93b1251837ad68726
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|
Release files / ornamentalist-2.2.0-py3-none-any.whl
| Download URL | ornamentalist-2.2.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0582ee829503a312ca79e89247124891080ed18b51f91cc338e35b6baeeb3ef8
|
|
BLAKE2b-256 checksum How to use checksums |
3e9875f8eb76a8f878e25e79116e70b5f9274665858b7bcf2c654cc64a0b6a1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|