Template Class Hamiltonian

Inheritance Relationships

Base Type

Class Documentation

template<typename T>
class Hamiltonian : public Pennylane::Algorithms::Observable<T>

General Hamiltonian as a sum of observables.

TODO: Check whether caching a sparse matrix representation can give a speedup

Public Types

using PrecisionT = T

Public Functions

template<typename T1, typename T2>
inline Hamiltonian(T1 &&arg1, T2 &&arg2)

Create a Hamiltonian from coefficients and observables.

Parameters
  • arg1 – Arguments to construct coefficients

  • arg2 – Arguments to construct observables

inline virtual void applyInPlace(StateVectorManagedCPU<T> &sv) const override

Apply the observable to the given statevector in place.

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

Get the wires the observable applies to.

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

Get the name of the observable.

Public Static Functions

static inline auto create(std::initializer_list<T> arg1, std::initializer_list<std::shared_ptr<Observable<T>>> arg2) -> std::shared_ptr<Hamiltonian<T>>

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
  • arg1 – Argument to construct coefficients

  • arg2 – Argument to construct terms