merlin.utils.deprecations module
- merlin.utils.deprecations.sanitize_parameters(*args, **_kw)
Decorate methods to centralize parameter sanitization.
- Parameters:
args (Any) – Either the decorated callable itself, for bare decorator usage, or a sequence of sanitizer callables for factory usage.
_kw (Any) – Unused keyword arguments accepted for signature flexibility.
- Returns:
Decorated callable or decorator factory result, depending on how the function is invoked.
- Return type:
Any
Notes
Supported usage patterns are:
@sanitize_parameters@sanitize_parameters(proc1, proc2, ...)
The decorator emits standardized warnings or errors based on the global deprecation registry, applies registered converter functions for present deprecated parameters, and then applies any additional processors sequentially.
- merlin.utils.deprecations.warn_deprecated_enum_access(owner, name)
Warn on deprecated enum-style attribute access.
- merlin.utils.deprecations.raise_no_bunching_deprecated(*, stacklevel=2)
Warn and raise when deprecated
no_bunchingis used.- Parameters:
stacklevel (int) – Warning stack level used for the emitted deprecation warning. Default is
2.- Raises:
ValueError – Always raised after emitting the deprecation warning.
- Return type:
- merlin.utils.deprecations.normalize_measurement_strategy(measurement_strategy, computation_space)
Normalize measurement strategy and computation space with deprecation warnings.
Enforces the v0.3 requirement that
computation_spacemust live insideMeasurementStrategywhen using the new factory methods.- Parameters:
measurement_strategy (
MeasurementStrategyLike| str | None) – Measurement strategy provided by the caller. Supports the modern strategy object, legacy enum aliases, legacy strings, orNone.computation_space (ComputationSpace | str | None) – Computation space provided alongside the strategy.
- Returns:
Normalized measurement strategy and resolved computation space.
- Return type:
tuple[
MeasurementStrategyLike, ComputationSpace]- Raises:
TypeError – If the provided strategy is incompatible with the separate
computation_spaceargument or cannot be normalized.ValueError – If a modern
MeasurementStrategydoes not define a computation space.
Notes
The normalization follows these rules:
If MeasurementStrategy instance (new API) + constructor computation_space provided → ERROR: user must move computation_space into the factory method
If measurement_strategy is None and computation_space provided → OK with deprecation warning (default to MeasurementStrategy.probs(computation_space))
If legacy enum (PROBABILITIES, etc) + constructor computation_space → OK with deprecation warning (backward compat)
If MeasurementStrategy instance only → use its computation_space
If legacy enum only → wrap with computation_space param