Template Class StateVectorLQubit¶
Defined in File StateVectorLQubit.hpp
Inheritance Relationships¶
Base Type¶
public Pennylane::StateVectorBase< PrecisionT, Derived >
(Template Class StateVectorBase)
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>¶
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<std::size_t> &wires, bool inverse = false, const std::vector<PrecisionT> ¶ms = {})¶
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<std::size_t> &wires, bool inverse = false, const std::vector<PrecisionT> ¶ms = {})¶
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<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool inverse = false, const std::vector<PrecisionT> ¶ms = {})¶
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<std::size_t> &wires, bool inverse, const std::vector<PrecisionT> ¶ms, 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<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool inverse, const std::vector<PrecisionT> ¶ms, 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 void applyPauliRot(const std::vector<std::size_t> &wires, const bool inverse, const std::vector<PrecisionT> ¶ms, const std::string &word)¶
Apply a PauliRot gate to the state-vector.
- Parameters
wires – Wires to apply gate to.
inverse – Indicates whether to use inverse of gate.
params – Rotation angle.
word – A Pauli word (e.g. “XYYX”).
-
inline auto applyGenerator(Pennylane::Gates::KernelType kernel, const std::string &opName, const std::vector<std::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<std::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<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::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<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::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<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::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<std::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<std::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<std::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<std::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).
-
inline void setBasisState(const std::size_t index)¶
Prepares a single computational basis state.
- Parameters
index – Index of the target element.
-
inline void setBasisState(const std::vector<std::size_t> &state, const std::vector<std::size_t> &wires)¶
Prepares a single computational basis state.
- Parameters
state – Binary number representing the index
wires – Wires.
-
inline void resetStateVector()¶
Reset the data back to the \(\ket{0}\) state.
-
inline void setStateVector(const std::vector<std::size_t> &indices, const std::vector<ComplexT> &values)¶
Set values for a batch of elements of the state-vector.
- Parameters
values – Values to be set for the target elements.
indices – Indices of the target elements.
Protected Functions
-
inline explicit StateVectorLQubit(std::size_t num_qubits, Threading threading, CPUMemoryModel memory_model)¶