Template Class StateVectorCudaManaged¶
Defined in File StateVectorCudaManaged.hpp
Inheritance Relationships¶
Base Type¶
public Pennylane::LightningGPU::StateVectorCudaBase< double, StateVectorCudaManaged< double > >
(Template Class StateVectorCudaBase)
Class Documentation¶
-
template<class Precision = double>
class StateVectorCudaManaged : public Pennylane::LightningGPU::StateVectorCudaBase<double, StateVectorCudaManaged<double>>¶ Managed memory CUDA state-vector class using custateVec backed gate-calls.
- Template Parameters
Precision – Floating-point precision type.
Public Types
-
using ComplexT = std::complex<PrecisionT>¶
-
using CFP_t = typename StateVectorCudaBase<Precision, StateVectorCudaManaged<Precision>>::CFP_t¶
Public Functions
-
StateVectorCudaManaged() = delete¶
-
inline StateVectorCudaManaged(std::size_t num_qubits)¶
-
inline StateVectorCudaManaged(const StateVectorCudaManaged &other)¶
-
~StateVectorCudaManaged() = default¶
-
inline void resetStateVector(bool use_async = false)¶
the statevector data to the |0…0> state.
- Parameters
use_async – Use an asynchronous memory copy or not. Default is false.
-
inline void setBasisState(const std::vector<std::size_t> &state, const std::vector<std::size_t> &wires, const bool use_async = false)¶
Prepare a single computational basis state.
- Parameters
state – Binary number representing the index
wires – Wires.
use_async(Optional[bool]) – immediately sync with host-sv after applying operation.
-
inline void setStateVector(const ComplexT *state_ptr, const std::size_t num_states, const std::vector<std::size_t> &wires, bool use_async = false)¶
Set values for a batch of elements of the state-vector.
- Parameters
state_ptr – Pointer to the initial state data.
num_states – Length of the initial state data.
wires – Wires.
use_async – Use an asynchronous memory copy. Default is false.
-
inline void applyOperation(const std::string &opName, const std::vector<std::size_t> &wires, bool adjoint, const std::vector<Precision> ¶ms, const std::vector<ComplexT> &matrix)¶
Apply a single gate to the state-vector. Offloads to custatevec specific API calls if available. If unable, attempts to use prior cached gate values on the device. Lastly, accepts a host-provided matrix if otherwise, and caches on the device for later reuse.
- Parameters
opName – Name of gate to apply.
wires – Wires to apply gate to.
adjoint – Indicates whether to use adjoint of gate.
params – Optional parameter list for parametric gates.
matrix – Gate data (in row-major format).
-
inline void applyOperation(const std::string &opName, const std::vector<std::size_t> &wires, bool adjoint = false, const std::vector<Precision> ¶ms = {0.0}, const std::vector<CFP_t> &gate_matrix = {})¶
Apply a single gate to the state-vector. Offloads to custatevec specific API calls if available. If unable, attempts to use prior cached gate values on the device. Lastly, accepts a host-provided matrix if otherwise, and caches on the device for later reuse.
- Parameters
opName – Name of gate to apply.
wires – Wires to apply gate to.
adjoint – Indicates whether to use adjoint of gate.
params – Optional parameter list for parametric gates.
gate_matrix – Gate data (in row-major format).
-
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> &tgt_wires, bool adjoint, const std::vector<Precision> ¶ms, const std::vector<ComplexT> &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).
tgt_wires – Wires to apply gate to.
adjoint – Indicates whether to use adjoint of gate.
params – Optional parameter list for parametric gates.
matrix – Gate data (in row-major format).
-
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> &tgt_wires, bool adjoint = false, const std::vector<Precision> ¶ms = {0.0}, const std::vector<CFP_t> &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).
tgt_wires – Wires to apply gate to.
adjoint – Indicates whether to use adjoint of gate.
params – Optional parameter list for parametric gates.
gate_matrix – Gate data (in row-major format).
-
inline void applyControlledMatrix(const ComplexT *gate_matrix, const std::size_t matrix_size, const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &tgt_wires, bool inverse = false)¶
Apply a single gate to the state vector.
- Parameters
gate_matrix – Gate matrix data (in row-major format).
matrix_size – Size of the matrix.
controlled_wires – Control wires.
controlled_values – Control values (false or true).
tgt_wires – Target wires to apply gate to.
inverse – Indicates whether to use adjoint of gate.
-
inline auto applyGenerator(const std::string &opName, const std::vector<std::size_t> &wires, bool adjoint = false) -> PrecisionT¶
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.
adjoint – Indicates whether to use adjoint of gate.
-
inline auto applyControlledGenerator(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 adjoint = false) -> PrecisionT¶
Apply a single controlled generator to the state vector using the given kernel.
- Parameters
opName – Name of gate to apply.
controlled_wires – Control wires.
controlled_values – Control values (true or false).
wires – Wires to apply gate to.
adjoint – Indicates whether to use adjoint of gate. (Default to false)
-
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 adjoint = false) -> PrecisionT¶
Apply a single generator to the state vector using the given kernel.
- Parameters
opName – Name of gate to apply.
controlled_wires – Control wires.
controlled_values – Control values (true or false).
wires – Wires to apply gate to.
adjoint – Indicates whether to use adjoint of gate. (Default to false)
-
inline void applyMatrix(const std::complex<PrecisionT> *gate_matrix, const std::vector<std::size_t> &wires, bool adjoint = 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.
adjoint – Indicate whether inverse should be taken.
-
inline void applyMatrix(const std::vector<std::complex<PrecisionT>> &gate_matrix, const std::vector<std::size_t> &wires, bool adjoint = false)¶
Apply a given matrix directly to the statevector using a std vector.
- Parameters
matrix – Pointer to the array data (in row-major format).
wires – Wires to apply gate to.
adjoint – Indicate whether inverse should be taken.
-
inline void collapse(std::size_t wire, bool branch)¶
Collapse the state vector after having measured one of the qubit.
Note: The branch parameter imposes the measurement result on the given wire.
- Parameters
wire – Wire to measure.
branch – Branch 0 or 1.
-
inline void applyIdentity(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyPauliX(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyPauliY(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyPauliZ(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyHadamard(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyS(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyT(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyRot(const std::vector<std::size_t> &wires, bool adjoint, Precision param0, Precision param1, Precision param2)¶
-
inline void applyRot(const std::vector<std::size_t> &wires, bool adjoint, const std::vector<Precision> ¶ms)¶
-
inline void applyCNOT(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyCY(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyCZ(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applySWAP(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyCRot(const std::vector<std::size_t> &wires, bool adjoint, const std::vector<Precision> ¶ms)¶
-
inline void applyCRot(const std::vector<std::size_t> &wires, bool adjoint, Precision param0, Precision param1, Precision param2)¶
-
inline void applyControlledPhaseShift(const std::vector<std::size_t> &wires, bool adjoint, Precision param)¶
-
inline void applySingleExcitation(const std::vector<std::size_t> &wires, bool adjoint, Precision param)¶
-
inline void applySingleExcitationMinus(const std::vector<std::size_t> &wires, bool adjoint, Precision param)¶
-
inline void applySingleExcitationPlus(const std::vector<std::size_t> &wires, bool adjoint, Precision param)¶
-
inline void applyToffoli(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyCSWAP(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline void applyDoubleExcitation(const std::vector<std::size_t> &wires, bool adjoint, Precision param)¶
-
inline void applyDoubleExcitationMinus(const std::vector<std::size_t> &wires, bool adjoint, Precision param)¶
-
inline void applyDoubleExcitationPlus(const std::vector<std::size_t> &wires, bool adjoint, Precision param)¶
-
inline PrecisionT applyGeneratorGlobalPhase([[maybe_unused]] const std::vector<std::size_t> &wires, [[maybe_unused]] bool adj = false)¶
Gradient generator function associated with the GlobalPhase gate.
- Parameters
sv – Statevector
wires – Wires to apply operation.
adj – Takes adjoint of operation if true. Defaults to false.
-
inline PrecisionT applyGeneratorRX(const std::vector<std::size_t> &wires, bool adj = false)¶
Gradient generator function associated with the RX gate.
- Parameters
wires – Wires to apply operation.
adj – Takes adjoint of operation if true. Defaults to false.
-
inline PrecisionT applyGeneratorRY(const std::vector<std::size_t> &wires, bool adj = false)¶
Gradient generator function associated with the RY gate.
- Parameters
wires – Wires to apply operation.
adj – Takes adjoint of operation if true. Defaults to false.
-
inline PrecisionT applyGeneratorRZ(const std::vector<std::size_t> &wires, bool adj = false)¶
Gradient generator function associated with the RZ gate.
- Parameters
wires – Wires to apply operation.
adj – Takes adjoint of operation if true. Defaults to false.
-
inline PrecisionT applyGeneratorIsingXX(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyGeneratorIsingYY(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyGeneratorIsingZZ(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyGeneratorIsingXY(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyGeneratorPhaseShift(const std::vector<std::size_t> &wires, bool adj = false)¶
Gradient generator function associated with the PhaseShift gate.
- Parameters
wires – Wires to apply operation.
adj – Takes adjoint of operation if true. Defaults to false.
-
inline PrecisionT applyGeneratorCRX(const std::vector<std::size_t> &wires, bool adj = false)¶
Gradient generator function associated with the controlled RX gate.
- Parameters
wires – Wires to apply operation.
adj – Takes adjoint of operation if true. Defaults to false.
-
inline PrecisionT applyGeneratorCRY(const std::vector<std::size_t> &wires, bool adj = false)¶
Gradient generator function associated with the controlled RY gate.
- Parameters
wires – Wires to apply operation.
adj – Takes adjoint of operation if true. Defaults to false.
-
inline PrecisionT applyGeneratorCRZ(const std::vector<std::size_t> &wires, bool adj = false)¶
Gradient generator function associated with the controlled RZ gate.
- Parameters
wires – Wires to apply operation.
adj – Takes adjoint of operation if true. Defaults to false.
-
inline PrecisionT applyGeneratorControlledPhaseShift(const std::vector<std::size_t> &wires, bool adj = false)¶
Gradient generator function associated with the controlled PhaseShift gate.
- Parameters
wires – Wires to apply operation.
adj – Takes adjoint of operation if true. Defaults to false.
-
inline PrecisionT applyGeneratorSingleExcitation(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyGeneratorSingleExcitationMinus(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyGeneratorSingleExcitationPlus(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyGeneratorDoubleExcitation(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyGeneratorDoubleExcitationMinus(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyGeneratorDoubleExcitationPlus(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyGeneratorMultiRZ(const std::vector<std::size_t> &wires, bool adjoint)¶
-
inline PrecisionT applyControlledGeneratorRX(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
Gradient generator function associated with the controlled-RX gate.
- Parameters
controlled_wires – Control wires.
controlled_values – Control values (false or true).
wires – Target wires to apply operation.
adj – Takes adjoint of operation if true. Defaults to false.
-
inline PrecisionT applyControlledGeneratorRY(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorRZ(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorIsingXX(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorIsingXY(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorIsingYY(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorIsingZZ(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorSingleExcitation(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorSingleExcitationMinus(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorSingleExcitationPlus(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorDoubleExcitation(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorDoubleExcitationMinus(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorDoubleExcitationPlus(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorPhaseShift(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorGlobalPhase(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline PrecisionT applyControlledGeneratorMultiRZ(const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, bool adj = false)¶
-
inline auto getCublasCaller() const -> const CublasCaller&¶
Access the CublasCaller the object is using.
- Returns
a reference to the object’s CublasCaller object.
-
inline auto getCusparseHandle() const -> cusparseHandle_t¶
Get the cuSPARSE handle that the object is using.
- Returns
cusparseHandle_t returns the cuSPARSE handle.
-
inline auto getCusvHandle() const -> custatevecHandle_t¶
Get the cuStateVec handle that the object is using.
- Returns
custatevecHandle_t returns the cuStateVec handle.
-
inline auto getDataVector() -> std::vector<std::complex<PrecisionT>>¶
Get a host data copy.
- Returns
std::vector<std::complex<PrecisionT>>