Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cuStateVec issue on GPU in Google Colab #542

Open
95-martin-orion opened this issue Jul 11, 2022 · 3 comments
Open

cuStateVec issue on GPU in Google Colab #542

95-martin-orion opened this issue Jul 11, 2022 · 3 comments

Comments

@95-martin-orion
Copy link
Collaborator

Branched from #495. @Gopal-Dahale wrote:

New problem that I faced when using qsimcirq as backend in tfq.ControlledPQC.

circuit  # some cirq circuit
observable # some observable
gpu_options = qsimcirq.QSimOptions(use_gpu=True, gpu_mode=1)
qsim_simulator = qsimcirq.QSimSimulator(qsim_options=gpu_options)

computation_layer = tfq.layers.ControlledPQC(circuit, observable,backend = qsim_simulator)
ValueError: cuStateVec GPU execution requested, but not supported. 
If your device has GPU support and the NVIDIA cuStateVec library is installed, you may need to compile qsim locally.

I have put the cuquantum files in /usr/local/cuquantum and in .bashrc have added these lines

export CUQUANTUM_ROOT=/usr/local/cuquantum
export LD_LIBRARY_PATH=${CUQUANTUM_ROOT}/lib:${LD_LIBRARY_PATH}
export CUQUANTUM_DIR=/usr/local/cuquantum

followed by source ~/.bashrc. Ran the test program given on docs site (statevec_example) which gave the result example PASSED.

Any solution for this would be helpful.

@95-martin-orion
Copy link
Collaborator Author

@Gopal-Dahale, can you confirm that you set up both cuQuantum and NVCC on your device before building qsim? The error you are seeing occurs when the qsim_custatevec is not initialized, which occurs if either cuQuantum or NVCC is not available when qsim is initially built.

Relevant code snippets:

int detect_custatevec() {
#if defined(__NVCC__) && defined(__CUSTATEVEC__)
GPUCapabilities gpu = CUSTATEVEC;

def _load_qsim_custatevec():
instr = qsim_decide.detect_custatevec()

@Gopal-Dahale
Copy link

Gopal-Dahale commented Aug 11, 2022

@95-martin-orion This issue is resolved for me. Here are the steps that helped me and can be used on google colab.

  1. Download the tarball of cuquantum and extract it to /usr/local/cuquantum.
  2. Set the following environment variables
import os
os.environ['CUQUANTUM_ROOT']='/usr/local/cuquantum'
os.environ['CUQUANTUM_DIR']='/usr/local/cuquantum'
os.environ['LD_LIBRARY_PATH']=f"/usr/local/cuquantum/lib:{os.environ['LD_LIBRARY_PATH']}"
os.environ['PATH']=f"/usr/local/cuquantum/lib:{os.environ['PATH']}"
  1. Verify cuquantum installation by executing the code example.
  2. Install qsimcirq.
  3. Verify qsimcirq installation and its integration with cuquantum by executing the example with these options.

I think we can close this issue.

@QuantumJaeYoo
Copy link

FYI, from 0.16.0, qsim uses CUQUANTUM_ROOT only, no more CUQUANTUM_DIR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants