Template Class Measurements

Inheritance Relationships

Base Type

  • public MeasurementsBase< StateVectorT, Measurements< StateVectorT > >

Class Documentation

template<class StateVectorT>
class Measurements : public MeasurementsBase<StateVectorT, Measurements<StateVectorT>>

Public Functions

inline explicit Measurements(const StateVectorT &statevector)
template<template<class> class functor_t, int num_wires>
inline PrecisionT applyExpValNamedFunctor(const std::vector<size_t> &wires)

Templated method that returns the expectation value of named observables.

Template Parameters
  • functor_t – Expectation value functor class for Kokkos dispatcher.

  • nqubits – Number of wires.

Parameters

wires – Wires to apply the observable to.

template<template<class> class functor_t, int num_wires>
inline PrecisionT applyExpValFunctor(const KokkosVector &matrix, const std::vector<size_t> &wires)

Templated method that returns the expectation value of a matrix-valued operator.

Template Parameters
  • functor_t – Expectation value functor class for Kokkos dispatcher.

  • nqubits – Number of wires.

Parameters
  • matrix – Matrix (linearized into a KokkosVector).

  • wires – Wires to apply the observable to.

inline auto getExpValMatrix(const KokkosVector &matrix, const std::vector<std::size_t> &wires) -> PrecisionT

Calculate expectation value with respect to multi qubit observable on specified wires.

Parameters
  • matrix – Hermitian matrix representing observable to be used.

  • wires – Wires to apply observable to.

  • params – Not used.

Returns

Expectation value with respect to observable applied to specified wires.

inline PrecisionT expval(const Observable<StateVectorT> &ob)

Calculate expectation value for a general Observable.

Parameters

ob – Observable.

Returns

Expectation value with respect to the given observable.

inline PrecisionT expval(const Pennylane::LightningKokkos::Observables::HermitianObs<StateVectorT> &ob)

Calculate expectation value for a HermitianObs.

Parameters

ob – HermitianObs.

Returns

Expectation value with respect to the given observable.

inline PrecisionT expval(const std::vector<ComplexT> &matrix_, const std::vector<size_t> &wires)

Expected value of an observable.

Parameters
  • matrix – Square matrix in row-major order.

  • wires – Wires where to apply the operator.

Returns

Floating point expected value of the observable.

inline PrecisionT expval(const std::string &operation, const std::vector<size_t> &wires)

Expected value of an observable.

Parameters
  • operation – String with the operator name.

  • wires – Wires where to apply the operator.

Returns

Floating point expected value of the observable.

template<typename op_type>
inline std::vector<PrecisionT> expval(const std::vector<op_type> &operations_list, const std::vector<std::vector<size_t>> &wires_list)

Expected value for a list of observables.

Template Parameters

op_type – Operation type.

Parameters
  • operations_list – List of operations to measure.

  • wires_list – List of wires where to apply the operators.

Returns

Floating point std::vector with expected values for the observables.

inline auto expval(const Observable<StateVectorT> &obs, const size_t &num_shots, const std::vector<size_t> &shot_range) -> PrecisionT

Expectation value for a Observable with shots.

Parameters
  • obs – Observable.

  • num_shots – Number of shots.

  • shots_range – Vector of shot number to measurement.

Returns

Floating point expected value of the observable.

template<class index_type>
inline PrecisionT expval(const index_type *row_map_ptr, const index_type row_map_size, const index_type *entries_ptr, const ComplexT *values_ptr, const index_type numNNZ)

Expected value of a Sparse Hamiltonian.

Template Parameters

index_type – integer type used as indices of the sparse matrix.

Parameters
  • row_map_ptr – row_map array pointer. The j element encodes the number of non-zeros above row j.

  • row_map_size – row_map array size.

  • entries_ptr – pointer to an array with column indices of the non-zero elements.

  • values_ptr – pointer to an array with the non-zero elements.

  • numNNZ – number of non-zero elements.

