Template Class MeasurementsTNCuda

Class Documentation

template<class TensorNetT>
class MeasurementsTNCuda

ObservablesTNCuda’s Measurement Class.

This class couples with a tensor network to perform measurements. Observables are defined in the observable class.

Template Parameters

TensorNetT – type of the tensor network to be measured.

Public Functions

inline explicit MeasurementsTNCuda(const TensorNetT &tensor_network)
template<std::size_t thread_per_block = 256>
inline auto probs(const std::vector<std::size_t> &wires, const int32_t numHyperSamples = 1) -> std::vector<PrecisionT>

Probabilities for a subset of the full system.

Template Parameters

thread_per_block – Number of threads per block in the CUDA kernel and is default as 256. 256 is chosen as a default value because it is a balance of warp size and occupancy. Note that this number is not optimal for all cases and may need to be adjusted based on the specific use case, especially the number of elements in the subset is small.

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

  • numHyperSamples – Number of hyper samples to be used in the calculation and is default as 1.

Returns

Floating point std::vector with probabilities.

inline auto generate_samples(const std::vector<std::size_t> &wires, const std::size_t num_samples, const int32_t numHyperSamples = 1) -> std::vector<std::size_t>

Utility method for samples.

Parameters
  • wires – Wires can be a subset or the full system.

  • num_samples – Number of samples

  • numHyperSamples – Number of hyper samples to use in the calculation and is default as 1.

Returns

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

inline auto var(ObservableTNCuda<TensorNetT> &obs, const int32_t numHyperSamples = 1) -> PrecisionT

Calculate var value for a general ObservableTNCuda Observable.

Current implementation ensure that only one cutensornetNetworkOperator_t object is attached to the circuit.

Parameters
  • obs – An Observable object.

  • numHyperSamples – Number of hyper samples to use in the calculation and is default as 1.

inline auto expval(ObservableTNCuda<TensorNetT> &obs, const int32_t numHyperSamples = 1) -> PrecisionT

Calculate expectation value for a general ObservableTNCuda Observable.

Parameters
  • obs – An Observable object.

  • numHyperSamples – Number of hyper samples to use in the calculation and is default as 1.

Returns

Expectation value with respect to the given observable.