Skip to main content

pyzag

Documentation Testing Code formatting

pyzag is a library for efficiently training generic models defined with a recursive nonlinear function. Full documentation is available here.

The library is available as open source code with an MIT license.

Nonlinear recursive functions

A nonlinear recursive function has the form

$$f\left(x_{i-1}, x_i; p\right) =0 , \forall i \in \left(1,2,\ldots,n \right)$$

with $x$ the model state (the unknowns to solve for) and $p$ the model parameters. Given the model and an initial condition $x_0$ we can define a sequence $\mathcal{X} = \left(x_0, x_1, \ldots, x_n \right)$ by recursively solving the nonlinear equation for $x_n$.

While this form seems abstract, it actually describes a large number of interesting and useful models. For example, consider the ordinary differential equation defined by

$$\dot{x} = g\left(x; p \right)$$

$$x(0) = x_0$$

We can convert this into a nonlinear recursive equation by applying a numerical time integration scheme, for example the backward Euler method:

$$x_{i} = x_{i-1} + g(x_i; p) \Delta t_i $$

This algebraic equation has our standard form for a nonlinear recursive model:

$$f\left(x_{i-1}, x_i; p \right) = x_i - x_{i-1} - g(x_i; p) \Delta t_i $$

However, defining our time series with an algebraic equation, rather than a differential equation, provides access to a range of models that cannot be expressed as ODEs, for example difference equations.

Training building blocks

The goal of training is basically to find the parameters $p$ for a nonlinear recursive function $f$ and initial condition $x_0$ such that the resulting sequence $\mathcal{X}$ best matches a target series $\hat{\mathcal{X}}$. At a minimum to train a model we need to efficiently generate the time series $\mathcal{X}$ for different parameter values and, often, for multiple targets. Additionally, we often need the derivative of the sequence $\mathcal{X}$ with respect to the model parameters $p$.

pyzag provides a few building block methods for efficiently generating sequences and their derivatives:

  1. pyzag can vectorize simulating the sequences both for independent instantiations of the same model (i.e. batch vectorization) but also by vectorizing over some number of steps $i$. This paper describes the basic idea, but pyzag extends the concept to general nonlinear recursive models. The advantage of the approach is that it can increase the calculation bandwith if batch parallelism alone is not enough to fully utilize the compute device.
  2. pyzag implements the parameter gradient calculation with the adjoint method. For long sequences this approach is much more memory efficient compared to automatic differentiation and is also generally more computationally efficient.
  3. pyzag also provides several methods for solving the resulting batched, time-chunked nonlinear and linear equations and predictors for starting the nonlinear solves based on previously simulated pieces of the sequence.

Deterministic and stochastic models

pyzag is built on top of PyTorch, integrating the adjoint calculation into PyTorch AD. Users can seemlessly define and train deterministic models using PyTorch primitives.

The library also provides helper classes to convert a deterministic model, defined as a nonlinear recursive relation implemented with a PyTorch model, into a statistical model using the pyro library. Specifically, pyzag provides methods for automatically converting the deterministic model to a stochastic model by replacing determinsitc parameters with prior distributions as well as methods for converting models into a hierarchical statistical format to provide dependence across multiple sequences.

Metadata

Release files for pyzag 1.1.4

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

Source distribution (sdist)

Source distribution for pyzag 1.1.4
File Size Uploaded
pyzag-1.1.4.tar.gz 26.5 kB Details

Built distribution (wheel)

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

Total release size: 52.6 kB

Release files / pyzag-1.1.4.tar.gz

Download URL pyzag-1.1.4.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cbf969ee88aeb8daa7714758b2b4498299eaeeef1a70f5e3a61e096cff3c9fa1
BLAKE2b-256 checksum
How to use checksums
72e8dc96735af9203dd93b9528f67575e3fb2a583f635c80e4bf8dc1368e5c84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 9, 2026.

Transparency log

Release files / pyzag-1.1.4-py3-none-any.whl

Download URL pyzag-1.1.4-py3-none-any.whl
Size 26.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5ef3d6c3be1ff6ca5b716026e563cfc49700f6d6e191fdd58e97963ba30d1da
BLAKE2b-256 checksum
How to use checksums
fe9aff85dec09de8d32d9727ce62a0c42c7ece2bde6e3eb822f675681e5f3fdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 9, 2026.

Transparency log

Release history Release notifications | RSS feed

2.0.0

2 release files

This release

1.1.4 This release

2 release files

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.9.0

1 release file

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