Template Class HamiltonianBase¶
Defined in File Observables.hpp
Inheritance Relationships¶
Base Type¶
public Pennylane::Observables::Observable< StateVectorT >
(Template Class Observable)
Class Documentation¶
-
template<class StateVectorT>
class HamiltonianBase : public Pennylane::Observables::Observable<StateVectorT>¶ Base class for a general Hamiltonian representation as a sum of observables.
- Template Parameters
StateVectorT – State vector class.
Public Types
-
using PrecisionT = typename StateVectorT::PrecisionT¶
Public Functions
-
template<typename T1, typename T2>
inline HamiltonianBase(T1 &&coeffs, T2 &&obs)¶ Create a Hamiltonian from coefficients and observables.
- Parameters
coeffs – Arguments to construct coefficients
obs – Arguments to construct observables
-
inline virtual void applyInPlace(StateVectorT &sv) const override¶
Apply the observable to the given statevector in place.
-
inline virtual void applyInPlaceShots(StateVectorT &sv, std::vector<std::vector<PrecisionT>> &eigenValues, std::vector<std::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 getWires() const -> std::vector<std::size_t> override¶
Get the wires the observable applies to.
-
inline virtual auto getObsName() const -> std::string override¶
Get the name of the observable.
-
inline virtual auto getObs() const -> std::vector<std::shared_ptr<Observable<StateVectorT>>> override¶
Get the observable.
-
inline virtual auto getCoeffs() const -> std::vector<PrecisionT> override¶
Get the coefficients of the observable.
Public Static Functions
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
coeffs – Arguments to construct coefficients
obs – Arguments to construct observables
- Returns
std::shared_ptr<HamiltonianBase<StateVectorT>>
Protected Attributes
-
std::vector<PrecisionT> coeffs_¶
-
std::vector<std::shared_ptr<Observable<StateVectorT>>> obs_¶