Installation Procedure for GPU Enabled Mode

Quantum Rings SDK now supports Nvidia GPUs, either in the native mode or together with the toolkit for Qiskit.

The following steps outline the installation procedure.

Note

If you are a windows user, we recommend using a WSL based Linux instance on the system.

Also, you have to set the directory where the CUDA Runtime is installed. See the code examples at the end of this page for additional help.

STEP - 1

Obtain your license to the Quantum Rings SDK by selecting the Login menu.

Skip this step, if you are already registered.

Login to the Quantum Rings portal. Download your access keys by selecting the Manage Keys menu in the left-hand side bar.

STEP - 2

Warning

This step my be challenging and you may need professional help. Installing device drivers can make your installation unstable. Always proceed with a backup and read all documentation carefully. Ensure that you are installing the correct drivers for your hardware platform. Installing open source drivers may not be a good idea.

Update the NVIDIA drivers for your system. For some linux installations, you may be required to install the NVIDIA drivers directly from the linux distribution. Search for the documentation from your linux operating system provider and go by their recommendation.

Note

If you are using your university supercomputer or a cloud environment equipped with NVIDIA GPUs, your system adminstrator may have already installed the required components for you.

STEP - 3

Create a virtual environment for your Python version using the following example.

virtualenv --python = /usr/bin/python3.11 myenv
source myenv/bin/activate

In some installations, the virtual environment can be created as follows :

python3.11 -m venv myenv
source myenv/bin/activate

Noe that, installing a Python virtual environment may require additional steps.

You can optionally choose to install Jupyter notebook, at this time using the following command.

pip install notebook

STEP - 4

Install the CUDA Toolkit by following the instructions in the link : CUDA Toolkit

Follow the instructions shown on the screen after the CUDA toolkit is installed and setup the paths as recommended. If not set, the Quantum Rings SDK will have linkage problems.

Note

Linux Users:

After installing the CUDA toolkit, you may have to set the environment variable LD_LIBRARY_PATH to point to the folder where the CUDA toolkit library was installed. If this is not set, then there may be runtime linkage errors when you import QuantumRingsLib in your Python code.

Windows Users:

Ensure that the environment variable CUDA_PATH is set to the folder where the CUDA toolkit is installed. Also ensure that the environment variable PATH includes the path where CUDA Toolkit components are installed. Usually this is C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9\bin but check your installation and your CUDA Toolkit version.

If the environment variables are not set properly, there will be linkage problems and the SDK will not load. If you are a Windows user, see additional instructions at the end of this page to setup the DLL search path with Python.

If you are using your university supercomputer or a cloud environment with NVIDIA GPUs, then your system administrator may have already installed the necessary runtime components optimized for your hadware platform.You may just have to select the cuda runtime module. This is typically done using a module loader, as shown below. Browse the modules installed in your system and select the most recent cuda run time. Note that your system may use a different way of loading runtime components.

module load cuda-12.6.1-gcc-12.1.0

STEP - 5

Install the Quantum Rings SDK using the following command:

pip install quantumrings-nvidia-gpu

STEP - 6

Now, try the following program from your Jupyter notebook or directly from the terminal to ensure that everything is working fine.

# For Windows users. Linux users may skip this.
# Setup the CUDA Runtime path with Python
import os
cuda_path = os.getenv("CUDA_PATH", "")
if "" == cuda_path:
    # set a hard-coded path based on your CUDA installation
    cuda_path = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.9\\bin"
else:
    # create from the environment
    cuda_path += "\\bin"
os.add_dll_directory(cuda_path)
##
#

    import QuantumRingsLib
    from QuantumRingsLib import QuantumRegister, AncillaRegister, ClassicalRegister, QuantumCircuit
    from QuantumRingsLib import QuantumRingsProvider
    from QuantumRingsLib import job_monitor
    from QuantumRingsLib import JobStatus
    from QuantumRingsLib import OptimizeQuantumCircuit
    from matplotlib import pyplot as plt
    import numpy as np
    import math

    provider = QuantumRingsProvider(token = <YOUR_TOKEN_HERE>, name = <YOUR_ACCOUNT_NAME_HERE>)
    backend = provider.get_backend("amber_quantum_rings")
    numberofqubits = 50
    shots = 100

    q = QuantumRegister(numberofqubits, 'q')
    c = ClassicalRegister(numberofqubits, 'c')
    qc = QuantumCircuit(q, c)

    qc.h(0);
    for i in range(qc.num_qubits - 1) :
            qc.cnot(i, i + 1);

    qc.measure_all();

    job = backend.run(qc, shots = shots)
    job_monitor(job)

    result = job.result()
    counts = result.get_counts()

Using the GPU Mode

Certain programs with large number of qubits(> 22) with complex entanglements and a large number of gate operations can benefit from using a GPU.

To switch to the GPU mode, select the amber_quantum_rings backend as follows

backend = provider.get_backend("amber_quantum_rings")

To switch to the CPU mode, select the scarlet_quantum_rings backend as follows

backend = provider.get_backend("scarlet_quantum_rings")

Note

Programs with a few qubits and gate operations usually run faster on the CPU mode with the scarlet_quantum_rings backend.

You can also store backend name in the configuration file using the key backend and allow the method provider.get_backend select it automatically by not providing any arguments. For saving the backend name in the configuration file, please follow the instruction in the section Saving the Quantum Rings account locally. Once the backend name is saved in the configuration file, you can obtain the backend by providing no arguments to the provider.get_backend method as follows:

provider = QuantumRingsProvider()
backend = provider.get_backend()

Windows Users

Please note that the following dynamically linkable libraries are required in the search path for the SDK to load.

  • cublas64_X.dll

  • cublasLt64_X.dll

  • cudart64_X.dll

  • cusolver64_X.dll

  • cusparse64_X.dll

  • nvJitLink_X_Y.dll

In these library names, X and Y indicate your CUDA Runtime versions.

In some installations, Python does not load these libraries from the installed search paths. In such installations, before importing QuantumRingsLib, the directory where the CUDA Runtime components are installed is to be set with the os.add_dll_directory API. Otherwise import QuantumRingsLib will throw an exception ImportError: DLL load failed while importing QuantumRingsLib: The specified module could not be found. Add the path where the CUDA Runtime is installed as follows:

import os
os.add_dll_directory("C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.9\\bin")
import QuantumRingsLib

Edit the CUDA Runtime path to suit your installation.

Alternatively, if the environment variable CUDA_PATH is set, you can use the following code to set this automatically.

import os
cuda_path = os.getenv("CUDA_PATH", "")
if "" == cuda_path:
    #set a hard-coded path
    cuda_path = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.9\\bin"
else:
    #create from the environment
    cuda_path += "\\bin"

os.add_dll_directory(cuda_path)

import QuantumRingsLib