Template Class Observable

Inheritance Relationships

Derived Types

Class Documentation

template<class StateVectorT>
class Observable

A base class (CRTP) for all observable classes.

We note that all subclasses must be immutable (does not provide any setter).

Template Parameters

StateVectorT – State vector class.

Subclassed by Pennylane::Observables::HamiltonianBase< StateVectorT >, Pennylane::Observables::HermitianObsBase< StateVectorT >, Pennylane::Observables::NamedObsBase< StateVectorT >, Pennylane::Observables::SparseHamiltonianBase< StateVectorT >, Pennylane::Observables::TensorProdObsBase< StateVectorT >

Public Types

using PrecisionT = typename StateVectorT::PrecisionT

Public Functions

virtual ~Observable() = default
virtual void applyInPlace(StateVectorT &sv) const = 0

Apply the observable to the given statevector in place.

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

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.

virtual auto getObsName() const -> std::string = 0

Get the name of the observable.

virtual auto getWires() const -> std::vector<size_t> = 0

Get the wires the observable applies to.

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

Get the observable data.

inline virtual auto getCoeffs() const -> std::vector<PrecisionT>

Get the coefficients of a Hamiltonian observable.

inline auto operator==(const Observable<StateVectorT> &other) const -> bool

Test whether this object is equal to another object.

inline auto operator!=(const Observable<StateVectorT> &other) const -> bool

Test whether this object is different from another object.

Protected Functions

Observable() = default
Observable(const Observable&) = default
Observable(Observable&&) noexcept = default
Observable &operator=(const Observable&) = default
Observable &operator=(Observable&&) noexcept = default