tidy3d.plugins.autograd.optimizers.optimize#
- class optimize[source]#
Bases:
Run a full gradient-descent optimization loop (convenience wrapper).
This is a thin convenience wrapper around the optax-style stepping API provided by this module (no optax dependency required). It is not intended to grow into a full optimization framework — for advanced use cases (custom stopping criteria, checkpointing, schedulers, DRC-aware updates, etc.) use the lower-level
optimizer.init/optimizer.update/apply_updatesinterface directly.Uses
autograd.value_and_gradto compute gradients ofobjective_fnat each step, then updates parameters using the providedoptimizer.- Parameters:
objective_fn (Callable[[Params], Union[float, np.ndarray]]) – Scalar-valued objective function evaluated on the current parameters. It must accept the same parameter structure as
params0and return a differentiable scalar (Pythonfloator scalarnp.ndarray) thatautograd.value_and_gradcan handle.params0 (np.ndarray, float, or dict) – Initial parameter values as a single array, a scalar, or a dict of arrays/scalars.
optimizer (Adam) – Optimizer instance that provides
.init()and.update()methods.num_steps (int) – Number of optimization steps to run.
bounds (tuple or dict, optional) – Parameter bounds applied after each update step. For array params: a
(lo, hi)tuple whereNonedisables a side. For dict params: adictmapping parameter keys to(lo, hi)tuples. Keys absent from the dict are left unclipped.callback (Optional[Callable[[Params, Params, AdamState, int, Union[float, np.ndarray]], None]]) – If provided, called each step before the parameter update as
callback(params, grad, state, step_index, objective_val). All arguments reflect the pre-update state of the current iterate, andgrad/objective_valare the raw outputs ofobjective_fnbefore any min/max direction handling. The final (post-loop) params are available in the return value.direction ({"min", "max"} = "min") – Optimization direction.
"min"performs gradient descent onobjective_fn."max"performs gradient ascent by negating the gradient passed to the optimizer while still recording the raw objective values inhistory["objective_fn_val"].
- Returns:
(params, state, history)wherehistoryis a dict with keys"objective_fn_val"and"grad_norm", each a list of per-step values of the raw objective and raw gradient norm, respectively.- Return type: