pyhs3.Model

class pyhs3.Model(*, parameterset, distributions, domain, functions, progress=True, mode='FAST_RUN', observables=None, likelihood=None)[source]

Probabilistic model with compiled tensor operations.

A model represents a specific instantiation of a workspace with concrete parameter values and domain constraints. It builds symbolic computation graphs for distributions and functions, with optional compilation for performance optimization.

The model handles dependency resolution between parameters, functions, and distributions, ensuring proper evaluation order through topological sorting of the computation graph.

HFDC constraint storage. For HistFactoryDistChannel distributions, self.distributions[name] stores the full per-channel expression (main Poisson x constraint product) so that logpdf(name, **params) matches pyhf/cabinetry semantics for callers asking about a single channel’s probability. self._hfdc_poisson[name] stores only the main Poisson term; log_prob uses it to assemble the joint NLL without double-counting constraint factors when multiple channels share a nuisance parameter. Constraint expressions are appended to self._hfdc_constraints exactly once per unique dedup key across all channels: single-parameter modifiers (normsys, histosys) are deduped by parameter name using self._hfdc_constraint_params_seen; multi-parameter modifiers (shapesys, staterror) are channel-local by workspace validation and always emitted as-is.

HS3 Reference

Models are computational representations of :hs3:label:`HS3 workspaces <hs3.file-format>`.

Parameters:
__init__(*, parameterset, distributions, domain, functions, progress=True, mode='FAST_RUN', observables=None, likelihood=None)[source]

Represents a probabilistic model composed of parameters, domains, distributions, and functions.

Parameters:
  • parameterset (ParameterSet) – The parameter set used in the model.

  • distributions (Distributions) – Set of distributions to include.

  • domain (Domain) – Domain constraints for parameters.

  • functions (Functions) – Set of functions that compute parameter values.

  • progress (bool) – Whether to show progress bar during dependency graph construction.

  • mode (str) – PyTensor compilation mode. Defaults to “FAST_RUN”. Options: “FAST_RUN” (apply all rewrites, use C implementations), “FAST_COMPILE” (few rewrites, Python implementations), “NUMBA” (compile using Numba), “JAX” (compile using JAX), “PYTORCH” (compile using PyTorch), “DebugMode” (debugging), “NanGuardMode” (NaN detection).

  • observables (dict[str, tuple[float, float]] | None) – Dictionary mapping observable names to (lower, upper) bounds.

domain

The original domain with constraints for parameters.

Type:

Domain

parameterset

The original parameter set with parameter values.

Type:

ParameterSet

distributions

Symbolic distribution expressions.

Type:

dict[str, pytensor.tensor.variable.TensorVariable]

parameters

Symbolic parameter variables.

Type:

dict[str, pytensor.tensor.variable.TensorVariable]

functions

Computed function values.

Type:

dict[str, pytensor.tensor.variable.TensorVariable]

mode

PyTensor compilation mode.

Type:

str

_compiled_functions

Cache of compiled PyTensor functions.

Type:

dict[str, Callable[…, npt.NDArray[np.float64]]]

Parameters:

likelihood (Likelihood | None)

Methods

__init__(*, parameterset, distributions, ...)

Represents a probabilistic model composed of parameters, domains, distributions, and functions.

graph_summary(name)

Get a summary of the computation graph structure.

logpdf(name, **parametervalues)

Evaluates the natural logarithm of the PDF.

logpdf_unsafe(name, **parametervalues)

Evaluates the log PDF with automatic type conversion (convenience method).

pars(name)

Get the ordered list of input parameter names for a distribution.

parsort(name, names)

Similar to numpy's argsort, returns the indices that would sort the parameters.

pdf(name, **parametervalues)

Evaluates the probability density function of the specified distribution.

pdf_unsafe(name, **parametervalues)

Evaluates the PDF with automatic type conversion (convenience method).

visualize_graph(name[, fmt, outfile, path])

Visualize the computation graph for a distribution.

Attributes

data

Observed data arrays from the workspace, keyed by observable name.

free_params

Non-constant parameter values from the workspace parameter set.

log_prob

Symbolic joint log-probability expression for the full likelihood.

nominal_params

Default parameter values from the workspace parameter set.