Template Class SparseHamiltonianBase

Inheritance Relationships

Base Type

Class Documentation

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

Sparse representation of SparseHamiltonian<T>

Template Parameters

T – Floating-point precision.

Public Types

using PrecisionT = typename StateVectorT::PrecisionT
using ComplexT = typename StateVectorT::ComplexT
using IdxT = std::size_t

Public Functions

template<typename T1, typename T2, typename T3 = T2, typename T4 = std::vector<std::size_t>>
inline SparseHamiltonianBase(T1 &&data, T2 &&indices, T3 &&offsets, T4 &&wires)

Create a SparseHamiltonianBase from data, indices and offsets in CSR format.

Parameters
  • data – Arguments to construct data

  • indices – Arguments to construct indices

  • offsets – Arguments to construct offsets

  • wires – Arguments to construct wires

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 getObsName() const -> std::string override

Get the name of the observable.

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

Get the wires the observable applies to.

Public Static Functions

static inline auto create(std::initializer_list<ComplexT> data, std::initializer_list<IdxT> indices, std::initializer_list<IdxT> offsets, std::initializer_list<std::size_t> wires) -> std::shared_ptr<SparseHamiltonianBase<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
  • data – Argument to construct data

  • indices – Argument to construct indices

  • offsets – Argument to construct offsets

  • wires – Argument to construct wires

Protected Attributes

std::vector<ComplexT> data_
std::vector<IdxT> indices_
std::vector<IdxT> offsets_
std::vector<std::size_t> wires_