Template Class Measures¶
Defined in File Measures.hpp
Class Documentation¶
-
template<class fp_t = double, class SVType = StateVectorRawCPU<fp_t>>
class Measures¶ Observable’s Measurement Class.
This class performs measurements in the state vector provided to its constructor. Observables are defined by its operator(matrix) or through a string-based function dispatch.
- Template Parameters
fp_t – Floating point precision of underlying measurements.
SVType – type of the statevector to be measured.
Public Functions
-
inline std::vector<fp_t> probs()¶
Probabilities of each computational basis state.
- Returns
Floating point std::vector with probabilities in lexicographic order.
-
inline std::vector<fp_t> 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 fp_t expval(const std::vector<CFP_t> &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 fp_t 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<class index_type>
inline fp_t expval(const index_type *row_map_ptr, const index_type row_map_size, const index_type *entries_ptr, const CFP_t *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
fp_t floating point precision.
-
template<typename op_type>
inline std::vector<fp_t> 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 fp_t 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 observables.
-
inline fp_t var(const std::vector<CFP_t> &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 observables.
-
template<typename op_type>
inline std::vector<fp_t> 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.
-
inline std::vector<size_t> generate_samples(size_t num_samples)¶
Generate samples using the alias method. Reference: https://en.wikipedia.org/wiki/Alias_method.
- Parameters
num_samples – The number of samples to generate.
- Returns
1-D vector of samples in binary, each sample is separated by a stride equal to the number of qubits.