Returns

Floating point expected value of the observable.

inline auto var(const Observable<StateVectorT> &ob) -> PrecisionT

Calculate variance of a general Observable.

Parameters

ob – Observable.

Returns

Variance with respect to the given observable.

inline PrecisionT var(const std::string &operation, const std::vector<size_t> &wires)

Variance of an observable.

Parameters
  • operation – String with the operator name.

  • wires – Wires where to apply the operator.

Returns

Floating point with the variance of the observable.

inline PrecisionT var(const std::vector<ComplexT> &matrix, const std::vector<size_t> &wires)

Variance of an observable.

Parameters
  • matrix – Square matrix in row-major order.

  • wires – Wires where to apply the operator.

Returns

Floating point with the variance of the observable.

template<typename op_type>
inline std::vector<PrecisionT> var(const std::vector<op_type> &operations_list, const std::vector<std::vector<size_t>> &wires_list)

Variance for a list of observables.

Template Parameters

op_type – Operation type.

Parameters
  • operations_list – List of operations to measure. Square matrix in row-major order or string with the operator name.

  • wires_list – List of wires where to apply the operators.

Returns

Floating point std::vector with the variance of the observables.

template<class index_type>
inline PrecisionT var(const index_type *row_map_ptr, const index_type row_map_size, const index_type *entries_ptr, const ComplexT *values_ptr, const index_type numNNZ)

Variance of a sparse Hamiltonian.

Template Parameters

index_type – integer type used as indices of the sparse matrix.

Parameters
  • row_map_ptr – row_map array pointer. The j element encodes the number of non-zeros above row j.

  • row_map_size – row_map array size.

  • entries_ptr – pointer to an array with column indices of the non-zero elements.

  • values_ptr – pointer to an array with the non-zero elements.

  • numNNZ – number of non-zero elements.

Returns

Floating point with the variance of the sparse Hamiltonian.

inline auto var(const Observable<StateVectorT> &obs, const size_t &num_shots) -> PrecisionT

Calculate the variance for an observable with the number of shots.

Parameters
  • obs – An observable object.

  • num_shots – Number of shots.

Returns

Variance of the given observable.

inline auto probs() -> std::vector<PrecisionT>

Probabilities to measure rotated basis states.

Returns

Floating point std::vector with probabilities in lexicographic order.

inline std::vector<PrecisionT> probs(const std::vector<size_t> &wires)

Probabilities for a subset of the full system.

Parameters

wires – Wires will restrict probabilities to a subset of the full system.

Returns

Floating point std::vector with probabilities. The basis columns are rearranged according to wires.

inline std::vector<PrecisionT> probs(const Observable<StateVectorT> &obs, size_t num_shots = 0)

Probabilities of each computational basis state for an observable.

Parameters
  • obs – An observable object.

  • num_shots – Number of shots. If specified with a non-zero number, shot-noise will be added to return probabilities

Returns

Floating point std::vector with probabilities in lexicographic order.

inline std::vector<PrecisionT> probs(size_t num_shots)

Probabilities with shot-noise.

Parameters

num_shots – Number of shots.

Returns

Floating point std::vector with probabilities.

inline std::vector<PrecisionT> probs(const std::vector<size_t> &wires, size_t num_shots)

Probabilities with shot-noise for a subset of the full system.

Parameters
  • num_shots – Number of shots.

  • wires – Wires will restrict probabilities to a subset of the full system.

Returns

Floating point std::vector with probabilities.

inline auto generate_samples(size_t num_samples) -> std::vector<size_t>

Inverse transform sampling method for samples. Reference https://en.wikipedia.org/wiki/Inverse_transform_sampling.

Parameters

num_samples – Number of Samples

Returns

std::vector<size_t> to the samples. Each sample has a length equal to the number of qubits. Each sample can be accessed using the stride sample_id*num_qubits, where sample_id is a number between 0 and num_samples-1.