Template Class StateVectorKokkos¶
Defined in File StateVectorKokkos.hpp
Inheritance Relationships¶
Base Type¶
public Pennylane::StateVectorBase< double, StateVectorKokkos< double > >
(Template Class StateVectorBase)
Class Documentation¶
-
template<class fp_t = double>
class StateVectorKokkos : public Pennylane::StateVectorBase<double, StateVectorKokkos<double>>¶ Kokkos state vector class.
- Template Parameters
fp_t – Floating-point precision type.
Public Types
-
using DoubleLoopRank = Kokkos::Rank<2>¶
-
using HostExecSpace = Kokkos::DefaultHostExecutionSpace¶
-
using KokkosExecSpace = Kokkos::DefaultExecutionSpace¶
-
using KokkosSizeTVector = Kokkos::View<std::size_t*>¶
-
using UnmanagedComplexHostView = Kokkos::View<ComplexT*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>¶
-
using UnmanagedSizeTHostView = Kokkos::View<std::size_t*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>¶
-
using UnmanagedConstComplexHostView = Kokkos::View<const ComplexT*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>¶
-
using UnmanagedConstSizeTHostView = Kokkos::View<const std::size_t*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>¶
-
using UnmanagedPrecisionHostView = Kokkos::View<PrecisionT*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>¶
-
using ScratchViewComplex = Kokkos::View<ComplexT*, KokkosExecSpace::scratch_memory_space, Kokkos::MemoryTraits<Kokkos::Unmanaged>>¶
-
using ScratchViewSizeT = Kokkos::View<std::size_t*, KokkosExecSpace::scratch_memory_space, Kokkos::MemoryTraits<Kokkos::Unmanaged>>¶
-
using TeamPolicy = Kokkos::TeamPolicy<>¶
Public Functions
-
StateVectorKokkos() = delete¶
-
inline StateVectorKokkos(std::size_t num_qubits, const Kokkos::InitializationSettings &kokkos_args = {})¶
-
inline void initZeros()¶
Init zeros for the state-vector on device.
-
inline void setBasisState(const std::size_t index)¶
Set value for a single element of the state-vector on device.
- 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.
- Parameters
num_qubits – Number of qubits
-
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.
-
inline void setStateVector(const std::vector<ComplexT> &state, const std::vector<std::size_t> &wires)¶
Set values for a batch of elements of the state-vector.
- Parameters
state – State.
wires – Wires.
-
inline void setStateVector(const ComplexT *state, const std::vector<std::size_t> &wires)¶
Set values for a batch of elements of the state-vector.
- Parameters
state – State.
wires – Wires.
-
inline StateVectorKokkos(ComplexT *hostdata_, std::size_t length, const Kokkos::InitializationSettings &kokkos_args = {})¶
Create a new state vector from data on the host.
- Parameters
num_qubits – Number of qubits
-
inline StateVectorKokkos(std::complex<PrecisionT> *hostdata_, std::size_t length, const Kokkos::InitializationSettings &kokkos_args = {})¶
-
inline StateVectorKokkos(const ComplexT *hostdata_, std::size_t length, const Kokkos::InitializationSettings &kokkos_args = {})¶
Create a new state vector from data on the host.
- Parameters
num_qubits – Number of qubits
-
inline StateVectorKokkos(std::vector<ComplexT> hostdata_, const Kokkos::InitializationSettings &kokkos_args = {})¶
Create a new state vector from data on the host.
- Parameters
num_qubits – Number of qubits
-
inline StateVectorKokkos(const StateVectorKokkos &other, const Kokkos::InitializationSettings &kokkos_args = {})¶
Copy constructor.
- Parameters
other – Another state vector
-
inline ~StateVectorKokkos()¶
Destructor for StateVectorKokkos class.
- Parameters
other – Another state vector
-
inline void applyOperation(const std::string &opName, const std::vector<std::size_t> &wires, bool inverse = false, const std::vector<fp_t> ¶ms = {}, const std::vector<ComplexT> &gate_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 adjoint of gate.
params – Optional parameter list for parametric gates.
gate_matrix – Optional std gate matrix if opName doesn’t exist.
-
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”).
-
template<bool inverse = false>
inline void applyControlledGlobalPhase(const std::vector<ComplexT> &diagonal)¶
-
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<fp_t> ¶ms = {}, const std::vector<ComplexT> &gate_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 adjoint of gate.
params – Optional parameter list for parametric gates.
gate_matrix – Optional std gate matrix if opName doesn’t exist.
-
inline void applyMultiQubitOp(const KokkosVector matrix, const std::vector<std::size_t> &wires, bool inverse = false)¶
Apply a multi qubit operator to the state vector using a matrix.
- Parameters
matrix – Kokkos gate matrix in the device space
wires – Wires to apply gate to.
inverse – Indicates whether to use adjoint of gate.
-
inline void applyMatrix(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.
-
inline void applyMatrix(std::vector<ComplexT> &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 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.
-
inline void applyMatrix(const std::vector<ComplexT> &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 auto applyGenerator(const std::string &opName, const std::vector<std::size_t> &wires, bool inverse = false, const std::vector<fp_t> ¶ms = {}) -> fp_t¶
Apply a single generator to the state vector using the given kernel.
- Parameters
opName – Name of gate to apply.
wires – Wires to apply gate to.
inverse – Indicates whether to use adjoint of gate.
params – Optional parameter list for parametric gates.
-
inline void collapse(std::size_t wire, bool branch)¶
Collapse the state vector 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 updateData(const KokkosVector other)¶
Update data of the class.
- Parameters
other – Kokkos View
-
inline void updateData(const StateVectorKokkos<fp_t> &other)¶
Update data of the class.
- Parameters
other – State vector
-
inline void updateData(ComplexT *new_data, std::size_t new_size)¶
Update data of the class.
- Parameters
new_data – data pointer to new data.
new_size – size of underlying data storage.
-
inline void updateData(std::vector<ComplexT> &other)¶
Update data of the class.
- Parameters
other – STL vector of type ComplexT
-
inline auto getData() -> ComplexT*¶
Get underlying Kokkos view data on the device.
- Returns
ComplexT *
-
inline auto getView() const -> KokkosVector&¶
Get the Kokkos data of the state vector.
- Returns
The pointer to the data of state vector
-
inline auto getView() -> KokkosVector&¶
Get the Kokkos data of the state vector.
- Returns
The pointer to the data of state vector
-
inline auto getDataVector() -> std::vector<ComplexT>¶
Get the vector-converted Kokkos view.
- Returns
std::vector<ComplexT>
-
inline void HostToDevice(ComplexT *sv, std::size_t length)¶
Copy data from the host space to the device space.
-
inline void DeviceToHost(ComplexT *sv, std::size_t length) const¶
Copy data from the device space to the host space.
-
inline void DeviceToDevice(KokkosVector vector_to_copy)¶
Copy data from the device space to the device space.