Skip to main content

PyLIMID

PyPI Documentation License: Apache 2.0 Python 3.12

PyLIMID is a Python library built on top of NumPyro for building and solving limited-memory influence diagrams (LIMIDs) whose chance nodes can be discrete, continuous, or both in the same model.

Rather than requiring every chance and utility node to be represented as a table, PyLIMID uses NumPyro distributions, JAX functions, and sampling. And because JAX compiles and vectorises the computations, models run efficiently on both CPU and GPU.

Early development. The public API is still settling and may change between releases, so pin a version if you build on it.

Features

  • Flexible distributions. A chance node is a NumPyro distribution whose parameters can be any JAX expression of its parents, so you are not limited to a conditional probability table.
  • Bayesian priors. Represent uncertain model parameters as chance nodes with prior distributions.
  • Utilities as functions. A utility is a Python function of its parents written with JAX, so it can express thresholds, nonlinearities, or risk preferences instead of a lookup table.
  • Policy fitting. Policy gradient jointly fits the decision rules within declared policy families. Decisions can use categorical observations, numerical observations, or both, depending on the family.
  • Mixed inference. Posteriors use exact enumeration for categorical nodes and supported finite counts, and MCMC sampling (NUTS) for continuous ones. Numerical counts also support forward simulation and observed likelihoods.

Limitations

  • Continuous actions are scalar. Decisions can choose finite categorical actions or a real number in a declared domain. DistributionPolicy composes continuous distributions with parameter models. Vector actions and parameter-dependent support are not supported.
  • Count posteriors need fixed enumerable support. Scalar Binomial counts with a concrete number of trials are supported. Unknown unbounded counts, shifted ranges and batched counts remain unsupported. Parent-dependent bounds do not have a supported enumeration path.
  • Results are approximate. Inference summaries and expected utility are estimated from samples. More evaluation samples reduce estimation noise, while policy quality also depends on the chosen family and training. Training does not guarantee an optimal policy. For discrete diagrams that meet its solver's requirements, consider pyAgrum when you need an exact solution.

Installation

PyLIMID uses Python 3.12. Installing it also pulls in NumPyro and JAX:

pip install pylimid

The default installation uses the CPU. For NVIDIA GPUs on Linux (x86_64 or aarch64), choose a CUDA extra compatible with your GPU and NVIDIA driver:

pip install "pylimid[cuda12]"  # CUDA 12
pip install "pylimid[cuda13]"  # CUDA 13

These extras install the CUDA libraries automatically. They do not support native Windows or macOS. GPU support under Windows WSL2 is experimental. See the JAX installation guide for GPU and driver requirements.

Example

A small shop sells ice cream by weight. Each kilogram costs $10 and brings in $100 if it all sells, and anything not sold by the evening is thrown away. The freezer holds up to 40 kilograms. The owner can also run a promotion for $60, which is expected to increase average demand by 20%.

The promotion must be announced the evening before, when tomorrow's weather is still uncertain. In the morning, the owner checks the weather and decides how much ice cream to order, remembering whether the promotion is running. Without a promotion, average demand is 4 kilograms on cloudy days and 12 on sunny days. Should the shop promote, and how much should it stock?

import jax.numpy as jnp
import numpyro.distributions as dist

from pylimid import (
    ChanceNode,
    DecisionNode,
    DistributionPolicy,
    InfluenceDiagram,
    Interval,
    Linear,
    TabularSoftmax,
    UtilityNode,
    solve,
)

COST = 10.0
PRICE = 100.0
CAPACITY = 40.0
PROMOTION_COST = 60.0
PROMOTION_BOOST = jnp.array([1.0, 1.2])
WEATHER_STATES = ("cloudy", "sunny")
WEATHER_PROBS = jnp.array([0.7, 0.3])
DEMAND_MEANS = jnp.array([4.0, 12.0])


def demand_dist(weather, promotion):
    mean = DEMAND_MEANS[weather] * PROMOTION_BOOST[promotion]
    return dist.Gamma(concentration=4.0, rate=4.0 / mean)


def profit(order, demand, promotion):
    revenue = PRICE * jnp.minimum(order, demand)
    return revenue - COST * order - PROMOTION_COST * promotion


diagram = InfluenceDiagram()
diagram.add_node(
    ChanceNode(
        name="weather",
        states=WEATHER_STATES,
        dist=lambda: dist.Categorical(probs=WEATHER_PROBS),
    )
)
diagram.add_node(
    DecisionNode(
        name="promotion",
        states=("skip", "run"),
        policy_family=TabularSoftmax(),
    )
)
diagram.add_node(
    ChanceNode(name="demand", parents=("weather", "promotion"), dist=demand_dist)
)
diagram.add_node(
    DecisionNode(
        name="order",
        parents=("weather", "promotion"),
        action_space=Interval(0.0, CAPACITY),
        policy_family=DistributionPolicy(
            distribution=dist.TruncatedNormal,
            parameter_model=Linear(outputs=("loc",)),
            fixed_parameters={"low": 0.0, "high": CAPACITY, "scale": 0.25},
        ),
    )
)
diagram.add_node(
    UtilityNode(name="profit", parents=("order", "demand", "promotion"), values=profit)
)

solution = solve(diagram, num_steps=2_000)
print(solution.render())

weather is a discrete chance node, and demand is a continuous one. The two decisions use different kinds of actions: promotion passes an index for skip or run, while order passes the quantity in kilograms directly to profit.

A decision's parents are what is known when it acts. The promotion has no parents because the weather is still unknown. The order sees both the weather and the earlier promotion choice, while actual demand remains unknown.

TabularSoftmax learns promotion probabilities, and DistributionPolicy learns a continuous order distribution. The interval declares which stock quantities are allowed, while the TruncatedNormal's fixed bounds keep orders within that range. Linear learns its location from the weather and promotion, with scale fixed at 0.25 kilograms.

In this run, the promotion rule puts more than 99.9% probability on running the promotion. When it runs, mean orders are about 7.2 kilograms on cloudy days and 21.0 on sunny days, with estimated expected profit of about $542.6 per day. Both rules remain stochastic, and training does not guarantee the best policy.

The quickstart walks through this example and adds a Bayesian prior for a busier season. The Solving guide explores training settings and a different order distribution.

Documentation

The full documentation is at https://pylimid.readthedocs.io:

  • The quickstart builds and solves the example above.
  • The user guide explains each piece in depth: chance nodes, decisions, utilities, inference, and solving.

Contributing

Contributions are welcome. CONTRIBUTING.md explains how to set up a development environment, which checks a change has to pass, and the conventions the project follows.

License

PyLIMID is released under the Apache 2.0 license. See LICENSE.md for details.

Metadata

Release files for pylimid 0.3.0

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

Source distribution (sdist)

Source distribution for pylimid 0.3.0
File Size Uploaded Provenance Actions
pylimid-0.3.0.tar.gz 2.9 MB With provenance Details for pylimid-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 2.9 MB

Release files / pylimid-0.3.0.tar.gz

Download URL pylimid-0.3.0.tar.gz
Size 2.9 MB
Tags Source
SHA-256 checksum
How to use checksums
af1593cb9ae93578456f4d32de02fe0faeea73a46afb8a3bd7029de6707a45b2
BLAKE2b-256 checksum
How to use checksums
653392ed17d5514d6270c3e2df352917138d5d658dbe91da1820a3b2e38d0c6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 29, 2026.

Transparency log

Release files / pylimid-0.3.0-py3-none-any.whl

Download URL pylimid-0.3.0-py3-none-any.whl
Size 81.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8967c10e9976a293e6aeb18e0c3d43df6ee18887fa1123cc9698ed23d13fd928
BLAKE2b-256 checksum
How to use checksums
e7a69bec69be22639a82c108cd5999ca5080c437eb21195de333ccfca3011c96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 29, 2026.

Transparency log

Security for pylimid 0.3.0

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 pylimid-0.3.0.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 Oct 29, 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