pyhs3.Workspace¶
- class pyhs3.Workspace(**data)[source]¶
Workspace for managing HS3 model specifications.
A workspace contains parameter points, distributions, domains, and functions that define a probabilistic model. It provides methods to construct Model objects with specific parameter values and domain constraints.
- Variables:
metadata – Required metadata containing HS3 version and optional attribution
distributions – List of distribution configurations
functions – List of function configurations
domains – List of domain configurations
parameter_points – List of parameter point configurations
data – Data specifications for observations
likelihoods – Likelihood specifications mapping distributions to data
analyses – Analysis configurations for automated analyses
misc – Arbitrary user-created information
parameter_collection (ParameterPoints) – Named parameter sets.
distribution_set (Distributions) – Available distributions.
domain_collection (Domains) – Domain constraints for parameters.
function_set (Functions) – Available functions for parameter computation.
HS3 Reference
See HS3 file format specification for the complete workspace structure.
- Parameters:
data (
Any)
Fields¶ Field
Type
Required
Default
No
factory
No
factory
No
factory
No
factory
No
factory
No
factory
Yes
No
factory
No
factory
- __init__(**data)¶
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (
Any)
Methods
format_validation_error(validation_error, ...)Format a ValidationError into a readable error summary.
load(path, *[, verbose, suppress_traceback])Load workspace from a JSON file.
model()Constructs a
Modelrooted attarget.model_post_init(_Workspace__context, /)Resolve foreign key references after workspace construction.
Resolve the
ParameterContextfortarget.Attributes
- classmethod Workspace.format_validation_error(validation_error, path, verbose)[source]¶
Format a ValidationError into a readable error summary.
- classmethod Workspace.load(path, *, verbose=False, suppress_traceback=True)[source]¶
Load workspace from a JSON file.
- Parameters:
- Returns:
The loaded workspace instance
- Return type:
- Workspace.model(target, *, domain=None, parameter_set=None, progress=True, mode='CVM')[source]¶
- Workspace.model(target, *, parameter_set=None, progress=True, mode='CVM')
- Workspace.model(target, *, domain=None, parameter_set=None, progress=True, mode='CVM')
- Workspace.model(target, *, domain=None, parameter_set=None, progress=True, mode='CVM')
Constructs a
Modelrooted attarget.Dispatch is based on the type of
target:Analysis— all context (domain, parameter set, observables) is derived from the analysis; gains access tolog_prob,data, andfree_params. Only the likelihood’s distributions and their transitive dependencies are built.Likelihood— observable bounds are derived from the likelihood’s data;domainfalls back todefault_domainthen index 0, andparameter_setfalls back to workspace defaults unless overridden. Only the likelihood’s distributions and their transitive dependencies are built.str— searches analyses then likelihoods by name; delegates to the appropriate registered path. Falls back to legacy domain indexing if the name is not found in either.int— legacy path:targetindexes into workspace domains and the complete workspace graph is built.
- Parameters:
target (
int) – Dispatch key. Pass anAnalysisorLikelihoodfor the modern paths, a name string to search analyses/likelihoods, or anintdomain index for the legacy path.domain (
int|str|Domain|None) – Override domain (legacy and Likelihood paths only).parameter_set (
int|str|ParameterSet|None) – Override parameter set (legacy and Likelihood paths only).progress (
bool) – Whether to show a progress bar during graph construction.mode (
str) – PyTensor compilation mode (default"CVM"; seeModel).
- Returns:
The constructed model.
- Return type:
- Workspace.model_post_init(_Workspace__context, /)[source]¶
Resolve foreign key references after workspace construction.
- Workspace.parameter_context(target, *, parameter_set=None, domain=None)[source]¶
- Workspace.parameter_context(target, *, parameter_set=None, domain=None)
- Workspace.parameter_context(target, *, parameter_set=None, domain=None)
- Workspace.parameter_context(target, *, parameter_set=None, domain=None)
Resolve the
ParameterContextfortarget.The context is what
model()builds the model from: the referenced parameter point, the domain bounds and the parameters of interest. Dispatch is based on the type oftarget, as inmodel():Analysis– the analysis domains, merged into one when there are several; itsinitparameter point (an empty one when it has none) unlessparameter_setoverrides it; and itsparameters_of_interest. The analysis must satisfy HS3 section 2.7 with that parameter point.domaincannot be overridden.Likelihood–domainfalls back todefault_domainthen index 0, andparameter_setto the first parameter point; no parameters of interest.str– searches analyses then likelihoods by name and resolves as above; otherwise the name selects a domain, as for anint.int–targetindexes into the workspace domains (unlessdomainoverrides it) andparameter_setfalls back to the first parameter point; no parameters of interest.
- Parameters:
parameter_set (
int|str|ParameterSet|None) – Override parameter set: aParameterSet, or an index or name into the workspace parameter points.domain (
int|str|Domain|None) – Override domain: aDomain, or an index or name into the workspace domains (not for analyses).
- Returns:
The resolved context.
- Return type:
- Raises:
UnlistedParameterError – If an analysis violates HS3 section 2.7.
MissingInitialValueError – If a free parameter of an analysis has no starting value in the parameter point.
UnknownParameterOfInterestError – If an analysis names a parameter of interest that its likelihood does not use.
UnconstrainedParameterError – If a parameter that gets no constraint term is not
constin the parameter point.ValueError – If an analysis references an unknown
init, ifdomainis given for an analysis, or if an override is requested from a workspace without parameter points or domains.
- Workspace.metadata¶
- Workspace.distributions¶
- Workspace.functions¶
- Workspace.domains¶
- Workspace.parameter_points¶
- Workspace.data¶
- Workspace.likelihoods¶
- Workspace.analyses¶
- Workspace.misc¶