tidy3d.plugins.autograd.optimizers.BacktrackingSafeUpdate#
- class BacktrackingSafeUpdate[source]#
Bases:
SafeUpdateFind a valid update with global and per-parameter backtracking.
A bare constraint function checks one parameterization at a time. Pass a
ConstraintCheckerimplementation to control how candidates are evaluated, for exampleBatchedConstraintCheckerortidy3d.plugins.klayout.BatchedDRCChecker.The current parameterization is validated first. The full proposed update and successively smaller global updates are then checked from largest to smallest scale. Unless the full update passes, the configured recovery policy improves the accepted global update. If no global candidate passes, recovery starts from the current parameterization instead. Parameter order is deterministic or reproducibly randomized by
candidate_orderandrandom_seed.The returned metrics include the accepted global scale, the norm fraction of the proposed update retained, the number of constraint checks, and the counts of fully accepted, partially accepted, and unchanged parameters.
- Parameters:
checker (ConstraintChecker or Callable) – Candidate checker, or a scalar function that receives one parameterization and returns whether it is valid. Wrap a function with
BatchedConstraintCheckerwhen it accepts a complete batch.max_backtracks (int = 8) – Maximum number of successively shrunken nonzero steps after the full proposed step.
shrink_factor (float = 0.5) – Factor in
(0, 1)used to shrink each successive step.candidate_order ({"deterministic", "random"} = "deterministic") – Order in which parameters are recovered after the global search. Global candidates are always checked first from largest to smallest scale.
random_seed (int, optional = 0) – Seed used for reproducible randomized parameter ordering. Set to
Nonefor nondeterministic ordering.recovery (CoordinateRecovery or SpeculativePrefixRecovery or None) – Policy used after a rejected full global update. Defaults to
SpeculativePrefixRecovery. Set toNoneto retain only the global search.
Attributes
Nonzero candidate step scales from largest to smallest.
Methods
find_safe_update(current, proposed)Return the first valid update, or retain a valid current parameterization.
- checker#
- max_backtracks = 8#
- shrink_factor = 0.5#
- candidate_order = 'deterministic'#
- random_seed = 0#
- recovery#
- property candidate_scales#
Nonzero candidate step scales from largest to smallest.
- find_safe_update(current, proposed)[source]#
Return the first valid update, or retain a valid current parameterization.
- Raises:
RuntimeError – If the current parameterization does not satisfy the constraint.