Template Class MeasurementsMPI

Inheritance Relationships

Base Type

  • public MeasurementsBase< StateVectorT, MeasurementsMPI< StateVectorT > >

Class Documentation

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

Public Functions

inline explicit MeasurementsMPI(StateVectorT &statevector)
inline PrecisionT expval(StateVectorT &sv)

Expectation value of an observable.

Parameters

sv – Observable-state-vector product.

Returns

Floating point expectation value of the observable.

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

Expectation value of an observable.

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

  • wires – Wires where to apply the operator.

Returns

Floating point expectation value of the observable.

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

Expectation value of an observable.

Parameters
  • operation – String with the operator name.

  • wires – Wires where to apply the operator.

Returns

Floating point expectation value of the observable.

inline PrecisionT expval(Observable<StateVectorT> &ob)

Calculate expectation value for a general Observable.

Parameters

ob – Observable.

Returns

Expectation value with respect to the given observable.

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

Expectation 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 expectation values for the observables.

inline auto expval(const std::vector<std::string> &pauli_words, const std::vector<std::vector<std::size_t>> &target_wires, const std::vector<PrecisionT> &coeffs) -> PrecisionT

Expected value of a Pauli string (Pauli words with coefficients)

Parameters
  • pauli_words – Vector of operators’ name strings.

  • target_wires – Vector of wires where to apply the operator.

  • coeffs – Complex buffer of size |pauli_words|

Returns

Floating point expected value of the observable.

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

Expectation value for a Observable with shots.

Parameters
  • obs – An Observable object.

  • num_shots – Number of shots.

  • shot_range – Vector of shot number to measurement.

Returns

Floating point expected value of the observable.

inline PrecisionT var(StateVectorT &sv)

Variance of an observable.

Parameters

sv – Observable-state-vector product.

Returns

Floating point variance of the observable.

inline PrecisionT var(const std::vector<ComplexT> &matrix, const std::vector<std::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 variance of the 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 variance of the observable.

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

Calculate variance for a general Observable.

Parameters

ob – Observable.

Returns

variance with respect to the given observable.

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

Variance 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 variances for the observables.

inline auto var(const Observable<StateVectorT> &obs, const std::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 for local state vector. Needs MPI Gather to collect probabilities for the full state vector.

This will return the probability local to the MPI rank/global index. To obtain the full probability vector, you need to call MPI Gather.

Returns

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

inline auto probs(const std::vector<std::size_t> &wires, const std::vector<std::size_t> &device_wires = {}) -> std::vector<PrecisionT>

Probabilities for a subset of the full system.

This will return the probability local to the MPI rank/global index. To obtain the full probability vector, you need to call MPI GatherV.

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

  • device_wires – Wires on the device.

Returns

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

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

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 auto probs(std::size_t num_shots) -> std::vector<PrecisionT>

Probabilities with shot-noise.

Parameters

num_shots – Number of shots.

Returns

Floating point std::vector with probabilities.

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

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

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

  • num_shots – Number of shots.

Returns

Floating point std::vector with probabilities.

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

Utility method for samples.

Note that the generated samples are ordered by their global index (bin).

Parameters

num_samples – Number of samples to generate.