Skip to content

⚡ [Feature]: Implement a Centralized Configuration System #60

Description

@PPeitsch

Problem Description

Currently, algorithm parameters (e.g., smoothing_window, peak_prominence, min_points_fit) are hardcoded as default values in the signatures of many different functions and methods across the codebase. This approach has several drawbacks:

  1. Inconsistency: It's difficult to ensure that related parameters are consistent across different modules.
  2. Difficult to Tune: To change a default behavior globally, a developer must find and modify every instance of that parameter, which is error-prone.
  3. Reproducibility Issues: If a default parameter value changes between library versions, users' scripts might produce different results without any code changes, harming reproducibility.

Proposed Solution

Implement a centralized configuration system, similar to the options system in pandas or matplotlib. This would provide a single, global point of control for the default parameters of all analysis algorithms.

The proposed system would work as follows:

  1. A central configuration object would be available, e.g., pkynetics.options.
  2. Users could inspect and modify these global defaults in their scripts.
import pkynetics

# View all peak detection options
print(pkynetics.options.peak_detection)

# Globally change the default prominence for all subsequent analyses
pkynetics.options.peak_detection.prominence = 0.05
  1. All functions in the library would be refactored to use these global defaults when a parameter is not explicitly provided by the user.

Alternative Solutions

  • Status Quo: Continue with hardcoded defaults. (Rejected: Not scalable or reproducible).
  • Configuration Files (YAML/JSON): Allow loading configurations from files. This could be an extension of the proposed system but adds complexity for a first implementation. The programmatic API should be prioritized.

Additional Context

This is a significant architectural improvement that will enhance the library's usability, maintainability, and scientific rigor by promoting reproducible analyses. Although it requires a considerable refactoring effort, the long-term benefits are substantial.

Implementation Details

  1. Create a pkynetics/config.py module to house the configuration object and its API (set_option, get_option, etc.). A nested class or dictionary structure could be used.
  2. Systematically refactor each module (e.g., dsc, dilatometry, model_fitting_methods) to use the new configuration system. The pattern would be:
    # Before:
    # def my_function(param: int = 21): ...
    
    # After:
    from pkynetics import options
    def my_function(param: Optional[int] = None):
        if param is None:
            param = options.some_module.param_default
        # ...
  3. This work can be done incrementally, module by module, to make it manageable.

Guidelines

  • I agree to follow this project's Contributing Guidelines
  • I have searched for similar feature requests
  • I understand that this is a request and implementation is not guaranteed

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions