CUDA-Q¶
Description¶
CUDA-Q is an open-source quantum development platform that orchestrates the hardware and software needed to run useful, large-scale quantum computing applications. The platform’s hybrid programming model allows computation on GPU, CPU, and QPU resources in tandem from within a single quantum program. CUDA-Q is “qubit-agnostic”—seamlessly integrating with all QPUs and qubit modalities and offering GPU-accelerated simulations when adequate quantum hardware isn’t available.
Available Versions¶
The following versions of CUDA-Q are currently available:
- Runtime dependencies:
- singularity/ce-3.11.0
CUDA-Q is available as a container; use singularity to build or run the applications. First load the singularity module with the following command:
module load singularity/ce-3.11.0
The container is located at /storage-apps/software/containers/cuda-q/cuda-quantum_cu12-0.12.0.sif.
Best practice for using CUDA-Q¶
We recommend running CUDA-Q applications on GPUs. CUDA-Q quantum algorithm simulations can achieve a significant speedup on the GPU over the CPU.
Examples¶
Here are the example codes written in Python and C++.
import sys
import cudaq
print(f"Running on target {cudaq.get_target().name}")
qubit_count = int(sys.argv[1]) if 1 < len(sys.argv) else 2
@cudaq.kernel
def kernel():
qubits = cudaq.qvector(qubit_count)
h(qubits[0])
for i in range(1, qubit_count):
x.ctrl(qubits[0], qubits[i])
mz(qubits)
result = cudaq.sample(kernel)
print(result) # Example: { 11:500 00:500 }
To run the example, execute the following command after adding singularity to your environment:
singularity exec --nv /storage-apps/software/containers/cuda-q/cuda-quantum_cu12-0.12.0.sif python3 program.py
#include <cudaq.h>
__qpu__ void kernel(int qubit_count) {
cudaq::qvector qubits(qubit_count);
h(qubits[0]);
for (auto i = 1; i < qubit_count; ++i) {
cx(qubits[0], qubits[i]);
}
mz(qubits);
}
int main(int argc, char *argv[]) {
auto qubit_count = 1 < argc ? atoi(argv[1]) : 2;
auto result = cudaq::sample(kernel, qubit_count);
result.dump(); // Example: { 11:500 00:500 }
}
singularity exec --nv /storage-apps/software/containers/cuda-q/cuda-quantum_cu12-0.12.0.sif nvq++ program.cpp -o program.x
To run the example, execute the following command:
singularity exec --nv /storage-apps/software/containers/cuda-q/cuda-quantum_cu12-0.12.0.sif ./program.x
You can find more examples in /storage-apps/software/cuda-q/examples/. It also contains Jupyter notebooks which can be run using the Jupyter Notebook - singularity app via the Open OnDemand platform. Specify the container path mentioned above in the form.
User guide¶
More information on CUDA-Q can be found here. The documentation and user guide are available here.