Template Class StateVectorBase

Inheritance Relationships

Derived Types

Class Documentation

template<class PrecisionT, class Derived>
class StateVectorBase

State-vector base class.

This class combines a data array managed by a derived class (CRTP) and implementations of gate operations. The bound data is assumed to be complex, and is required to be in either 32-bit (64-bit complex<float>) or 64-bit (128-bit complex<double>) floating point representation. As this is the base class, we do not add default template arguments.

Template Parameters
  • T – Floating point precision of underlying statevector data.

  • Derived – Type of a derived class

Subclassed by Pennylane::LightningGPU::StateVectorCudaBase< double, StateVectorCudaManaged< double > >, Pennylane::LightningGPU::StateVectorCudaBase< double, StateVectorCudaMPI< double > >, Pennylane::LightningQubit::StateVectorLQubit< double, StateVectorLQubitManaged< double > >, Pennylane::LightningQubit::StateVectorLQubit< double, StateVectorLQubitRaw< double > >, Pennylane::LightningQubit::StateVectorLQubit< PrecisionT, Derived >

Public Types

using ComplexT = std::complex<PrecisionT>

StateVector complex precision type.

Public Functions

inline explicit StateVectorBase(size_t num_qubits)

Constructor used by derived classes.

Parameters

num_qubits – Number of qubits

inline auto getNumQubits() const -> std::size_t

Get the number of qubits represented by the statevector data.

Returns

std::size_t

inline auto getTotalNumQubits() const -> size_t

Get the total number of qubits of the simulated system.

Returns

std::size_t

inline size_t getLength() const

Get the size of the statevector.

Returns

The size of the statevector

inline auto getData() -> decltype(auto)

Get the data pointer of the statevector.

Returns

A pointer to the statevector data

inline auto getData() const -> decltype(auto)
inline void applyOperation(const std::string &opName, const std::vector<size_t> &wires, bool adjoint = false, const std::vector<PrecisionT> &params = {})

Apply a single gate to the state-vector.

Parameters
  • opName – Gate’s name.

  • wires – Wires to apply gate to.

  • adjoint – Indicates whether to use adjoint of gate.

  • params – Optional parameter list for parametric gates.

inline void applyOperations(const std::vector<std::string> &ops, const std::vector<std::vector<size_t>> &ops_wires, const std::vector<bool> &ops_adjoint, const std::vector<std::vector<PrecisionT>> &ops_params)

Apply multiple gates to the state-vector.

Parameters
  • ops – Vector of gate names to be applied in order.

  • ops_wires – Vector of wires on which to apply index-matched gate name.

  • ops_adjoint – Indicates whether gate at matched index is to be inverted.

  • ops_params – Optional parameter data for index matched gates.

inline void applyOperations(const std::vector<std::string> &ops, const std::vector<std::vector<size_t>> &ops_wires, const std::vector<bool> &ops_adjoint)

Apply multiple gates to the state-vector.

Parameters
  • ops – Vector of gate names to be applied in order.

  • ops_wires – Vector of wires on which to apply index-matched gate name.

  • ops_adjoint – Indicates whether gate at matched index is to be inverted.

inline auto applyGenerator(const std::string &opName, const std::vector<size_t> &wires, bool adjoint = false) -> PrecisionT

Apply a single generator to the state-vector.

Parameters
  • opName – Name of generator to apply.

  • wires – Wires the generator applies to.

  • adjoint – Indicates whether to use adjoint of operator.

inline void applyMatrix(const ComplexT *matrix, const std::vector<size_t> &wires, bool inverse = false)

Apply a given matrix directly to the statevector using a raw matrix pointer vector.

Parameters
  • matrix – Pointer to the array data (in row-major format).

  • wires – Wires to apply gate to.

  • inverse – Indicate whether inverse should be taken.

Protected Attributes

size_t num_qubits_ = {0}