Computing Matrix Product State (MPS) Amplitudes#

The following code example illustrates how to define a tensor network state, factorize it as a Matrix Product State (MPS), and then compute a slice of amplitudes of the factorized MPS state. The full code can be found in the NVIDIA/cuQuantum repository (here).

Headers and error handling#

Define the tensor network state and the desired slice of state amplitudes#

Let’s define a tensor network state corresponding to a 6-qubit quantum circuit and request a slice of state amplitudes where qubits 0 and 1 are fixed at value 1.

Initialize the cuTensorNet library handle#

Define quantum gates on GPU#

Allocate MPS tensors#

Here we set the shapes of MPS tensors and allocate GPU memory for their storage.

Allocate the amplitudes slice tensor on GPU#

Here we allocate GPU memory for the requested amplitudes slice tensor.

Allocate the scratch buffer on GPU#

Create a pure tensor network state#

Now let’s create a pure tensor network state for a 6-qubit quantum circuit.

Apply quantum gates#

Let’s construct the GHZ quantum circuit by applying the corresponding quantum gates.

Request MPS factorization for the final quantum circuit state#

Here we express our intent to factorize the final quantum circuit state using MPS factorization. The provided shapes of the MPS tensors refer to their maximal size limit during the MPS renormalization procedure. The actually computed shapes of the final MPS tensors may be smaller. No computation is done here yet.

Configure MPS factorization procedure#

After expressing our intent to perform MPS factorization of the final quantum circuit state, we can also configure the MPS factorization procedure by resetting different options, for example, the SVD algorithm. Starting with cuTensorNet v2.7.0, the MPS gauge option can now be enabled. By setting it to CUTENSORNET_STATE_MPS_GAUGE_SIMPLE, the simple update algorithm is utilized to enhance the accuracy of the MPS factorization.

Prepare the computation of MPS factorization#

Let’s create a workspace descriptor and prepare the computation of MPS factorization.

Compute MPS factorization#

Once the MPS factorization procedure has been configured and prepared, let’s compute the MPS factorization of the final quantum circuit state.

Create the state amplitudes accessor#

Once the factorized MPS representation of the final quantum circuit state has been computed, let’s create the amplitudes accessor object that will compute the requested slice of state amplitudes.

Configure the state amplitudes accessor#

Now we can configure the state amplitudes accessor object by setting the number of hyper-samples to be used by the tensor network contraction path finder.

Prepare the computation of the amplitudes slice tensor#

Let’s prepare the computation of the amplitudes slice tensor.

Set up the workspace#

Now we can set up the required workspace buffer.

Compute the specified slice of state amplitudes#

Once everything has been set up, we compute the requested slice of state amplitudes, copy it back to Host memory, and print it.

Free resources#