In this case, we are looking for the amplitude of a specific bit sequence, called a single amplitude. The square of the absolute value of the amplitude corresponds to the probability of occurrence of that bit sequence. Since it is already impossible with 150 qubits to represent the amplitude of all state vectors simultaneously, we seek a single amplitude.
参考:
Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES
SPDX-License-Identifier: BSD-3-Clause
import tools and make a random circuit
import cirq
from cirq.testing import random_circuit
import cupy as cp
import numpy as np
import time
from cuquantum import contract, CircuitToEinsum
num_qubits = 150
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)
Let's execte and just get the amplitude of the all zero bit string.
l = [0 for _ in range(num_qubits)]
bitstring = ''.join(map(str, l))
print(bitstring)
start1 = time.time()
myconverter = CircuitToEinsum(circuit, dtype='complex128', backend=cp)
expression, operands = myconverter.amplitude(bitstring)
print("preprocess:", time.time() - start1)
start2 = time.time()
amplitude = contract(expression, *operands)
print("process:", time.time() - start2)
print(amplitude)
print(np.abs(amplitude)**2)
The result is below. We used A100 GPU with 80G memory.
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
preprocess: 0.03520393371582031
process: 8.503039121627808
(-3.215549355384471e-13-1.3319241534803108e-13j)
1.2113779607537728e-25
Preprocessing takes 0.03sec and 150qubits random circuit finish in 8.5sec. The circuit was a very simple one so finished faster. that's all.