optimization.optimizer.torch.base

Torch Base Optimizer

This module contains a base class for all PyTorch-based optimizers.

Kramer Harrison, 2025

Classes

TorchBaseOptimizer(problem)

A base class for all PyTorch-based optimizers.

class TorchBaseOptimizer(problem: OptimizationProblem)[source]

A base class for all PyTorch-based optimizers.

This class handles the common setup and optimization loop logic for any optimizer using the PyTorch backend.

optimize(n_steps: int = 100, lr: float = 0.01, gamma: float = 0.99, disp: bool = True, plot: bool = False, callback: Callable[[int, float], None] | None = None)[source]

Runs the optimization loop.

Parameters:
  • n_steps (int) – The number of optimization steps.

  • lr (float) – The learning rate.

  • gamma (float) – The decay factor for the learning rate.

  • disp (bool) – Whether to display progress.

  • plot – If True, update live plots during optimization.

  • callback (Callable[[int, float], None] | None) – A callback function to be called after each step with the current step and loss value.