Hello, I am using the new simulator from NVIDIA. cuTensorNet is a new technology and I think it will be hard to find good documents on it. Today I will try to show how to get the state vector from cuTensorNet using Google Cirq.
reference:
Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES
SPDX-License-Identifier: BSD-3-Clause
Load the tool first. Install any missing pieces.
import cirq
from cirq.testing import random_circuit
import cupy as cp
import numpy as np
from cuquantum import contract, CircuitToEinsum
This time I'm going to run a 10-qubit random circuit, and I'm going to build it according to Google Cirq.
num_qubits = 10
n_moments = 6
op_density = 0.9
gate_domain = {cirq.H: 1,
cirq.S: 1,
cirq.T: 1,
cirq.CNOT: 2,
cirq.CZ: 2}
circuit = random_circuit(num_qubits, n_moments, op_density=op_density, gate_domain=gate_domain, random_state=6)
print(circuit)
This one is converted to a tensor network, a function was provided.
myconverter = CircuitToEinsum(circuit, dtype='complex128', backend=cp)
expression, operands = myconverter.state_vector()
sv = contract(expression, *operands)
sv.reshape(1, 2**num_qubits)
It takes the contraction of a circuit described in Einsum form and puts it in final state vector notation.
The state vector form is a quantum state without a measurement on tensor network. The final step is to convert the tensor to a vector of state vectors and you are done.
array([[0.35355339+0.j , 0. +0.j , 0.25 +0.25j, ...,
0. +0.j , 0. +0.j , 0. +0.j ]])
The state vector was obtained fairly quickly. I think this is useful for small models, since the state vector can be used to check the calculation. That's all.