1"""High-level configuration object for the statistic workflow.
3``StatisticConfig`` is the Python entry point for configuring the bound C++
4statistic manager. It mirrors the fields exposed by the pybind11
5``StatisticConfig`` binding.
8from __future__
import annotations
10from dataclasses
import dataclass, field
12from typing
import Dict, Optional, Tuple
14from pyhyperiso.phyperiso.pyhyperiso
import statistic
as st
16from pyhyperiso.core.Statistic.Copula
import CopulaKind
17from pyhyperiso.core.Statistic.ExperimentObs
import ExperimentObs
18from pyhyperiso.core.Statistic.MarginalConfig
import MarginalKind
21@dataclass(frozen=True)
23 """Immutable progress snapshot produced by the C++ statistic pipeline."""
32 elapsed_seconds: float = 0.0
33 eta_seconds: float = -1.0
34 finished: bool =
False
39 """Thread-safe bridge exposing C++ progress to Python frontends."""
45 self, phase: str =
"preparing", message: str =
"Preparing statistic workflow"
47 """Reset progress reporting and set the initial phase and message."""
58 eta_seconds: float = -1.0,
59 finished: bool =
False,
61 """Publish a progress update to Python and graphical frontends."""
72 def snapshot(self) -> StatisticProgressSnapshot:
73 """Return an immutable snapshot of the latest progress event."""
76 phase=str(event.phase),
77 message=str(event.message),
78 completed=int(event.completed),
79 total=int(event.total),
80 attempts=int(event.attempts),
81 failures=int(event.failures),
82 fraction=float(event.fraction),
83 elapsed_seconds=float(event.elapsed_seconds),
84 eta_seconds=float(event.eta_seconds),
85 finished=bool(event.finished),
86 sequence=int(event.sequence),
91 """Likelihood backend used by the statistic manager.
94 PROFILED_NUISANCE: Full likelihood backend with explicit nuisance
95 parameters, nuisance copula and experimental-observable copula.
96 CHI2_MC_COVARIANCE: Chi-square backend without explicit nuisance
97 coordinates. The covariance is estimated from Monte-Carlo theory
98 propagation and combined with the experimental covariance.
101 PROFILED_NUISANCE = st.StatisticLikelihoodMode.PROFILED_NUISANCE
102 CHI2_MC_COVARIANCE = st.StatisticLikelihoodMode.CHI2_MC_COVARIANCE
105 """Convert this Python enum wrapper to the bound C++ enum.
108 Bound C++ ``StatisticLikelihoodMode`` value.
114 """Validate that a value has the expected wrapper type.
117 value: Value to validate.
118 typ: Expected Python type.
119 name: Human-readable argument name.
125 TypeError: If ``value`` is not an instance of ``typ``.
127 if not isinstance(value, typ):
128 raise TypeError(f
"{name} must be {typ.__name__}, got {type(value).__name__}.")
133 """Convert a Python ``ParamId`` wrapper to C++.
136 pid: Python parameter identifier.
139 Bound C++ ``ParamId`` value.
141 return _require(pid, ParamId,
"ParamId").to_cpp()
145 """Convert a Python ``MarginalKind`` wrapper to C++.
148 kind: Python marginal kind enum.
151 Bound C++ ``MarginalKind`` value.
153 return _require(kind, MarginalKind,
"MarginalKind").to_cpp()
157 """Convert a Python ``CopulaKind`` wrapper to C++.
160 kind: Python copula kind enum.
163 Bound C++ ``CopulaKind`` value.
165 return _require(kind, CopulaKind,
"CopulaKind").to_cpp()
169 """Convert a Python likelihood mode wrapper to C++.
172 mode: Python likelihood backend enum.
175 Bound C++ ``StatisticLikelihoodMode`` value.
179 StatisticLikelihoodMode,
180 "StatisticLikelihoodMode",
185 """Convert a Python ``ExperimentObs`` wrapper to C++.
188 obs: Python experimental-observable wrapper.
191 Bound C++ ``ExperimentObs`` value.
193 return _require(obs, ExperimentObs,
"ExperimentObs").to_cpp()
198 """Expert configuration for fitting, nuisance pruning and covariance logic.
200 ``StatisticConfig`` should remain the simple user-facing object. Fields that
201 affect minimization internals, likelihood backend selection, covariance
202 regularization or nuisance-preselection live here.
205 override_nuisance_marginals: Dict[ParamId, MarginalKind] = field(default_factory=dict)
206 override_exp_data_marginals: Dict[ExperimentObs, MarginalKind] = field(default_factory=dict)
208 nuisance_copula_type: CopulaKind = CopulaKind.GAUSSIAN
209 exp_data_copula_type: CopulaKind = CopulaKind.GAUSSIAN
211 MLE_max_iter: int = 500
212 MLE_tol: float = 1e-8
213 MLE_strategy: int = 2
214 MLE_run_hesse: bool =
True
215 MLE_request_minos: bool =
False
216 MLE_verbose: bool =
False
218 nuisance_relevance_cutoff: float = 1e-8
219 nuisance_sensitivity_pruning: bool =
True
220 nuisance_sensitivity_probe_sigmas: float = 1.0
221 nuisance_sensitivity_rel_cutoff: float = 1e-6
222 nuisance_sensitivity_abs_cutoff: float = 1e-12
223 nuisance_sensitivity_scale_floor: float = 1e-3
224 nuisance_sensitivity_contexts: int = 2
225 nuisance_sensitivity_context_sigma: float = 0.35
226 nuisance_sensitivity_seed: int = 12345
227 nuisance_sensitivity_keep_on_failure: bool =
True
229 fit_parameter_sensitivity_check: bool =
True
230 fit_parameter_sensitivity_probe_fraction: float = 0.05
231 fit_parameter_sensitivity_rel_cutoff: float = 1e-10
232 fit_parameter_sensitivity_abs_cutoff: float = 1e-12
233 fit_parameter_sensitivity_keep_on_failure: bool =
True
235 MLE_trace_first_evals: bool =
False
236 MLE_trace_max_evals: int = 25
237 MLE_allow_profile_hessian_fallback: bool =
True
238 MLE_profile_hessian_step_scale: float = 1.0
239 MLE_profile_hessian_eig_floor_rel: float = 1e-8
241 likelihood_mode: StatisticLikelihoodMode = StatisticLikelihoodMode.CHI2_MC_COVARIANCE
242 chi2_covariance_ridge_rel: float = 1e-8
243 chi2_covariance_ridge_abs: float = 1e-12
247 MC_force_decay_threads_to_one: bool =
True
248 MC_forced_decay_threads: int = 1
251 """Convert this Python config to the bound C++ ``AdvancedStatisticConfig``."""
252 cpp = st.AdvancedStatisticConfig()
253 cpp.override_nuisance_marginals = {
257 cpp.override_exp_data_marginals = {
264 cpp.MLE_tol = float(self.
MLE_tol)
280 cpp.fit_parameter_sensitivity_probe_fraction = float(
285 cpp.fit_parameter_sensitivity_keep_on_failure = bool(
303 """Basic configuration of the statistic pipeline.
305 This is the small, common config used by examples and scripts. Advanced
306 minimization, nuisance-pruning and covariance options are grouped in
307 :class:`AdvancedStatisticConfig` under ``advanced``.
310 MC_draws: Number of accepted MC predictions used in uncertainty
311 propagation or chi-square covariance estimation.
312 MC_threads: Number of worker threads used by MC propagation.
313 MC_seed: RNG seed used for reproducible MC nuisance and experimental-data sampling.
314 skew_abs_threshold: Skewness threshold for symmetric vs split-Gaussian
316 print_mc_progress: Print a compact progress bar with live ETA during MC
318 print_chi2_pipeline_progress: In chi-square MC-covariance mode, print
319 the post-MC workflow stages so the MC ETA is not mistaken for the
321 print_mc_config: Print nuisance candidates and retained MC marginal
323 print_fit_summary: Print high-level fit diagnostics.
324 print_scan_summary: Print likelihood-scan diagnostics.
325 print_cache_summary: Enable ``StatisticManager::print_cache`` output.
326 print_debug: Master debug flag enabling extra diagnostic output.
327 write_mc_samples_csv: Persist accepted MC observable samples.
328 mc_samples_csv_path: Output CSV path when sample writing is enabled.
329 advanced: Expert configuration object.
334 MC_seed: int = 123456
335 skew_abs_threshold: float = 0.2
337 print_mc_progress: bool =
False
338 print_chi2_pipeline_progress: bool =
False
339 print_mc_config: bool =
False
340 print_fit_summary: bool =
False
341 print_scan_summary: bool =
False
342 print_cache_summary: bool =
False
343 print_debug: bool =
False
345 write_mc_samples_csv: bool =
False
346 mc_samples_csv_path: str =
"obs_samples.csv"
347 mc_progress_probe_draws: int = 5
348 mc_progress_update_every: int = 1
350 progress_monitor: Optional[StatisticProgressMonitor] =
None
351 fit_parameter_bounds: Dict[ParamId, Tuple[float, float]] = field(default_factory=dict)
352 fit_parameter_offsets: Dict[ParamId, float] = field(default_factory=dict)
353 advanced: AdvancedStatisticConfig = field(default_factory=AdvancedStatisticConfig)
356 """Convert this Python config to the bound C++ ``StatisticConfig``."""
357 cpp = st.StatisticConfig()
360 cpp.MC_seed = int(self.
MC_seed)
375 cpp.fit_parameter_bounds = {
379 cpp.fit_parameter_offsets = {
388 "AdvancedStatisticConfig",
389 "StatisticLikelihoodMode",
390 "StatisticProgressMonitor",
391 "StatisticProgressSnapshot",
bool MLE_allow_profile_hessian_fallback
float nuisance_sensitivity_abs_cutoff
float chi2_covariance_ridge_rel
int nuisance_sensitivity_seed
float nuisance_relevance_cutoff
StatisticLikelihoodMode likelihood_mode
float MLE_profile_hessian_step_scale
float nuisance_sensitivity_context_sigma
bool MLE_trace_first_evals
float nuisance_sensitivity_probe_sigmas
float MLE_profile_hessian_eig_floor_rel
CopulaKind nuisance_copula_type
Dict override_exp_data_marginals
bool MC_force_decay_threads_to_one
bool nuisance_sensitivity_pruning
bool fit_parameter_sensitivity_keep_on_failure
CopulaKind exp_data_copula_type
float nuisance_sensitivity_rel_cutoff
bool nuisance_sensitivity_keep_on_failure
float fit_parameter_sensitivity_probe_fraction
int MC_forced_decay_threads
float chi2_covariance_ridge_abs
bool fit_parameter_sensitivity_check
float nuisance_sensitivity_scale_floor
float fit_parameter_sensitivity_rel_cutoff
int nuisance_sensitivity_contexts
float fit_parameter_sensitivity_abs_cutoff
Dict override_nuisance_marginals
int mc_progress_probe_draws
Dict fit_parameter_offsets
bool print_chi2_pipeline_progress
int mc_progress_update_every
AdvancedStatisticConfig advanced
Optional progress_monitor
bool write_mc_samples_csv
Dict fit_parameter_bounds
StatisticProgressSnapshot snapshot(self)
None set_progress(self, str phase, str message, float fraction, *int completed=0, int total=0, float eta_seconds=-1.0, bool finished=False)
None reset(self, str phase="preparing", str message="Preparing statistic workflow")
_cpp_marginal_kind(MarginalKind kind)
_require(value, typ, str name)
_cpp_experiment_obs(ExperimentObs obs)
_cpp_param_id(ParamId pid)
_cpp_copula_kind(CopulaKind kind)
_cpp_likelihood_mode(StatisticLikelihoodMode mode)