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:

  1. @sanitize_parameters

  2. @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.

Parameters:
  • owner (str) – Name of the owning class.

  • name (str) – Deprecated enum-style attribute being accessed.

Returns:

True if the access was recognized and handled, False otherwise.

Return type:

bool

merlin.utils.deprecations.raise_no_bunching_deprecated(*, stacklevel=2)

Warn and raise when deprecated no_bunching is 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:

None

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_space must live inside MeasurementStrategy when 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, or None.

  • 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_space argument or cannot be normalized.

  • ValueError – If a modern MeasurementStrategy does not define a computation space.

Notes

The normalization follows these rules:

  1. If MeasurementStrategy instance (new API) + constructor computation_space provided → ERROR: user must move computation_space into the factory method

  2. If measurement_strategy is None and computation_space provided → OK with deprecation warning (default to MeasurementStrategy.probs(computation_space))

  3. If legacy enum (PROBABILITIES, etc) + constructor computation_space → OK with deprecation warning (backward compat)

  4. If MeasurementStrategy instance only → use its computation_space

  5. If legacy enum only → wrap with computation_space param