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.
  • Mixed inference. Posteriors are computed by exact enumeration for discrete nodes and by MCMC sampling (NUTS) for continuous ones, so a single diagram can combine both.

Limitations

  • Decisions are discrete. A decision node must choose among a finite set of actions (continuous decisions are not yet supported).
  • Results are approximate. Inference and solving both return Monte Carlo estimates rather than exact answers, and they get more precise with more samples. For purely discrete diagrams, an exact solver like pyAgrum is the better choice.

Installation

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

pip install pylimid

By default, JAX is installed in its CPU-only version. If you have an NVIDIA GPU, install the extra that matches your CUDA version:

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

They do not support native Windows or macOS. See the JAX installation guide for GPU and driver requirements.

Example

A small shop sells ice cream. Every morning the owner checks the weather forecast and decides how many ice creams to stock, from 0 to 200 in steps of 20. Each ice cream costs $1 and sells for $10, and anything not sold by the evening is thrown away. The forecast is cloudy with probability 0.7 and sunny with probability 0.3. Past seasons suggest average demand of 40 ice creams on cloudy days and 120 on sunny days. The owner expects the coming season to be busier, but is uncertain about how much. How many should the shop stock?

We express that belief with a Bayesian prior on a positive busyness multiplier. Its LogNormal distribution has mean 1.2, representing 20% higher average demand, and a log-scale standard deviation of 0.1. Demand depends on both the weather and this unknown multiplier.

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

from pylimid import ChanceNode, DecisionNode, InfluenceDiagram, UtilityNode, solve

WEATHER_STATES = ("cloudy", "sunny")
DEMAND_MEANS = jnp.array([40.0, 120.0])
BUSYNESS_MEAN = 1.2
BUSYNESS_LOG_SD = 0.1
ORDERS = jnp.arange(0, 201, 20)


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


def profit(order, demand):
    stocked = ORDERS[order]
    return 10.0 * jnp.minimum(stocked, demand) - 1.0 * stocked


diagram = InfluenceDiagram()
diagram.add_node(
    ChanceNode(
        name="weather",
        states=WEATHER_STATES,
        dist=lambda: dist.Categorical(probs=jnp.array([0.7, 0.3])),
    )
)
diagram.add_node(
    ChanceNode(
        name="busyness",
        dist=lambda: dist.LogNormal(
            jnp.log(BUSYNESS_MEAN) - BUSYNESS_LOG_SD**2 / 2, BUSYNESS_LOG_SD
        ),
    )
)
diagram.add_node(
    ChanceNode(name="demand", parents=("weather", "busyness"), dist=demand_dist)
)
diagram.add_node(
    DecisionNode(
        name="order", parents=("weather",), states=tuple(str(n) for n in ORDERS)
    )
)
diagram.add_node(UtilityNode(name="profit", parents=("order", "demand"), values=profit))

solution = solve(diagram, num_samples=50_000)
for info, action in solution.policy["order"].items():
    print(f"{WEATHER_STATES[info[0]]}: stock {int(ORDERS[action])}")
# cloudy: stock 80
# sunny: stock 200

weather is a discrete chance node, busyness and demand are continuous ones, order is the decision, and profit is the utility. The decision's parents are what is known when it is made, so order sees the weather while busyness and demand remain unknown. Note that order is the index of the chosen action, which is why profit looks the stock level up in ORDERS.

The shop should stock far more than the average demand: a missed sale loses $9 of margin, while a leftover ice cream only costs $1. The sunny-day order reaches the maximum possible order of 200. The quickstart walks through this example step by step.

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.2.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.2.0
File Size Uploaded Provenance Actions
pylimid-0.2.0.tar.gz 2.6 MB With provenance Details for pylimid-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 2.6 MB

Release files / pylimid-0.2.0.tar.gz

Download URL pylimid-0.2.0.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
1d6c7d3a49b98ec2db5e81c656044aecccc7465178925e16849d59480b5bba51
BLAKE2b-256 checksum
How to use checksums
c638546ed48f4c8ed191595f7e97d0148c04e0927741e0439a47f118163a059c
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 Oct 18, 2026.

Transparency log

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

Download URL pylimid-0.2.0-py3-none-any.whl
Size 63.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1b3927bd2c4724bf4e1c5b40d24871a1327022f4d44c6a504932189c2e1fafb
BLAKE2b-256 checksum
How to use checksums
bb9f8d5d80e36af2e072f3a0603828e74701791630ed6475a08019205e9cd222
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 Oct 18, 2026.

Transparency log

Security for pylimid 0.2.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.2.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 18, 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