The following code example illustrates how to integrate cuTensorNet functionalities to perform tensor QR operation. The full code can be found in the `NVIDIA/cuQuantum `_ repository (`here `_). ----------------------- Define QR decomposition ----------------------- We first define the QR decomposition to perform with the data type, modes partition, and the extents. .. literalinclude:: ../../../../tensor_network/samples/approxTN/tensor_qr_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: #2 :end-before: Sphinx: #3 .. note:: `cutensornetTensorQR` operates in reduced mode, expecting the shared extent for the output to be the minimum of the combined row extent and the combined column extent. ----------------------------------- Allocate memory and initialize data ----------------------------------- Next, we allocate memory for the input and output tensor operands. The input operand is initialized to random values. .. literalinclude:: ../../../../tensor_network/samples/approxTN/tensor_qr_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: #3 :end-before: Sphinx: #4 ---------------------------------------------------- Initialize cuTensorNet and create tensor descriptors ---------------------------------------------------- Then we initialize the library handle of cuTensorNet and create `cutensorTensorDescriptor_t` for input and output tensors. .. literalinclude:: ../../../../tensor_network/samples/approxTN/tensor_qr_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: #4 :end-before: Sphinx: #5 ------------------------------------- Query and allocate required workspace ------------------------------------- Once all tensor descriptors are created, we can query the required workspace size with `cutensornetWorkspaceComputeQRSizes`. .. literalinclude:: ../../../../tensor_network/samples/approxTN/tensor_qr_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: #5 :end-before: Sphinx: #6 --------- Execution --------- At this stage, we can perform the QR decomposition by calling `cutensornetTensorQR`. .. literalinclude:: ../../../../tensor_network/samples/approxTN/tensor_qr_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: #6 :end-before: Sphinx: #7 -------------- Free resources -------------- After the computation, we need to free up all resources. .. literalinclude:: ../../../../tensor_network/samples/approxTN/tensor_qr_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: #7