pub struct VQE<A: Ansatz> { /* private fields */ }Expand description
Variational Quantum Eigensolver for ground state energy estimation.
§Example
ⓘ
use logosq_algorithms::{VQE, Hamiltonian, HardwareEfficientAnsatz};
let hamiltonian = Hamiltonian::new(4);
let ansatz = HardwareEfficientAnsatz::new(4, 2);
let vqe = VQE::new(hamiltonian, ansatz);
println!("VQE has {} parameters", vqe.num_parameters());Implementations§
Source§impl<A: Ansatz> VQE<A>
impl<A: Ansatz> VQE<A>
Sourcepub fn new(hamiltonian: Hamiltonian, ansatz: A) -> Self
pub fn new(hamiltonian: Hamiltonian, ansatz: A) -> Self
Create a new VQE instance.
Sourcepub fn with_shots(self, shots: u32) -> Self
pub fn with_shots(self, shots: u32) -> Self
Set the number of measurement shots.
Sourcepub fn with_max_iterations(self, max_iterations: usize) -> Self
pub fn with_max_iterations(self, max_iterations: usize) -> Self
Set the maximum iterations.
Sourcepub fn with_convergence_threshold(self, threshold: f64) -> Self
pub fn with_convergence_threshold(self, threshold: f64) -> Self
Set the convergence threshold.
Sourcepub fn with_optimizer(self, optimizer: &str) -> Self
pub fn with_optimizer(self, optimizer: &str) -> Self
Set the optimizer.
Sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
Get the number of variational parameters.
Sourcepub fn evaluate(&self, parameters: &[f64]) -> Result<f64, AlgorithmError>
pub fn evaluate(&self, parameters: &[f64]) -> Result<f64, AlgorithmError>
Evaluate energy for given parameters.
Sourcepub fn evaluate_with_gradients(
&self,
parameters: &[f64],
) -> Result<(f64, Vec<f64>), AlgorithmError>
pub fn evaluate_with_gradients( &self, parameters: &[f64], ) -> Result<(f64, Vec<f64>), AlgorithmError>
Evaluate energy and gradients using parameter-shift rule.
Sourcepub fn run(&self) -> Result<VQEResult, AlgorithmError>
pub fn run(&self) -> Result<VQEResult, AlgorithmError>
Run the VQE optimization.
Auto Trait Implementations§
impl<A> Freeze for VQE<A>where
A: Freeze,
impl<A> RefUnwindSafe for VQE<A>where
A: RefUnwindSafe,
impl<A> Send for VQE<A>
impl<A> Sync for VQE<A>
impl<A> Unpin for VQE<A>where
A: Unpin,
impl<A> UnwindSafe for VQE<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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more