Template Class StateVectorLQubit

Inheritance Relationships

Base Type

Class Documentation

template<class PrecisionT, class Derived>
class StateVectorLQubit : public Pennylane::StateVectorBase<PrecisionT, Derived>

Lightning qubit state vector class.

Minimal class, without data storage, for the Lightning qubit state vector. This class interfaces with the dynamic dispatcher and threading functionalities and is a bridge between the base (agnostic) class and specializations for distinct data storage types.

Template Parameters
  • PrecisionT – Floating point precision of underlying state vector data.

  • Derived – Derived class for CRTP.

Public Types

using ComplexT = std::complex<PrecisionT>
using MemoryStorageT = Pennylane::Util::MemoryStorageLocation::Undefined

Public Functions

inline CPUMemoryModel memoryModel() const

Get the statevector’s memory model.

inline Threading threading() const

Get the statevector’s threading mode.

inline auto getSupportedKernels() const & -> std::tuple<const GateKernelMap&, const GeneratorKernelMap&, const MatrixKernelMap&, const ControlledGateKernelMap&, const ControlledGeneratorKernelMap&, const ControlledMatrixKernelMap&>

Returns a tuple containing the gate, generator, and controlled matrix kernel maps respectively.

inline auto getSupportedKernels() && -> std::tuple<GateKernelMap&&, GeneratorKernelMap&&, MatrixKernelMap&&, ControlledGateKernelMap&&, ControlledGeneratorKernelMap&&, ControlledMatrixKernelMap&&>
inline void applyOperation(Pennylane::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 applyOperation(const std::string &opName, const std::vector<size_t> &controlled_wires, const std::vector<bool> &controlled_values, 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.

  • controlled_wires – Control wires.

  • controlled_values – Control values (false or true).

  • wires – Wires to apply gate to.

  • inverse – Indicates whether to use inverse of gate.

  • params – Optional parameter list for parametric gates.

template<typename Alloc>
inline void applyOperation(const std::string &opName, const std::vector<size_t> &wires, bool inverse, const std::vector<PrecisionT> &params, const std::vector<ComplexT, Alloc> &matrix)

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.

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

template<typename Alloc>
inline void applyOperation(const std::string &opName, const std::vector<size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<size_t> &wires, bool inverse, const std::vector<PrecisionT> &params, const std::vector<ComplexT, Alloc> &matrix)

Apply a single gate to the state-vector.

Parameters
  • opName – Name of gate to apply.

  • controlled_wires – Control wires.

  • controlled_values – Control values (false or true).

  • wires – Wires to apply gate to.

  • inverse – Indicates whether to use inverse of gate.

  • params – Optional parameter list for parametric gates.

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

inline auto applyGenerator(Pennylane::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 auto applyGenerator(const std::string &opName, const std::vector<size_t> &controlled_wires, const std::vector<bool> &controlled_values, 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.

  • controlled_wires – Control wires.

  • controlled_values – Control values (false or true).

  • wires – Wires the gate applies to.

  • adj – Indicates whether to use adjoint of operator.

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

Apply a given controlled-matrix directly to the statevector.

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

  • controlled_wires – Control wires.

  • controlled_values – Control values (false or true).

  • wires – Wires to apply gate to.

  • inverse – Indicate whether inverse should be taken.

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

Apply a given controlled-matrix directly to the statevector.

Parameters
  • matrix – Vector containing the statevector data (in row-major format).

  • controlled_wires – Control wires.

  • controlled_values – Control values (false or true).

  • wires – Wires to apply gate to.

  • inverse – Indicate whether inverse should be taken.

inline void applyMatrix(Pennylane::Gates::KernelType kernel, const ComplexT *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(Pennylane::Gates::KernelType kernel, const std::vector<ComplexT> &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 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.

template<typename Alloc>
inline void applyMatrix(const std::vector<ComplexT, 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.

inline void collapse(const std::size_t wire, const bool branch)

Collapse the state vector as after having measured one of the qubits.

The branch parameter imposes the measurement result on the given wire.

Parameters
  • wire – Wire to collapse.

  • branch – Branch 0 or 1.

inline void normalize()

Normalize vector (to have norm 1).

Protected Functions

inline explicit StateVectorLQubit(size_t num_qubits, Threading threading, CPUMemoryModel memory_model)

Protected Attributes

const Threading threading_
const CPUMemoryModel memory_model_