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.
Versions¶
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 singularity module by following command:
bash
module load singularity/ce-3.11.0
The container is located in /storage-apps/software/containers/cuda-q/cuda-quantum_cu12-0.12.0.sif.
Best practice for using CUDA-Q¶
We recommend using CUDA-Q applications on GPUs. CUDA-Q quantum algorithm simulations can achieve a great speedup on GPU over 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 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 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 Open Ondemand platform. Specify the above mentioned cuda-quantum container path in the form.
User guide¶
More information on CUDA-Q can be found here. Documentation and user guide can be found here.