Does NVIDIA cuQuantum work on the PC? I was asked this question, so I put it in and ran it. My PC is a gaming laptop with GTX1650. The procedure is simple.
pip install cuquantum-python
That's it. If cupy is requested, you will need to include it as well.
import numpy as np
import cupy as cp
import cuquantum
from cuquantum import custatevec as cusv
nIndexBits = 3
nSvSize = (1 << nIndexBits)
nTargets = 1
nControls = 2
adjoint = 0
targets = np.asarray([2], dtype=np.int32)
controls = np.asarray([0, 1], dtype=np.int32)
h_sv = np.asarray([0.0+0.0j, 0.0+0.0j, 0.0+0.0j, 0.0+0.0j,
0.0+0.0j, 0.0+0.0j, 0.0+0.0j, 1.0+0.0j], dtype=np.complex64)
# the gate matrix can live on either host (np) or device (cp)
matrix = cp.asarray([0.0+0.0j, 1.0+0.0j, 1.0+0.0j, 0.0+0.0j], dtype=np.complex64)
if isinstance(matrix, cp.ndarray):
matrix_ptr = matrix.data.ptr
elif isinstance(matrix, np.ndarray):
matrix_ptr = matrix.ctypes.data
else:
raise ValueError
d_sv = cp.asarray(h_sv)
####################################################################################
# cuStateVec handle initialization
handle = cusv.create()
workspaceSize = cusv.apply_matrix_get_workspace_size(
handle, cuquantum.cudaDataType.CUDA_C_32F, nIndexBits, matrix_ptr, cuquantum.cudaDataType.CUDA_C_32F,
cusv.MatrixLayout.ROW, adjoint, nTargets, nControls, cuquantum.ComputeType.COMPUTE_32F)
# check the size of external workspace
if workspaceSize > 0:
workspace = cp.cuda.memory.alloc(workspaceSize)
workspace_ptr = workspace.ptr
else:
workspace_ptr = 0
# apply gate
cusv.apply_matrix(
handle, d_sv.data.ptr, cuquantum.cudaDataType.CUDA_C_32F, nIndexBits, matrix_ptr, cuquantum.cudaDataType.CUDA_C_32F,
cusv.MatrixLayout.ROW, adjoint, targets.ctypes.data, nTargets, controls.ctypes.data, 0, nControls,
cuquantum.ComputeType.COMPUTE_32F, workspace_ptr, workspaceSize)
# destroy handle
cusv.destroy(handle)
print(d_sv)
[0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
So, I multiplied CCX by |111>, and it came out to be successful. I have a lot of GPUs, so I'll try to use a big one in the future.