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.error_deprecated_enum_access(owner, name)

Fail on deprecated enum-style attribute access.

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

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

Return type:

None

Raises:

AttributeError – If owner is "MeasurementStrategy" and name is one of the deprecated enum-style attributes listed in _MEASUREMENT_STRATEGY_ENUM_MIGRATIONS.

merlin.utils.deprecations.raise_no_bunching_removed()

Raise when the removed no_bunching flag is used.

Returns:

This function never returns normally.

Return type:

None

Raises:

ValueError – Always raised with the 0.4 migration guidance.

merlin.utils.deprecations.normalize_measurement_strategy(measurement_strategy)

Normalize measurement strategy and computation space with deprecation errors.

Parameters:

measurement_strategy (MeasurementStrategyLike | str | None) – Measurement strategy provided by the caller. Supports the modern strategy object, legacy enum aliases, legacy strings, or None.

Returns:

Normalized measurement strategy and resolved computation space.

Return type:

tuple[MeasurementStrategyLike, ComputationSpace]

Raises:
  • TypeError – If the provided strategy is a string: which is an invalid measurement strategy.

  • 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 MeasurementStrategy instance only → use its computation_space

  3. If MeasurementStrategy.NONE -> use amplitudes with the default computation space