--------------------------------- Projection MPS Circuit DMRG --------------------------------- The following code example illustrates how to use the state projection MPS API to perform circuit simulation using DMRG optimization, following the method described by :ref:`[Ayral et al., 2023]`. The full code can be found in the `NVIDIA/cuQuantum `_ repository (`here `_). --------------------------------------------- Headers, error handling, and helper functions --------------------------------------------- .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #1 :end-before: Sphinx: Projection MPS Circuit DMRG #2 ------------------------------------------------------------------------------------ Define the tensor network state and quantum circuit configuration ------------------------------------------------------------------------------------ Let's define a tensor network state corresponding to a 16-qubit QFT quantum circuit. .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #2 :end-before: Sphinx: Projection MPS Circuit DMRG #3 ----------------------------------------- Initialize the cuTensorNet library handle ----------------------------------------- .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #3 :end-before: Sphinx: Projection MPS Circuit DMRG #4 --------------------------- Define quantum gates on GPU --------------------------- .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #4 :end-before: Sphinx: Projection MPS Circuit DMRG #5 -------------------------------------------- Create initial quantum state and apply gates -------------------------------------------- Here we query the available GPU memory and allocate a scratch buffer for computations, followed by creating the pure quantum state and then applying the quantum gates. .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #5 :end-before: Sphinx: Projection MPS Circuit DMRG #6 ------------------------------------------------------------- Set up and specify the MPS representation of the output state ------------------------------------------------------------- Now let's set up the MPS representation of the output state for our 16-qubit quantum circuit. .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #6 :end-before: Sphinx: Projection MPS Circuit DMRG #7 --------------------------------------- Initialize the MPS in the vacuum state --------------------------------------- For simplicity and reproducibility, we initialize the MPS as the vacuum state. This includes logic for the bond dimension, as we require the MPS to not have overcomplete bond dimensions. .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #7 :end-before: Sphinx: Projection MPS Circuit DMRG #8 ------------------------------------------------------------- Define MPS representation and allocate projection MPS tensors ------------------------------------------------------------- Here we set up the MPS representation to be optimized by the projection MPS API and allocate GPU memory for the projection MPS tensors and environment tensors to be used over the course of the DMRG optimization. .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #8 :end-before: Sphinx: Projection MPS Circuit DMRG #9 ------------------------------------- Create state projection MPS ------------------------------------- Now we create the `cutensornetStateProjectionMPS_t` object that will be used for DMRG optimization. Many MPS optimization algorithms, including circuit DMRG, make use of the gauge degree of freedom of the MPS and enforce orthogonality conditions on the MPS tensors, such that the optimized tensors constitute coefficients of the quantum state in a orthonormal basis defined by the other MPS tensors. By default, the `cutensornetStateProjectionMPSExtract` API enforces these orthogonality conditions by performing orthogonalization of the MPS tensors towards the environment for which the extraction happens. The following figure illustrates the main idea behind the state projection MPS API for the four-qubit case. .. figure:: ../../figures/circuit_dmrg_network.png :width: 900px :align: center The environment network is the initial MPS (left) contracted with the circuit gates (middle) and the target MPS (right), where the tensor to be variationally optimized is removed from the network. Contracting this network results in a single-site tensor, which we will call the environment tensor. Note that we use the following convention for the indexing of the environment tensors: The single-site environment for tensor :math:`i` is specified by the environment specification :math:`(i-1, i+1)`. .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #9 :end-before: Sphinx: Projection MPS Circuit DMRG #10 ------------------------- Perform DMRG optimization ------------------------- Once the state projection MPS has been prepared, we perform DMRG optimization through forward and backward sweeps to optimize the MPS representation. For each tensor, we extract the site tensor, compute the corresponding environment tensor, and then insert the resulting tensor back into the MPS. .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #10 :end-before: Sphinx: Projection MPS Circuit DMRG #11 -------------- Free resources -------------- .. literalinclude:: ../../../../tensor_network/samples/high_level/proj_mps_circuit_dmrg_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: Projection MPS Circuit DMRG #11 References ========== .. container:: references csl-bib-body hanging-indent :name: refs .. container:: csl-entry :name: ref-PRXQuantum.4.020304 Ayral, Thomas, Thibaud Louvet, Yiqing Zhou, Cyprien Lambert, E. Miles Stoudenmire, and Xavier Waintal. 2023. “Density-Matrix Renormalization Group Algorithm for Simulating Quantum Circuits with a Finite Fidelity.” *PRX Quantum* 4 (April): 020304. https://doi.org/10.1103/PRXQuantum.4.020304.