Template Class TensorProdObsBase

Inheritance Relationships

Base Type

Class Documentation

template<class StateVectorT>
class TensorProdObsBase : public Pennylane::Observables::Observable<StateVectorT>

Base class for a tensor product of observables.

Template Parameters

StateVectorT – State vector class.

Public Types

using PrecisionT = typename StateVectorT::PrecisionT

Public Functions

template<typename ...Ts>
inline explicit TensorProdObsBase(Ts&&... arg)

Create a tensor product of observables.

Parameters

arg – Arguments perfect forwarded to vector of observables.

inline auto getSize() const -> size_t

Get the number of operations in observable.

Returns

size_t

inline virtual auto getWires() const -> std::vector<size_t> override

Get the wires for each observable operation.

Returns

const std::vector<std::vector<size_t>>&

inline virtual void applyInPlace(StateVectorT &sv) const override

Apply the observable to the given statevector in place.

inline virtual auto getObs() const -> std::vector<std::shared_ptr<Observable<StateVectorT>>> override

Get the observable.

inline virtual void applyInPlaceShots(StateVectorT &sv, std::vector<std::vector<PrecisionT>> &eigenValues, std::vector<size_t> &ob_wires) const override

Apply unitaries of an observable to the given statevector in place.

Parameters
  • sv – Reference to StateVector object.

  • eigenValues – Eigenvalues of an observable.

  • ob_wires – Reference to a std::vector object which stores wires of the observable.

inline virtual auto getObsName() const -> std::string override

Get the name of the observable.

Public Static Functions

static inline auto create(std::initializer_list<std::shared_ptr<Observable<StateVectorT>>> obs) -> std::shared_ptr<TensorProdObsBase<StateVectorT>>

Convenient wrapper for the constructor as the constructor does not convert the std::shared_ptr with a derived class correctly.

This function is useful as std::make_shared does not handle brace-enclosed initializer list correctly.

Parameters

obs – List of observables

Returns

std::shared_ptr<TensorProdObsBase<StateVectorT>>

static inline auto create(std::vector<std::shared_ptr<Observable<StateVectorT>>> obs) -> std::shared_ptr<TensorProdObsBase<StateVectorT>>

Convenient wrapper for the constructor as the constructor does not convert the std::shared_ptr with a derived class correctly.

This function is useful as std::make_shared does not handle brace-enclosed initializer list correctly.

Parameters

obs – List of observables

Returns

std::shared_ptr<TensorProdObsBase<StateVectorT>>

Protected Attributes

std::vector<std::shared_ptr<Observable<StateVectorT>>> obs_
std::vector<size_t> all_wires_