Skip to content
Snippets Groups Projects
nvidia-cuda-q.md 2.09 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jan Siwiec's avatar
    Jan Siwiec committed
    # CUDA Quantum for Python
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    
    ## What Is CUDA Quantum?
    
    CUDA Quantum streamlines hybrid application development and promotes productivity and scalability in quantum computing. It offers a unified programming model designed for a hybrid setting—that is, CPUs, GPUs, and QPUs working together.
    
    For more information, see the [official documentation][1].
    
    ## How to Install Version Without GPU Acceleration
    
    Use (preferably in conda environment)
    
    ```bash
    pip install cuda-quantum
    ```
    
    ## How to Install Version With GPU Acceleration Using Conda
    
    Run:
    
    ```bash
    conda create -y -n cuda-quantum python=3.10 pip
    conda install -y -n cuda-quantum -c "nvidia/label/cuda-11.8.0" cuda
    conda install -y -n cuda-quantum -c conda-forge mpi4py openmpi cxx-compiler cuquantum
    conda env config vars set -n cuda-quantum
    LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$CONDA_PREFIX/envs/cuda-quantum/lib"
    conda env config vars set -n cuda-quantum
    MPI_PATH=$CONDA_PREFIX/envs/cuda-quantum
    conda run -n cuda-quantum pip install cuda-quantum
    conda activate cuda-quantum
    source $CONDA_PREFIX/lib/python3.10/site-packages/distributed_interfaces/activate_custom_mpi.sh
    ```
    
    Then configure the MPI:
    
    ``` bash
    export OMPI_MCA_opal_cuda_support=true OMPI_MCA_btl='^openib'
    ```
    
    ## How to Test Your Installation?
    
    You can test your installation by running the following script:
    
    ```bash
    import cudaq
    
    kernel = cudaq.make_kernel()
    qubit = kernel.qalloc()
    kernel.x(qubit)
    kernel.mz(qubit)
    
    result = cudaq.sample(kernel)
    ```
    
    ## Further Questions Considering the Installation?
    
    See the Cuda Quantum PyPI website at [https://pypi.org/project/cuda-quantum/][2].
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ## Example QNN
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    
    In the *qnn_example.py* you find a script that loads FashionMNIST dataset, chooses two data type (shirts and pants), then we create a Neural Network with quantum layer.This network is then trained on our data and later tested on the test dataset. You are free to try it on your own. Download the [QNN example][a] and rename it to `qnn_example.py`.
    
    ![](../img/cudaq.png)
    
    [1]: https://nvidia.github.io/cuda-quantum/latest/index.html
    [2]: https://pypi.org/project/cuda-quantum/
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    [a]: ../../../src/qnn_example