Skip to main content

pypolymix logo

Docs Code style Coverage
Docs Code style: black Coverage Status

Pypolymix

pypolymix is a light-weight PyTorch companion for building stochastic surrogate models.

Documentation

Project documentation lives at https://sandialabs.github.io/pypolymix.

Installation

From PyPI:

python -m pip install pypolymix

Optional extras:

python -m pip install "pypolymix[examples]"
python -m pip install "pypolymix[docs]"
python -m pip install "pypolymix[dev]"

For local development:

python -m pip install -e ".[dev,docs,examples]"

Quickstart

Fit a 1D polynomial chaos model with a mix of stochastic and deterministic coefficients:

import torch

from pypolymix.parameter_groups import DeterministicGroup, IIDGaussianGroup
from pypolymix.surrogate_models import PolynomialChaosExpansion
from pypolymix import StochasticModel

torch.manual_seed(0)
x = torch.linspace(-1, 1, 200).unsqueeze(-1)
y = torch.sin(3 * x) + 0.1 * torch.randn_like(x)

surrogate_model = PolynomialChaosExpansion(num_inputs=1, num_outputs=1, degree=5)
num_params = surrogate_model.num_params()

parameter_groups = [
    IIDGaussianGroup("stochastic", 2),
    DeterministicGroup("deterministic", num_params - 2),
]

model = StochasticModel(surrogate_model=surrogate_model, parameter_groups=parameter_groups)

optimizer = torch.optim.Adam(model.parameters(), lr=5e-3)
for _ in range(500):
    optimizer.zero_grad()
    preds = model(x, num_samples=16).mean(dim=0)
    data_loss = torch.mean((preds - y) ** 2)
    loss = data_loss + 1e-3 * model.distribution_loss()
    loss.backward()
    optimizer.step()

with torch.no_grad():
    samples = model(x, num_samples=100)
    mean = samples.mean(dim=0)
    std = samples.std(dim=0)

Polynomial chaos example

Development

If you use Poetry:

poetry install --with dev,docs,examples

Install the pre-commit hook:

pre-commit install

Examples

Notebooks live in docs/examples/ and are rendered on the documentation site.

For a full end-to-end workflow rather than a single notebook, see docs/examples/constitutive_model/: a runnable mixture-of-experts surrogate for a constitutive model, covering the data contract, transforms, training with checkpointing, and evaluation by integrating the learned right-hand side forward in time.

Metadata

Release files for pypolymix 0.1.9

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

Source distribution (sdist)

Source distribution for pypolymix 0.1.9
File Size Uploaded Provenance Actions
pypolymix-0.1.9.tar.gz 16.2 kB With provenance Details for pypolymix-0.1.9.tar.gz

Built distribution (wheel)

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

Total release size: 37.9 kB

Release files / pypolymix-0.1.9.tar.gz

Download URL pypolymix-0.1.9.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3522543f671c88d9c73c0804d5baaf990a53f484656fc2bb063c41a31ce4629c
BLAKE2b-256 checksum
How to use checksums
8fd68902140ed6ddf802c16f8a3f4c70983f21d0964816fe989876961cae743c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release files / pypolymix-0.1.9-py3-none-any.whl

Download URL pypolymix-0.1.9-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6144189a1efac0f972756a24c5840d29fbeb52865eedeb5f396075f505a3321d
BLAKE2b-256 checksum
How to use checksums
25dcd5be1cc2db3ccdc45613968414429fabd2ec7a4d428a569077ea9d6de9c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Security for pypolymix 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pypolymix-0.1.9.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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