Template Class StateVectorKokkos

Inheritance Relationships

Base Type

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 PrecisionT = fp_t
using ComplexT = Kokkos::complex<fp_t>
using CFP_t = ComplexT
using DoubleLoopRank = Kokkos::Rank<2>
using HostExecSpace = Kokkos::DefaultHostExecutionSpace
using KokkosExecSpace = Kokkos::DefaultExecutionSpace
using KokkosVector = Kokkos::View<ComplexT*>
using KokkosSizeTVector = Kokkos::View<size_t*>
using UnmanagedComplexHostView = Kokkos::View<ComplexT*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
using UnmanagedSizeTHostView = Kokkos::View<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 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<size_t*, KokkosExecSpace::scratch_memory_space, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
using TeamPolicy = Kokkos::TeamPolicy<>
using MemoryStorageT = Pennylane::Util::MemoryStorageLocation::Undefined

Public Functions

StateVectorKokkos() = delete
inline StateVectorKokkos(size_t num_qubits, const Kokkos::InitializationSettings &kokkos_args = {})
inline void initZeros()

Init zeros for the state-vector on device.

inline void setBasisState(const size_t index)

Set value for a single element of the state-vector on device.

Parameters

index – Index of the target element.

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 resetStateVector()

Reset the data back to the \(\ket{0}\) state.

Parameters

num_qubits – Number of qubits

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<size_t> &wires, bool inverse = false, const std::vector<fp_t> &params = {}, 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.

template<bool inverse = false>
inline void applyControlledGlobalPhase(const std::vector<ComplexT> &diagonal)
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<fp_t> &params = {}, 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<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<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<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<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 applyNamedOperation(const std::string &opName, const std::vector<size_t> &wires, bool inverse = false, const std::vector<fp_t> &params = {})
inline auto applyGenerator(const std::string &opName, const std::vector<size_t> &wires, bool inverse = false, const std::vector<fp_t> &params = {}) -> 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.

template<template<class, bool> class functor_t, int nqubits>
inline void applyGateFunctor(const std::vector<size_t> &wires, bool inverse = false, const std::vector<fp_t> &params = {})

Templated method that applies special n-qubit gates.

Template Parameters
  • functor_t – Gate functor class for Kokkos dispatcher.

  • nqubits – Number of qubits.

Parameters
  • wires – Wires to apply gate to.

  • inverse – Indicates whether to use adjoint of gate.

  • params – parameters for this gate

inline void applyMultiRZ(const std::vector<size_t> &wires, bool inverse = false, const std::vector<fp_t> &params = {})

Apply a MultiRZ operator to the state vector using a matrix.

Parameters
  • wires – Wires to apply gate to.

  • inverse – Indicates whether to use adjoint of gate.

  • params – parameters for this gate

inline void applyGlobalPhase(const std::vector<size_t> &wires, bool inverse = false, const std::vector<fp_t> &params = {})

Apply a GlobalPhase operator to the state vector using a matrix.

Parameters
  • wires – Wires to apply gate to.

  • inverse – Indicates whether to use adjoint of gate.

  • params – parameters for this gate

inline auto applyGeneratorMultiRZ(const std::vector<size_t> &wires, bool inverse = false, [[maybe_unused]] const std::vector<fp_t> &params = {}) -> fp_t

Apply a MultiRZ generator to the state vector using a matrix.

Parameters
  • wires – Wires to apply gate to.

  • inverse – Indicates whether to use adjoint of gate.

  • params – parameters for this gate

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*
inline auto getData() const -> const 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 underlying data vector.

inline auto getDataVector() const -> const 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.