Registry / ai-ml / pyro-api

pyro-api

JSON →
library0.1.2pypypi✓ verified 25d ago

pyro-api provides a generic, backend-agnostic API for probabilistic programming, allowing users to write code that can be executed with different Pyro backends (e.g., Pyro, NumPyro, Funsor) without modification. It aims to abstract common functionalities like distributions, inference primitives, and parameter management. The current version is 0.1.2, and it maintains a slow release cadence, primarily focusing on stability and compatibility.

pip install pyro-api
INSTALL
IMPORT
SIG · PYRO-API
P
pyro-api
ai-mlpythonv0.1.2
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pyroapi
import pyroapi
import pyro.generic
The pyro.generic module was moved to the standalone pyroapi package in version 0.1.0.
set_backend
from pyroapi import set_backend
distributions
import pyroapi.distributions as dist
param
import pyroapi.params as params
handlers
import pyroapi.handlers as handlers

This quickstart demonstrates how to set a backend for `pyro-api` and access its generic modules for distributions and parameters. Remember, `pyro-api` is an interface; you must install a concrete backend like `pyro` or `numpyro` for it to function correctly. The `set_backend()` call typically needs to happen early in your application's lifecycle.

import pyroapi import os # IMPORTANT: pyro-api is an interface. You must install a backend. # For example, run: pip install pyro # Or for NumPyro: pip install numpyro # Set the backend. This line typically goes near the start of your script. # 'pyro' is a common default, but 'numpyro' or 'funsor' are also options. # If the chosen backend is not installed, set_backend will raise an error. try: backend_name = os.environ.get('PYRO_BACKEND', 'pyro') # Use env var for testing pyroapi.set_backend(backend_name) print(f"Pyro-API backend successfully set to: {pyroapi.get_backend()}") # Now you can use the generic API for distributions, parameters, etc. import pyroapi.distributions as dist import pyroapi.params as params # Example: Define a generic parameter and a distribution mean_param = params.param("mean_value", 0.0) std_param = params.param("std_value", 1.0, constraint=dist.constraints.positive) generic_normal = dist.Normal(mean_param, std_param) print(f"\nCreated a generic Normal distribution with mean {mean_param.data} and std {std_param.data}") except ImportError as e: print(f"Failed to set Pyro-API backend: {e}") print("Please ensure your chosen backend (e.g., 'pyro' or 'numpyro') is installed.") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingThe `pyro.generic` module was moved out of the `pyro` package into the standalone `pyro-api` package in version 0.1.0. Direct imports like `from pyro.generic import something` will fail.
fix
Update imports to use `pyroapi` directly, e.g., `import pyroapi`, `from pyroapi import set_backend`, `import pyroapi.distributions as dist`.
affects: >=0.1.0
gotcha`pyro-api` is an interface and does not provide an implementation itself. You must install a backend library (e.g., `pyro`, `numpyro`, `funsor`) and call `pyroapi.set_backend()` before using any generic API features.
fix
Run `pip install <your-chosen-backend>` (e.g., `pip install pyro`) and include `pyroapi.set_backend("pyro")` early in your application's setup.
affects: All versions
gotchaWhen using `pyro-api`, ensure that all operations are performed through the generic API (e.g., `pyroapi.distributions`, `pyroapi.params`). Mixing generic API calls with direct backend-specific calls (e.g., `torch.tensor` directly when using `pyro` backend) can lead to unexpected behavior or break backend portability.
fix
Strive for full generic API usage when writing portable code. For example, use `pyroapi.tensor(data)` instead of `torch.tensor(data)`.
affects: All versions
Errors
Common errors & fixes
RuntimeError: No backend is currently set for pyro-api. Please call pyro_api.set_backend() before using pyro-api.
The pyro-api library is a backend-agnostic interface and requires an explicit backend (e.g., 'pyro', 'numpyro') to be set before any probabilistic programming operations can be performed.
fix
import pyro_api
pyro_api.set_backend('pyro') # or 'numpyro', 'funsor'
ModuleNotFoundError: No module named 'pyro-api'
Python module names use underscores instead of hyphens; while the package is installed as `pyro-api`, it is imported as `pyro_api`.
fix
import pyro_api
AttributeError: module 'pyro_api' has no attribute 'Normal'
Distributions like `Normal` are located within the `pyro_api.distributions` submodule, not directly under the top-level `pyro_api` module.
fix
from pyro_api import distributions
x = distributions.Normal(0., 1.)
ValueError: Unknown backend 'foo'. Available backends are: ['pyro', 'numpyro', 'funsor']
The specified backend name in `pyro_api.set_backend()` is not a recognized or supported backend for the pyro-api library.
fix
import pyro_api
pyro_api.set_backend('numpyro') # Use a valid backend name like 'pyro' or 'numpyro'
Upgrade
Version history
0.1.2latest on PyPI · released May 15, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources
pyro-api — pip install pyro-api · libregistry