optimize_s_params#

simpleEMS.sim_tools.optimize_s_params(simulate_fn: Callable, x0: dict[str, float], output_path: Path, bounds: tuple | None = None) → None#

Optimize simulation parameters using SciPy’s Nelder-Mead algorithm.

Runs scipy.optimize.minimize(..., method="Nelder-Mead") over simulate_fn, starting from x0. Stops on SciPy’s own convergence criteria (xatol=1e-3, fatol=1e-3), or early via a callback that stops the optimization once the parameter vector moves by less than 1e-4 (Euclidean norm) for 5 consecutive iterations. Prints the optimal parameter values to stdout when finished.

Parameters:
  • simulate_fn (callable) – Simulation function invoked at each optimization step as simulate_fn(output_path=output_path, optimize=True, optimize_val=x), where x is the current parameter vector (in the order of x0’s values). Must return a scalar cost to minimize, e.g. via optimize_s11 or optimize_s21.

  • x0 (dict[str, float]) – Initial parameter values, used as the optimization starting point. Keys are used only for the final printout; the order of the values defines the parameter vector order passed to simulate_fn.

  • output_path (Path) – Directory where simulation results are stored; forwarded to simulate_fn on every call.

  • bounds (sequence of (float, float), optional) – Per-parameter (min, max) bounds, in the same order as x0’s values, passed through to scipy.optimize.minimize. None in a pair means no bound on that side. Default is None (unbounded).

Returns:

Does not return a value; prints the optimal parameters found.

Return type:

None