Programmatic parameter sweeps for pydantic.
Project description
pydantic-sweep
pydantic_sweep is a library to programmatically, safely and flexibly define
complex parameter sweeps over pydantic models in Python.
Highlights:
- Specify parameter sweeps in Python
- Flexibility: specify complex parameter combinations by chaining simple functional operations
- Safety checks for parameter combinations (get meaningful errors early)
pydanticfield validation
For example, the following code will instantiate models with (x=5, sub=Sub1(s=1) and
(x=6, sub=Sub1(s=2) and try each of those with seed values of seed=43 and
seed=44, leading to four different configurations:
import pydantic_sweep as ps
class Sub1(ps.BaseModel):
s: int = 5
class Sub2(ps.BaseModel):
y: str = "hi"
class Model(ps.BaseModel):
seed: int = 42
x: int = 5
sub: Sub1 | Sub2
# We want to test across two seeds
configs = ps.config_product(
ps.field("seed", [43, 44]),
# And two specific Sub1 and `x` combinations
ps.config_zip(
ps.field("x", [ps.DefaultValue, 6]),
ps.field("sub.s", [1, 2]),
)
)
# This includes safety checks that Sub1 / Sub2 are uniquely specified
models = ps.initialize(Model, configs)
# The code above is equivalent to
models_manual = [
Model(seed=43, sub=Sub1(s=1)),
Model(seed=43, x=6, sub=Sub1(s=2)),
Model(seed=44, sub=Sub1(s=1)),
Model(seed=44, x=6, sub=Sub1(s=2)),
]
assert models == models_manual
# We can also check that we didn't accidentally duplicate a setting
ps.check_unique(models)
While in this toy example, manually specifying the combinations may still be viable, the library allows infinitely combining different configs and sub-models, making it a powerful tool for large-scale experiment definition. To learn mode about the capabilities of the library please visit the documentation page.
Installation
You can install the library by checking out the repo and running
pip install 'pydantic-sweep'
License
The main code-base is licensed under MPL-2.0 a weak copy-left license that allows commercial use. See the license file for the exact clauses and this FAQ for a high-level description.
An exception from this are the documentation in the docs and example folders as
well as this README file, which are licensed under the
0BSD: a highly
permissive license that does not require attribution. That way, you are free to copy &
paste example code into your use-case. See
here for a high-level description.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_sweep-0.3.5.tar.gz.
File metadata
- Download URL: pydantic_sweep-0.3.5.tar.gz
- Upload date:
- Size: 138.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1631f762be3376c3d44460a44df084a530161d580591ea4995dbdaf9735edc5
|
|
| MD5 |
52325d5b84575ac35ef26196bf6d9cc5
|
|
| BLAKE2b-256 |
d877b1eff735cbfe90fffa2fcd09cb4b37f21dc7f12906282c44466ea93ad5b7
|
Provenance
The following attestation bundles were made for pydantic_sweep-0.3.5.tar.gz:
Publisher:
release.yml on befelix/pydantic_sweep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_sweep-0.3.5.tar.gz -
Subject digest:
f1631f762be3376c3d44460a44df084a530161d580591ea4995dbdaf9735edc5 - Sigstore transparency entry: 230140351
- Sigstore integration time:
-
Permalink:
befelix/pydantic_sweep@0aea03329b4bc279a003727d4860c59180875f2f -
Branch / Tag:
refs/tags/v0.3.5 - Owner: https://github.com/befelix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0aea03329b4bc279a003727d4860c59180875f2f -
Trigger Event:
release
-
Statement type:
File details
Details for the file pydantic_sweep-0.3.5-py3-none-any.whl.
File metadata
- Download URL: pydantic_sweep-0.3.5-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
035e7c4caed9418ac6759be18901319e7fd1e12cf99c3297e70191ae8bf91d08
|
|
| MD5 |
780c924224a8fa524f35c547e1dd0862
|
|
| BLAKE2b-256 |
915786a775e0341f5b1c56b88857aff19f189dccb4eaf3544c167aab30782fe1
|
Provenance
The following attestation bundles were made for pydantic_sweep-0.3.5-py3-none-any.whl:
Publisher:
release.yml on befelix/pydantic_sweep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_sweep-0.3.5-py3-none-any.whl -
Subject digest:
035e7c4caed9418ac6759be18901319e7fd1e12cf99c3297e70191ae8bf91d08 - Sigstore transparency entry: 230140353
- Sigstore integration time:
-
Permalink:
befelix/pydantic_sweep@0aea03329b4bc279a003727d4860c59180875f2f -
Branch / Tag:
refs/tags/v0.3.5 - Owner: https://github.com/befelix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0aea03329b4bc279a003727d4860c59180875f2f -
Trigger Event:
release
-
Statement type: