1616
1717
1818class MinimizerBase (ABC ):
19- """Abstract base class for minimizer implementations.
20-
21- Provides shared logic and structure for concrete minimizers.
19+ """Abstract base for concrete minimizers.
20+
21+ Contract:
22+ - Subclasses must implement ``_prepare_solver_args``,
23+ ``_run_solver``, ``_sync_result_to_parameters`` and
24+ ``_check_success``.
25+ - The ``fit`` method orchestrates the full workflow and returns
26+ :class:`FitResults`.
2227 """
2328
2429 def __init__ (
@@ -39,18 +44,29 @@ def __init__(
3944 self .tracker : FitProgressTracker = FitProgressTracker ()
4045
4146 def _start_tracking (self , minimizer_name : str ) -> None :
47+ """Initialize progress tracking and timer.
48+
49+ Args:
50+ minimizer_name: Human-readable name shown in progress.
51+ """
4252 self .tracker .reset ()
4353 self .tracker .start_tracking (minimizer_name )
4454 self .tracker .start_timer ()
4555
4656 def _stop_tracking (self ) -> None :
57+ """Stop timer and finalize tracking."""
4758 self .tracker .stop_timer ()
4859 self .tracker .finish_tracking ()
4960
5061 @abstractmethod
5162 def _prepare_solver_args (self , parameters : List [Any ]) -> Dict [str , Any ]:
52- """Prepare the solver arguments directly from the list of free
53- parameters.
63+ """Prepare keyword-arguments for the underlying solver.
64+
65+ Args:
66+ parameters: List of free parameters to be fitted.
67+
68+ Returns:
69+ Mapping of keyword arguments to pass into ``_run_solver``.
5470 """
5571 pass
5672
@@ -60,6 +76,7 @@ def _run_solver(
6076 objective_function : Callable [..., Any ],
6177 engine_parameters : Dict [str , Any ],
6278 ) -> Any :
79+ """Execute the concrete solver and return its raw result."""
6380 pass
6481
6582 @abstractmethod
@@ -68,13 +85,25 @@ def _sync_result_to_parameters(
6885 raw_result : Any ,
6986 parameters : List [Any ],
7087 ) -> None :
88+ """Copy values from ``raw_result`` back to ``parameters`` in-
89+ place.
90+ """
7191 pass
7292
7393 def _finalize_fit (
7494 self ,
7595 parameters : List [Any ],
7696 raw_result : Any ,
7797 ) -> FitResults :
98+ """Build :class:`FitResults` and store it on ``self.result``.
99+
100+ Args:
101+ parameters: Parameters after the solver finished.
102+ raw_result: Backend-specific solver output object.
103+
104+ Returns:
105+ FitResults: Aggregated outcome of the fit.
106+ """
78107 self ._sync_result_to_parameters (parameters , raw_result )
79108 success = self ._check_success (raw_result )
80109 self .result = FitResults (
@@ -89,17 +118,24 @@ def _finalize_fit(
89118
90119 @abstractmethod
91120 def _check_success (self , raw_result : Any ) -> bool :
92- """Determine whether the fit was successful.
93-
94- This must be implemented by concrete minimizers.
95- """
121+ """Determine whether the fit was successful."""
96122 pass
97123
98124 def fit (
99125 self ,
100126 parameters : List [Any ],
101127 objective_function : Callable [..., Any ],
102128 ) -> FitResults :
129+ """Run the full minimization workflow.
130+
131+ Args:
132+ parameters: Free parameters to optimize.
133+ objective_function: Callable returning residuals for a given
134+ set of engine arguments.
135+
136+ Returns:
137+ FitResults with success flag, best chi2 and timing.
138+ """
103139 minimizer_name = self .name or 'Unnamed Minimizer'
104140 if self .method is not None :
105141 minimizer_name += f' ({ self .method } )'
@@ -123,6 +159,7 @@ def _objective_function(
123159 experiments : Any ,
124160 calculator : Any ,
125161 ) -> np .ndarray :
162+ """Default objective helper computing residuals array."""
126163 return self ._compute_residuals (
127164 engine_params ,
128165 parameters ,
@@ -138,6 +175,7 @@ def _create_objective_function(
138175 experiments : Any ,
139176 calculator : Any ,
140177 ) -> Callable [[Dict [str , Any ]], np .ndarray ]:
178+ """Return a closure capturing problem context for the solver."""
141179 return lambda engine_params : self ._objective_function (
142180 engine_params ,
143181 parameters ,
0 commit comments