Template Class StateVectorBase

Inheritance Relationships

Derived Types

Class Documentation

template<class T, 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::StateVectorCPU< double, StateVectorRawCPU< double > >, Pennylane::StateVectorCPU< double, StateVectorManagedCPU< double > >

Public Types

using PrecisionT = T

StateVector complex precision type.

using ComplexPrecisionT = std::complex<PrecisionT>

Public Functions

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

Get the number of qubits represented by the statevector data.

Returns

std::size_t

inline size_t getLength() const

Get the size of the statvector.

Returns

The size of the statevector

inline auto getData() -> decltype(auto)

Get the data pointer of the statevector.

Returns

The pointer to the data of statevector

inline auto getData() const -> decltype(auto)
inline auto getKernelForGate(Gates::GateOperation gate_op) const -> Gates::KernelType
inline auto getKernelForGenerator(Gates::GeneratorOperation gntr_op) const -> Gates::KernelType
inline auto getKernelForMatrix(Gates::MatrixOperation mat_op) const -> Gates::KernelType
template<class RhsDerived>
inline bool operator==(const StateVectorBase<PrecisionT, RhsDerived> &rhs)

Compare two statevectors.

Template Parameters

RhsDerived – The derived class for another statevector.

Parameters

rhs – Another statevector to compare.

Returns

bool

inline void applyOperation(Gates::KernelType kernel, const std::string &opName, const std::vector<size_t> &wires, bool inverse = false, const std::vector<PrecisionT> &params = {})

Apply a single gate to the state-vector using a given kernel.

Parameters
  • kernel – Kernel to run the operation.

  • opName – Name of gate to apply.

  • wires – Wires to apply gate to.

  • inverse – Indicates whether to use inverse of gate.

  • params – Optional parameter list for parametric gates.

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

Apply a single gate to the state-vector.

Parameters
  • opName – Name of gate to apply.

  • wires – Wires to apply gate to.

  • inverse – Indicates whether to use inverse 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_inverse, 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_inverse – 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_inverse)

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_inverse – Indicates whether gate at matched index is to be inverted.

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

Apply a single generator to the state-vector using a given kernel.

Parameters
  • kernel – Kernel to run the operation.

  • opName – Name of gate to apply.

  • wires – Wires to apply gate to.

  • adj – Indicates whether to use adjoint of operator.

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

Apply a single generator to the state-vector.

Parameters
  • opName – Name of gate to apply.

  • wires – Wires the gate applies to.

  • adj – Indicates whether to use adjoint of operator.

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

Apply a given matrix directly to the statevector using a given kernel.

Parameters
  • kernel – Kernel to run the operation

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

  • wires – Wires to apply gate to.

  • inverse – Indicate whether inverse should be taken.

inline void applyMatrix(Gates::KernelType kernel, const std::vector<ComplexPrecisionT> &matrix, const std::vector<size_t> &wires, bool inverse = false)

Apply a given matrix directly to the statevector using a given kernel.

Parameters
  • kernel – Kernel to run the operation

  • matrix – Matrix data (in row-major format).

  • wires – Wires to apply gate to.

  • inverse – Indicate whether inverse should be taken.

inline void applyMatrix(const ComplexPrecisionT *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.

template<typename Alloc>
inline void applyMatrix(const std::vector<ComplexPrecisionT, Alloc> &matrix, const std::vector<size_t> &wires, bool inverse = false)

Apply a given matrix directly to the statevector.

Parameters
  • matrix – Matrix data (in row-major format).

  • wires – Wires to apply gate to.

  • inverse – Indicate whether inverse should be taken.

Protected Functions

inline explicit StateVectorBase(size_t num_qubits)

Constructor used by derived classes.

Parameters

num_qubits – Number of qubits

inline void setNumQubits(size_t qubits)

Redefine the number of qubits in the statevector and number of elements.

Parameters

qubits – New number of qubits represented by statevector.