pub struct VqlsSolver { /* private fields */ }Expand description
The VQLS optimiser: holds the operator A, the normalised target |b⟩, and
the ansatz, and minimises the global cost over the ansatz parameters.
Implementations§
Source§impl VqlsSolver
impl VqlsSolver
Sourcepub fn new(
operator: LcuOperator,
b: &[Complex<f32>],
ansatz: HardwareEfficientAnsatz,
) -> QuantumResult<Self>
pub fn new( operator: LcuOperator, b: &[Complex<f32>], ansatz: HardwareEfficientAnsatz, ) -> QuantumResult<Self>
Build a solver for A|x⟩ = |b⟩. b is normalised internally and must be
non-zero with b.len() == 2^{n_qubits}.
§Errors
QuantumError::DimensionMismatchifb’s length or the ansatz qubit count disagree with the operator’s qubit count.QuantumError::InvalidParameterifbis the zero vector.
Sourcepub fn cost(&self, params: &[f32]) -> QuantumResult<f64>
pub fn cost(&self, params: &[f32]) -> QuantumResult<f64>
Evaluate the global cost
C(θ) = 1 − |⟨b|A|x⟩|² / ⟨x|A†A|x⟩ for a given parameter vector.
§Errors
Propagates ansatz preparation errors.
Sourcepub fn solution_state(&self, params: &[f32]) -> QuantumResult<Vec<Complex<f32>>>
pub fn solution_state(&self, params: &[f32]) -> QuantumResult<Vec<Complex<f32>>>
Sourcepub fn optimize(
&self,
init_params: &[f32],
max_iters: usize,
lr: f32,
eps: f32,
tol: f64,
) -> QuantumResult<VqlsResult>
pub fn optimize( &self, init_params: &[f32], max_iters: usize, lr: f32, eps: f32, tol: f64, ) -> QuantumResult<VqlsResult>
Minimise the cost by finite-difference gradient descent.
Starts from init_params, runs up to max_iters iterations with central
difference step eps and an initial learning rate lr that is halved
(backtracking) whenever a step fails to decrease the cost. Stops early when
the cost drops below tol or the learning rate underflows.
§Errors
QuantumError::DimensionMismatchifinit_params.len() != n_params().- Propagates cost-evaluation errors.
Trait Implementations§
Source§impl Clone for VqlsSolver
impl Clone for VqlsSolver
Auto Trait Implementations§
impl Freeze for VqlsSolver
impl RefUnwindSafe for VqlsSolver
impl Send for VqlsSolver
impl Sync for VqlsSolver
impl Unpin for VqlsSolver
impl UnsafeUnpin for VqlsSolver
impl UnwindSafe for VqlsSolver
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
Mutably borrows from an owned value. Read more