Template Class TNCudaBase

Inheritance Relationships

Base Type

Class Documentation

template<class PrecisionT, class Derived>
class TNCudaBase : public Pennylane::LightningTensor::TNCuda::TensornetBase<PrecisionT, Derived>

CRTP-enabled base class for cuTensorNet backends.

Template Parameters
  • PrecisionT – Floating point precision.

  • Derived – Derived class to instantiate using CRTP.

Public Functions

TNCudaBase() = delete
inline explicit TNCudaBase(const std::size_t numQubits, int device_id = 0, cudaStream_t stream_id = 0)
inline explicit TNCudaBase(const std::size_t numQubits, DevTag<int> dev_tag)
inline ~TNCudaBase()
inline auto getCudaDataType() const -> cudaDataType_t

Get the CUDA data type.

Returns

cudaDataType_t

inline auto getTNCudaHandle() const -> cutensornetHandle_t

Get the cutensornet handle that the object is using.

Returns

cutensornetHandle_t

inline auto getCublasCaller() const -> const CublasCaller&

Access the CublasCaller the object is using.

Returns

a reference to the object’s CublasCaller object.

inline auto getQuantumState() const -> cutensornetState_t

Get the quantum state pointer.

Returns

cutensornetState_t

inline auto getDevTag() const -> const DevTag<int>&

Get device and Cuda stream information (device ID and the associated Cuda stream ID).

Returns

DevTag

inline void applyOperations(const std::vector<std::string> &ops, const std::vector<std::vector<std::size_t>> &ops_wires, const std::vector<bool> &ops_adjoint, const std::vector<std::vector<PrecisionT>> &ops_params)

Append multiple gates to the compute graph. NOTE: This function does not update the quantum state but only appends gate tensor operator to the graph.

Parameters
  • ops – Vector of gate names to be applied in order.

  • ops_wires – Vector of wires on which to apply index-matched gate name.

  • ops_adjoint – Indicates whether gate at matched index is to be inverted.

  • ops_params – Vector of gate parameters.

inline void applyOperations(const std::vector<std::string> &ops, const std::vector<std::vector<std::size_t>> &ops_wires, const std::vector<bool> &ops_adjoint)

Append multiple gate tensors to the compute graph. NOTE: This function does not update the quantum state but only appends gate tensor operator to the graph.

Parameters
  • ops – Vector of gate names to be applied in order.

  • ops_wires – Vector of wires on which to apply index-matched gate name.

  • ops_adjoint – Indicates whether gate at matched index is to be inverted.

inline void applyControlledOperation(const std::string &baseOpName, const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &targetWires, bool adjoint = false, const std::vector<PrecisionT> &params = {0.0}, const std::vector<ComplexT> &gate_matrix = {})

Append a single controlled gate tensor to the compute graph.

NOTE: This function does not update the quantum state but only appends gate tensor operator to the graph. The controlled gate should be immutable as v24.08.

Parameters
  • baseOpName – Base gate’s name.

  • controlled_wires – Controlled wires for the gate.

  • controlled_values – Controlled values for the gate.

  • targetWires – Target wires for the gate.

  • adjoint – Indicates whether to use adjoint of gate.

  • params – Optional parameter list for parametric gates.

  • gate_matrix – Optional gate matrix for custom gates.

inline void applyOperation(const std::string &opName, const std::vector<std::size_t> &wires, bool adjoint = false, const std::vector<PrecisionT> &params = {0.0}, const std::vector<ComplexT> &gate_matrix = {})

Append a single gate tensor to the compute graph. NOTE: This function does not update the quantum state but only appends gate tensor operator to the graph.

Parameters
  • opName – Gate’s name.

  • wires – Wires to apply gate to.

  • adjoint – Indicates whether to use adjoint of gate.

  • params – Optional parameter list for parametric gates.

  • gate_matrix – Optional gate matrix for custom gates.

inline void get_state_tensor(ComplexT *host_data, const int32_t numHyperSamples = 1)

Get the state vector representation of a tensor network.

Parameters
  • host_data – Pointer to the host memory for state tensor data.

  • numHyperSamples – Number of hyper samples to use in the calculation and is set to 1 by default.

inline void get_state_tensor(CFP_t *tensor_data, const std::size_t tensor_data_size, const std::vector<int32_t> &projected_modes, const std::vector<int64_t> &projected_mode_values, const int32_t numHyperSamples = 1) const

Get a slice of the full state tensor.

Parameters
  • tensor_data – Pointer to the device memory for state tensor data.

  • tensor_data_size – Size of the state tensor data.

  • projected_modes – Projected modes to get the state tensor for.

  • projected_mode_values – Values of the projected modes.

  • numHyperSamples – Number of hyper samples to use in the calculation and is set to 1 by default.

Protected Functions

inline void dummy_tensor_update()

Dummy tensor operator update to allow multiple calls of appendMPSFinalize. This is a workaround to avoid the issue of the cutensornet library not allowing multiple calls of appendMPSFinalize.

This function either appends a new Identity gate to the graph when the gate cache is empty or update the existing gate operator by itself.

inline void computeState(int64_t **extentsPtr, void **tensorPtr)

Save quantumState information to data provided by a user.

Parameters

tensorPtr – Pointer to tensors provided by a user