pub enum Optimizer {
GradientDescent {
learning_rate: f64,
},
Adam {
learning_rate: f64,
beta1: f64,
beta2: f64,
epsilon: f64,
m: Array1<f64>,
v: Array1<f64>,
},
SPSA {
learning_rate: f64,
perturbation: f64,
},
QuantumNaturalGradient {
learning_rate: f64,
regularization: f64,
},
SciRS2 {
method: String,
config: HashMap<String, f64>,
adam_m: Array1<f64>,
adam_v: Array1<f64>,
lbfgs_history: Vec<(Array1<f64>, Array1<f64>)>,
prev_params: Option<Array1<f64>>,
prev_gradient: Option<Array1<f64>>,
cg_direction: Option<Array1<f64>>,
},
}Expand description
Optimizer for quantum machine learning models
Variants§
GradientDescent
Gradient descent
Adam
Adam optimizer
Fields
SPSA
SPSA optimizer
QuantumNaturalGradient
Quantum Natural Gradient optimizer.
This variant stores the scalar hyper-parameters only. Callers are expected
to pre-condition gradients through QuantumAutoDiff::natural_gradients()
(which requires a circuit executor closure) and then pass the resulting
natural-gradient vector to update_parameters. The regularization field
is used as additive damping: Δθ_i = −lr · g_i / (1 + reg).
Fields
SciRS2
SciRS2-based optimizers: Adam, L-BFGS (two-loop recursion), and
nonlinear Conjugate Gradient (Fletcher-Reeves/Polak-Ribiere), each
with real per-parameter state carried between update_parameters
calls.
Fields
lbfgs_history: Vec<(Array1<f64>, Array1<f64>)>Bounded curvature-pair history (s_k, y_k) for L-BFGS’s
two-loop recursion (method == “lbfgs”), newest last, truncated to
config["m"] entries.
Implementations§
Source§impl Optimizer
impl Optimizer
Sourcepub fn new(method: OptimizationMethod) -> Self
pub fn new(method: OptimizationMethod) -> Self
Creates a new optimizer with default parameters
Sourcepub fn update_parameters(
&mut self,
parameters: &mut Array1<f64>,
gradients: &ArrayView1<'_, f64>,
iteration: usize,
) -> Result<()>
pub fn update_parameters( &mut self, parameters: &mut Array1<f64>, gradients: &ArrayView1<'_, f64>, iteration: usize, ) -> Result<()>
Updates parameters based on gradients.
Each variant now carries and mutates its own real optimizer state
(Adam’s first/second moments, L-BFGS’s curvature-pair history, CG’s
previous conjugate direction, …), so this takes &mut self.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Optimizer
impl RefUnwindSafe for Optimizer
impl Send for Optimizer
impl Sync for Optimizer
impl Unpin for Optimizer
impl UnsafeUnpin for Optimizer
impl UnwindSafe for Optimizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.