pub struct HybridQuantumClassical<A: Float + ScalarOperand + Debug> { /* private fields */ }Expand description
Hybrid quantum-classical optimizer.
HybridQuantumClassical blends quantum-inspired exploration with classical
refinement, much in the spirit of variational hybrid algorithms. The first
switch_step updates are produced by a QuantumAnnealing instance that
performs broad exploration of the loss landscape. Subsequent updates are
produced by an Adam instance whose state is implicitly warm-started by
the best parameters discovered by the annealer.
§Examples
use optirs_core::quantum_inspired::HybridQuantumClassical;
use optirs_core::optimizers::Optimizer;
use scirs2_core::ndarray::Array1;
let mut optimizer: HybridQuantumClassical<f64> =
HybridQuantumClassical::new(0.05, 50);
let params = Array1::from_vec(vec![1.0, -1.0, 0.5]);
let grads = Array1::from_vec(vec![0.1, -0.2, 0.05]);
let _ = optimizer.step(¶ms, &grads).expect("step failed");Implementations§
Source§impl<A> HybridQuantumClassical<A>
impl<A> HybridQuantumClassical<A>
Sourcepub fn new(learning_rate: A, switch_step: usize) -> Self
pub fn new(learning_rate: A, switch_step: usize) -> Self
Create a new hybrid optimizer with default sub-optimizer settings.
Sourcepub fn with_quantum(self, quantum: QuantumAnnealing<A>) -> Self
pub fn with_quantum(self, quantum: QuantumAnnealing<A>) -> Self
Replace the underlying quantum annealer.
Sourcepub fn with_classical(self, classical: Adam<A>) -> Self
pub fn with_classical(self, classical: Adam<A>) -> Self
Replace the underlying classical optimizer.
Sourcepub fn with_quantum_config<F>(self, f: F) -> Self
pub fn with_quantum_config<F>(self, f: F) -> Self
Configure the quantum annealer via a builder closure.
Sourcepub fn with_classical_config<F>(self, f: F) -> Self
pub fn with_classical_config<F>(self, f: F) -> Self
Configure the classical optimizer via a builder closure.
Sourcepub fn phase(&self) -> OptimizationPhase
pub fn phase(&self) -> OptimizationPhase
Returns the current optimization phase.
Sourcepub fn switch_step(&self) -> usize
pub fn switch_step(&self) -> usize
Returns the configured switch step.
Sourcepub fn current_step(&self) -> usize
pub fn current_step(&self) -> usize
Returns the current step counter.
Sourcepub fn learning_rate(&self) -> A
pub fn learning_rate(&self) -> A
Returns the current learning rate, choosing the relevant sub-optimizer based on the current phase.
Sourcepub fn set_lr(&mut self, learning_rate: A)
pub fn set_lr(&mut self, learning_rate: A)
Set the learning rate on both the quantum annealer and the classical optimizer simultaneously.
Sourcepub fn quantum(&self) -> &QuantumAnnealing<A>
pub fn quantum(&self) -> &QuantumAnnealing<A>
Returns an immutable reference to the underlying quantum annealer.
Sourcepub fn classical(&self) -> &Adam<A>
pub fn classical(&self) -> &Adam<A>
Returns an immutable reference to the underlying classical optimizer.
Sourcepub fn quantum_mut(&mut self) -> &mut QuantumAnnealing<A>
pub fn quantum_mut(&mut self) -> &mut QuantumAnnealing<A>
Returns a mutable reference to the underlying quantum annealer.
Sourcepub fn classical_mut(&mut self) -> &mut Adam<A>
pub fn classical_mut(&mut self) -> &mut Adam<A>
Returns a mutable reference to the underlying classical optimizer.
Trait Implementations§
Source§impl<A: Debug + Float + ScalarOperand + Debug> Debug for HybridQuantumClassical<A>
impl<A: Debug + Float + ScalarOperand + Debug> Debug for HybridQuantumClassical<A>
Source§impl<A, D> Optimizer<A, D> for HybridQuantumClassical<A>
impl<A, D> Optimizer<A, D> for HybridQuantumClassical<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 HybridQuantumClassical<A>where
A: Freeze,
impl<A> RefUnwindSafe for HybridQuantumClassical<A>where
A: RefUnwindSafe,
impl<A> Send for HybridQuantumClassical<A>where
A: Send,
impl<A> Sync for HybridQuantumClassical<A>where
A: Sync,
impl<A> Unpin for HybridQuantumClassical<A>where
A: Unpin,
impl<A> UnsafeUnpin for HybridQuantumClassical<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for HybridQuantumClassical<A>where
A: UnwindSafe + RefUnwindSafe,
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.