pub struct QuantumSampler { /* private fields */ }Expand description
Shot-based quantum sampler
Implementations§
Source§impl QuantumSampler
impl QuantumSampler
Sourcepub fn new(config: SamplingConfig) -> Self
pub fn new(config: SamplingConfig) -> Self
Create new sampler with configuration
Sourcepub fn sample_state(&mut self, state: &Array1<Complex64>) -> Result<ShotResult>
pub fn sample_state(&mut self, state: &Array1<Complex64>) -> Result<ShotResult>
Sample measurements from a quantum state
Sourcepub fn sample_state_with_noise(
&mut self,
state: &Array1<Complex64>,
noise_model: &dyn NoiseModel,
) -> Result<ShotResult>
pub fn sample_state_with_noise( &mut self, state: &Array1<Complex64>, noise_model: &dyn NoiseModel, ) -> Result<ShotResult>
Sample measurements from a state with noise
Sourcepub fn sample_expectation(
&mut self,
state: &Array1<Complex64>,
observable: &PauliOperatorSum,
) -> Result<ExpectationResult>
pub fn sample_expectation( &mut self, state: &Array1<Complex64>, observable: &PauliOperatorSum, ) -> Result<ExpectationResult>
Sample expectation value of an observable
Sourcepub fn sample_multinomial(
&mut self,
probabilities: &[f64],
n_samples: usize,
) -> Result<Vec<usize>>
pub fn sample_multinomial( &mut self, probabilities: &[f64], n_samples: usize, ) -> Result<Vec<usize>>
Multinomial sampling: draw n_samples i.i.d. samples from a discrete
probability distribution.
The result is a count vector of the same length as probabilities, where
counts[i] is the number of times outcome i was drawn. Total counts
sum to n_samples.
The implementation uses the inverse-CDF (Alias/sequential) method which is O(k · n_samples) in the number of outcomes k, but correct and deterministic given the sampler’s current RNG state.
Sourcepub fn importance_sampling(
&mut self,
target_probs: &[f64],
proposal_probs: &[f64],
f_values: &[f64],
n_samples: usize,
) -> Result<ImportanceSamplingResult>
pub fn importance_sampling( &mut self, target_probs: &[f64], proposal_probs: &[f64], f_values: &[f64], n_samples: usize, ) -> Result<ImportanceSamplingResult>
Importance sampling: estimate the expectation E_p[f] using samples drawn from a proposal distribution q.
Given a target distribution target_probs (unnormalised is fine) and a
proposal distribution proposal_probs (must be strictly positive wherever
target_probs is non-zero), this method:
- Draws
n_samplesindices fromproposal_probs. - Evaluates the function values
f_values[i]at each outcomei. - Computes the self-normalised importance-sampling estimator
Ê = Σ w̃_i f_iwherew̃_i = w_i / Σ w_jandw_i = p_i / q_i.
Returns (estimate, effective_sample_size). The effective sample size
(ESS) measures how many i.i.d. samples from target_probs the weighted
sample is worth: ESS = (Σ w̃_i)² / Σ w̃_i².
§Errors
Returns an error if the distributions have different lengths, if
proposal_probs has a zero entry where target_probs is non-zero, or
if either distribution is empty.
Sourcepub fn estimate_convergence(
&mut self,
state: &Array1<Complex64>,
observable: &PauliOperatorSum,
) -> Result<ConvergenceResult>
pub fn estimate_convergence( &mut self, state: &Array1<Complex64>, observable: &PauliOperatorSum, ) -> Result<ConvergenceResult>
Estimate convergence of sampling
Auto Trait Implementations§
impl Freeze for QuantumSampler
impl RefUnwindSafe for QuantumSampler
impl Send for QuantumSampler
impl Sync for QuantumSampler
impl Unpin for QuantumSampler
impl UnsafeUnpin for QuantumSampler
impl UnwindSafe for QuantumSampler
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
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
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.