pub struct QuantumAnnealing<A: Float + ScalarOperand + Debug> { /* private fields */ }Expand description
Quantum annealing optimizer.
QuantumAnnealing performs a Metropolis-based stochastic search where each
candidate update is a perturbation of the current parameters whose magnitude
is scaled by the current temperature. The acceptance probability blends the
classical Boltzmann factor with a quantum-inspired tunneling kernel:
P(accept) = min(1, exp(-ΔE / (k * T) + Γ * exp(-‖δ‖²)))where ΔE is approximated by the dot product gradients · δ (treating the
supplied gradient as an unbiased local descent direction), Γ is the
tunneling strength and δ is the candidate perturbation.
Temperature follows a geometric (exponential) decay
T(t) = T_initial * (T_final / T_initial)^(t / N)which is well-behaved for arbitrary positive endpoints and reproduces
T(0) = T_initial, T(N) = T_final exactly.
§Examples
use optirs_core::quantum_inspired::QuantumAnnealing;
use optirs_core::optimizers::Optimizer;
use scirs2_core::ndarray::Array1;
let mut optimizer: QuantumAnnealing<f64> = QuantumAnnealing::new(0.05)
.with_temperature_schedule(2.0, 0.01)
.with_tunneling(0.5)
.with_seed(123);
let params = Array1::from_vec(vec![1.0, -1.0, 0.5]);
let gradients = params.mapv(|x| 2.0 * x);
let next = optimizer.step(¶ms, &gradients).expect("step failed");
assert_eq!(next.len(), 3);Implementations§
Source§impl<A> QuantumAnnealing<A>
impl<A> QuantumAnnealing<A>
Sourcepub fn new(learning_rate: A) -> Self
pub fn new(learning_rate: A) -> Self
Creates a new quantum annealing optimizer with the given learning rate and all other parameters set to sensible defaults.
Sourcepub fn with_temperature_schedule(self, initial: A, final_t: A) -> Self
pub fn with_temperature_schedule(self, initial: A, final_t: A) -> Self
Configure the temperature schedule endpoints.
initial must be strictly greater than final_t and both must be
positive. The current temperature is reset to initial on each call so
chained builders behave intuitively.
Sourcepub fn with_tunneling(self, strength: A) -> Self
pub fn with_tunneling(self, strength: A) -> Self
Configure the tunneling strength Γ.
Larger values increase the average acceptance rate by enlarging the quantum-inspired kernel contribution to the Metropolis exponent.
Sourcepub fn with_iterations(self, num_iterations: usize) -> Self
pub fn with_iterations(self, num_iterations: usize) -> Self
Configure the number of iterations the cooling schedule spans.
Sourcepub fn current_temperature(&self) -> A
pub fn current_temperature(&self) -> A
Returns the temperature for the current step.
Sourcepub fn best_energy(&self) -> A
pub fn best_energy(&self) -> A
Returns the best proxy energy discovered so far. Initialised to +∞.
Sourcepub fn current_step(&self) -> usize
pub fn current_step(&self) -> usize
Returns the current step count.
Sourcepub fn initial_temperature(&self) -> A
pub fn initial_temperature(&self) -> A
Returns the configured initial temperature.
Sourcepub fn final_temperature(&self) -> A
pub fn final_temperature(&self) -> A
Returns the configured final temperature.
Sourcepub fn tunneling_strength(&self) -> A
pub fn tunneling_strength(&self) -> A
Returns the configured tunneling strength.
Sourcepub fn num_iterations(&self) -> usize
pub fn num_iterations(&self) -> usize
Returns the configured number of iterations.
Sourcepub fn learning_rate(&self) -> A
pub fn learning_rate(&self) -> A
Returns the current learning rate. This is an inherent helper so the
caller does not need to qualify a dimension D to invoke the trait
implementation of Optimizer::get_learning_rate.
Sourcepub fn set_lr(&mut self, learning_rate: A)
pub fn set_lr(&mut self, learning_rate: A)
Set the learning rate. Inherent helper that mirrors the trait method.
Sourcepub fn best_params<D: Dimension>(&self) -> Option<Array<A, D>>
pub fn best_params<D: Dimension>(&self) -> Option<Array<A, D>>
Returns a clone of the best parameters seen so far, reshaped to the requested dimensionality.
Trait Implementations§
Source§impl<A: Debug + Float + ScalarOperand + Debug> Debug for QuantumAnnealing<A>
impl<A: Debug + Float + ScalarOperand + Debug> Debug for QuantumAnnealing<A>
Source§impl<A, D> Optimizer<A, D> for QuantumAnnealing<A>
impl<A, D> Optimizer<A, D> for QuantumAnnealing<A>
Source§fn step(
&mut self,
params: &Array<A, D>,
gradients: &Array<A, D>,
) -> Result<Array<A, D>>
fn step( &mut self, params: &Array<A, D>, gradients: &Array<A, D>, ) -> Result<Array<A, D>>
Source§fn get_learning_rate(&self) -> A
fn get_learning_rate(&self) -> A
Source§fn set_learning_rate(&mut self, learning_rate: A)
fn set_learning_rate(&mut self, learning_rate: A)
Auto Trait Implementations§
impl<A> Freeze for QuantumAnnealing<A>where
A: Freeze,
impl<A> RefUnwindSafe for QuantumAnnealing<A>where
A: RefUnwindSafe,
impl<A> Send for QuantumAnnealing<A>where
A: Send,
impl<A> Sync for QuantumAnnealing<A>where
A: Sync,
impl<A> Unpin for QuantumAnnealing<A>where
A: Unpin,
impl<A> UnsafeUnpin for QuantumAnnealing<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for QuantumAnnealing<A>where
A: UnwindSafe,
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> 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.