diff --git a/CHANGELOG.md b/CHANGELOG.md index 348e970cd..4d4321bb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ New Feature - Adds an option ``scaled_termination`` (defaults to True) to all of the desc optimizers to measure the norms for ``xtol`` and ``gtol`` in the scaled norm provided by ``x_scale`` (which defaults to using an adaptive scaling based on the Jacobian or Hessian). This should make things more robust when optimizing parameters with widely different magnitudes. The old behavior can be recovered by passing ``options={"scaled_termination": False}``. - ``desc.objectives.Omnigenity`` is now vectorized and able to optimize multiple surfaces at the same time. Previously it was required to use a different objective for each surface. - Adds a new objective ``desc.objectives.MirrorRatio`` for targeting a particular mirror ratio on each flux surface, for either an ``Equilibrium`` or ``OmnigenousField``. +- Adds a new objective ``desc.objectives.ExternalObjective`` for wrapping external codes with finite differences. Bug Fixes diff --git a/desc/objectives/_generic.py b/desc/objectives/_generic.py index cf5f66c31..8570c2389 100644 --- a/desc/objectives/_generic.py +++ b/desc/objectives/_generic.py @@ -25,17 +25,17 @@ class ExternalObjective(_Objective, ABC): computed with finite differences instead of AD. The function does not need not be JAX transformable. - The user supplied function must take an Equilibrium as its only positional argument, - but can take additional keyword arguments. + The user supplied function must take an Equilibrium or a list of Equilibria as its + only positional argument, but can take additional keyword arguments. Parameters ---------- eq : Equilibrium Equilibrium that will be optimized to satisfy the Objective. fun : callable - External objective function. It must take an Equilibrium as its only positional - argument, but can take additional kewyord arguments. It does not need to be JAX - transformable. + External objective function. It must take an Equilibrium or list of Equilibria + as its only positional argument, but can take additional kewyord arguments. + It does not need to be JAX transformable. dim_f : int Dimension of the output of ``fun``. target : {float, ndarray}, optional @@ -60,7 +60,8 @@ class ExternalObjective(_Objective, ABC): is called on the raw compute value, before any shifting, scaling, or normalization. vectorized : bool, optional - Whether or not ``fun`` is vectorized. Default = False. + Set to False if ``fun`` takes a single Equilibrium as its positional argument. + Set to True if ``fun`` instead takes a list of Equilibria. Default = False. abs_step : float, optional Absolute finite difference step size. Default = 1e-4. Total step size is ``abs_step + rel_step * mean(abs(x))``. @@ -72,8 +73,6 @@ class ExternalObjective(_Objective, ABC): kwargs : any, optional Keyword arguments that are passed as inputs to ``fun``. - # TODO: add example - """ _units = "(Unknown)"