stormvogel.parametric._backend

Backend registry for stormvogel.parametric.

A backend is anything that owns a concrete value type representing a polynomial / rational function, knows how to construct its symbols and constants, and can move values to and from pycarl (the representation stormpy uses internally).

Backends are registered with register(). The first backend to register also becomes the default; callers can change that with set_default().

Attributes

Classes

ParametricBackend

The contract a parametric-value backend must implement.

Functions

register(→ None)

Register a parametric backend.

set_default(→ None)

Select the backend used by stormvogel.parametric.symbol() /

get_default(→ ParametricBackend)

Return the currently-selected default backend.

registered_types(→ tuple[type, Ellipsis])

Return the union of all expr_types across registered backends.

backend_for(→ ParametricBackend)

Return the backend that owns value's concrete type.

Module Contents

stormvogel.parametric._backend.Number
class stormvogel.parametric._backend.ParametricBackend

Bases: Protocol

The contract a parametric-value backend must implement.

A backend is responsible for constructing its values (symbols, constants) and for bridging them to pycarl. All introspection operations (is_zero, evaluate, …) are registered as functools.singledispatch() overloads on the generics in stormvogel.parametric; the backend itself does not need to expose them on its instance.

name: str
expr_types: tuple[type, Ellipsis]
symbol(name: str, **kwargs: Any) Any

Create a parameter symbol with the given name.

constant(n: Number) Any

Lift a Python number into a backend-native constant.

to_pycarl(value: Any, var_map: dict[str, Any]) Any

Convert value to a pycarl factorized rational function.

var_map maps parameter names to the pycarl Variable objects created by the stormpy bridge. Callers guarantee that every free symbol in value has an entry.

from_pycarl(pycarl_value: Any) Any

Convert a pycarl rational function into a backend-native value.

stormvogel.parametric._backend._BACKENDS: list[ParametricBackend] = []
stormvogel.parametric._backend._default: ParametricBackend | None = None
stormvogel.parametric._backend.register(backend: ParametricBackend) None

Register a parametric backend.

If no default has been set yet, the first backend registered becomes it. Re-registering the same backend (by name) is a no-op — the existing entry is replaced in-place — so importing a backend module twice is harmless.

stormvogel.parametric._backend.set_default(name: str) None

Select the backend used by stormvogel.parametric.symbol() / stormvogel.parametric.constant().

stormvogel.parametric._backend.get_default() ParametricBackend

Return the currently-selected default backend.

Raises:

RuntimeError – If no backend has been registered yet (should not happen in practice: importing stormvogel.parametric auto-registers the sympy backend).

stormvogel.parametric._backend.registered_types() tuple[type, Ellipsis]

Return the union of all expr_types across registered backends.

Used by stormvogel.parametric.is_parametric() as the isinstance() check.

stormvogel.parametric._backend.backend_for(value: Any) ParametricBackend

Return the backend that owns value’s concrete type.

Raises:

LookupError – If no registered backend claims the type.