qrunch.chemistry.qrackle.scf.convergence_tools.scf_stepper_selection

Shared policy for selecting global and local SCF steppers.

Functions

should_switch_to_local(options, *, gradient, ...)

Determine whether a global SCF run has entered the local region.

switch_to_global_reason(options, *, ...[, ...])

Return the reason a local SCF run should return to the global stepper.

update_stepper_selection(options, state, *, ...)

Update a trajectory's active SCF stepper and return any transition performed.

Classes

SCFStepperSelectionOptionsProtocol

Options required by the SCF stepper-selection policy.

SCFStepperSelectionStateProtocol

Mutable trajectory state required by the shared stepper-selection policy.

SCFStepperSelectionTransition

A stepper-regime transition performed by update_stepper_selection().

class SCFStepperSelectionOptionsProtocol

Bases: Protocol

Options required by the SCF stepper-selection policy.

__init__(*args, **kwargs)
property convergence_slope_threshold: float

Required convergence slope for entering the local region.

property energy_increase_threshold: float

Energy increase considered significant.

property local_region_gradient_exit_threshold: float

Gradient threshold for leaving the local region.

property local_region_gradient_threshold: float

Gradient threshold for entering the local region.

property minimum_number_of_global_iterations_after_fallback: int

Minimum global iterations required after returning from local convergence.

property minimum_number_of_iterations_for_stability_fit: int

Minimum gradient history required to fit the convergence rate.

property number_of_iterations_for_stability_fit: int

Number of recent gradients used to fit the convergence rate.

class SCFStepperSelectionStateProtocol

Bases: Protocol

Mutable trajectory state required by the shared stepper-selection policy.

__init__(*args, **kwargs)
convergence_monitor: ConvergenceMonitor
energy_per_iteration: list[float]
global_steps_since_fallback: int
gradient_at_switch_to_local: float
local_convergence_monitor: ConvergenceMonitor | None
using_local_stepper: bool
class SCFStepperSelectionTransition

Bases: object

A stepper-regime transition performed by update_stepper_selection().

__init__(direction: Literal['global_to_local', 'local_to_global'], reason: str | None = None, slope: float | None = None) → None
Parameters:
  • direction (Literal['global_to_local', 'local_to_global'])

  • reason (str | None)

  • slope (float | None)

Return type:

None

direction: Literal['global_to_local', 'local_to_global']
reason: str | None = None
slope: float | None = None
should_switch_to_local(options: SCFStepperSelectionOptionsProtocol, *, gradient: float, rate: ConvergenceRate | None, global_stepper_indicates_local_region: bool, has_active_local_stepper: bool, global_steps_since_fallback: int, local_region_gradient_threshold: float | None = None) → bool

Determine whether a global SCF run has entered the local region.

Parameters:
  • options (SCFStepperSelectionOptionsProtocol) – SCF stepper-selection thresholds.

  • gradient (float) – Current gradient norm.

  • rate (ConvergenceRate | None) – Recent convergence rate, if enough history exists.

  • global_stepper_indicates_local_region (bool) – Whether the global stepper identifies a local region.

  • has_active_local_stepper (bool) – Whether local convergence is enabled (non DeactivatedSCFStepper). A DeactivatedSCFStepper as the local stepper means the local stepper should never be activated.

  • global_steps_since_fallback (int) – Number of global steps since the most recent fallback.

  • local_region_gradient_threshold (float | None) – Optional local-entry threshold override; zero disables local entry. Does not change the local-exit threshold.

Return type:

bool

switch_to_global_reason(options: SCFStepperSelectionOptionsProtocol, *, gradient: float, gradient_at_switch_to_local: float, rate: ConvergenceRate | None, energy_history: list[float], gradient_history: list[float], scaling_factor_for_gradient_at_switch_to_local: float = 3.0) → str | None

Return the reason a local SCF run should return to the global stepper.

Parameters:
  • options (SCFStepperSelectionOptionsProtocol) – SCF stepper-selection thresholds.

  • gradient (float) – Current gradient norm.

  • gradient_at_switch_to_local (float) – Gradient norm when the trajectory entered the local region.

  • rate (ConvergenceRate | None) – Recent convergence rate, if enough history exists.

  • energy_history (list[float]) – Total-energy history.

  • gradient_history (list[float]) – Local gradient history.

  • scaling_factor_for_gradient_at_switch_to_local (float) – Factor by which the gradient at switch to local is scaled to determine exit. We want the exit gradient condition to be significantly larger than the entry gradient condition.

Return type:

str | None

update_stepper_selection(options: SCFStepperSelectionOptionsProtocol, state: SCFStepperSelectionStateProtocol, *, gradient: float, global_stepper_indicates_local_region: bool, has_active_local_stepper: bool, reset_global_stepper: Callable[[], None], reset_local_stepper: Callable[[], None], accepted_energy_history: list[float] | None = None, local_region_gradient_threshold: float | None = None) → SCFStepperSelectionTransition | None

Update a trajectory’s active SCF stepper and return any transition performed.

Parameters:
  • options (SCFStepperSelectionOptionsProtocol) – SCF stepper-selection thresholds.

  • state (SCFStepperSelectionStateProtocol) – Mutable trajectory state updated by the selection policy.

  • gradient (float) – Current gradient norm.

  • global_stepper_indicates_local_region (bool) – Whether the global stepper identifies a local region.

  • has_active_local_stepper (bool) – Whether local convergence is enabled (non DeactivatedSCFStepper). A DeactivatedSCFStepper as the local stepper means the local stepper should never be activated.

  • reset_global_stepper (Callable[[], None]) – Resets the global stepper after a local fallback.

  • reset_local_stepper (Callable[[], None]) – Resets the local stepper after a global fallback.

  • accepted_energy_history (list[float] | None) – Energies of accepted evaluations, excluding rejected trust-region trials. When omitted, all energies in the trajectory are used.

  • local_region_gradient_threshold (float | None) – Optional local-entry threshold override, used after an instability displacement without modifying the options.

Return type:

SCFStepperSelectionTransition | None