Template Class TNCuda

Inheritance Relationships

Base Type

Class Documentation

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

CRTP-enabled base class for cuTensorNet backends. This class stores both tensor data and gate data supported by both ExactTN and MPS.

Template Parameters
  • PrecisionT – Floating point precision.

  • Derived – Derived class to instantiate using CRTP.

Public Functions

TNCuda() = delete
inline explicit TNCuda(std::size_t numQubits, std::size_t maxBondDim = 1)
inline explicit TNCuda(const std::size_t numQubits, DevTag<int> dev_tag, const std::size_t maxBondDim = 1)
~TNCuda() = default
inline auto getMethod() const -> std::string

Get the method of a derived class object.

Returns

std::string

inline auto getCublasCaller() const -> const CublasCaller&

Access the CublasCaller the object is using.

Returns

a reference to the object’s CublasCaller object.

inline void getData(ComplexT *res, const std::size_t res_length)

Get the full state vector representation of a quantum state. Note that users/developers should be responsible to ensure that there is sufficient memory on the host to store the full state vector.

Parameters
  • res – Pointer to the host memory to store the full state vector

  • res_length – Length of the result vector

inline auto getDataVector() -> std::vector<ComplexT>

Get the full state vector representation of a quantum state.

Returns

std::vector<ComplexT> Full state vector representation of the quantum state on host

inline void reset()

Set current quantum state as zero state.

inline void setBasisState(const std::vector<std::size_t> &basisState)

Update quantum state with a basis state. NOTE: This API assumes the bond vector is a standard basis vector ([1,0,0,……]) and current implementation only works for qubit systems.

Parameters

basisState – Vector representation of a basis state.

inline void updateSiteData(const std::size_t site_idx, const ComplexT *host_data, std::size_t host_data_size)

Update the ith tensor data.

Parameters
  • site_idx – Index of the site.

  • host_data – Pointer to the data on host.

  • host_data_size – Length of the data.

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.

inline auto getSitesExtents() const -> const std::vector<std::vector<std::size_t>>&

Get a const vector reference of sitesExtents_.

Returns

const std::vector<std::vector<std::size_t>>

Protected Functions

inline auto getTensorsOutDataPtr() -> std::vector<CFP_t*>

Get a vector of pointers to tensor data of each site.

Returns

std::vector<CFP_t *>

inline auto getSitesExtentsPtr() -> std::vector<int64_t const*>

Get a vector of pointers to extents of each site.

Returns

std::vector<int64_t const *> Note int64_t const* is required by cutensornet backend.

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

Save quantumState information to data provided by a user.

Parameters
  • extentsPtr – Pointer to extents provided by a user

  • tensorPtr – Pointer to tensors provided by a user

Protected Attributes

const std::size_t maxBondDim_
const std::vector<std::size_t> bondDims_