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

feature: Add CUDA-Q BYOC examples #645

Merged
merged 58 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c542dba
add byoc tutorial and examples
yitchen-tim Sep 12, 2024
d677440
fix: typo
yitchen-tim Sep 26, 2024
8b28c80
restructure example notebooks for CUDA-Q jobs
yitchen-tim Oct 9, 2024
8820cae
Merge branch 'public-main' into feature/cudaq-byoc
yitchen-tim Oct 9, 2024
38ed928
update cudaq job examples
yitchen-tim Oct 10, 2024
85942e7
Merge branch 'feature/cudaq-byoc' of https://github.com/amazon-braket…
yitchen-tim Oct 10, 2024
2ce5109
Update 0_hello_quantum.ipynb
yitchen-tim Oct 10, 2024
0ec6401
Update 0_hello_quantum.ipynb
yitchen-tim Oct 10, 2024
1c07093
Update 2_parallel_simulations.ipynb
yitchen-tim Oct 11, 2024
1c9a8d8
updates from feedbacks
yitchen-tim Oct 11, 2024
bd1ac2c
move detail of container build to the end
yitchen-tim Oct 11, 2024
19d41f9
change notebook names
yitchen-tim Oct 14, 2024
402aaa6
fix references between notebooks
yitchen-tim Oct 14, 2024
998565b
update notebooks and script
yitchen-tim Oct 22, 2024
3570ed3
CUDA-Q notebooks minor changes (#76)
mbeach-aws Oct 31, 2024
584280f
skip cuda-q jobs integ tests
yitchen-tim Oct 31, 2024
bd0f995
Merge branch 'public-main' into feature/cudaq-byoc
yitchen-tim Oct 31, 2024
484aaf8
fix lint
yitchen-tim Oct 31, 2024
fc537d7
add example links to readme
yitchen-tim Oct 31, 2024
90f4951
remove: lines for debugging
yitchen-tim Oct 31, 2024
ca6e816
add Braket device example
yitchen-tim Nov 7, 2024
9483e4e
change folder structure
yitchen-tim Nov 7, 2024
d9db7d6
update notebook links in readme
yitchen-tim Nov 7, 2024
1ba0309
fix notebook links
yitchen-tim Nov 7, 2024
a193325
add instruction about ECR write policy
yitchen-tim Nov 15, 2024
e2f9502
grammar
yitchen-tim Nov 15, 2024
79405ee
Update examples/nvidia_cuda_q/0_hello_cudaq_jobs.ipynb
yitchen-tim Nov 15, 2024
ae15bbc
Update examples/nvidia_cuda_q/0_hello_cudaq_jobs.ipynb
yitchen-tim Nov 15, 2024
ebbf3e3
Update examples/nvidia_cuda_q/2_parallel_simulations.ipynb
yitchen-tim Nov 15, 2024
c5f9fe8
Update examples/nvidia_cuda_q/2_parallel_simulations.ipynb
yitchen-tim Nov 15, 2024
093d6ed
Update examples/nvidia_cuda_q/2_parallel_simulations.ipynb
yitchen-tim Nov 15, 2024
5e23efb
Update 2_parallel_simulations.ipynb
yitchen-tim Nov 15, 2024
aa51264
Update examples/nvidia_cuda_q/0_hello_cudaq_jobs.ipynb
yitchen-tim Nov 15, 2024
833916b
Update examples/nvidia_cuda_q/2_parallel_simulations.ipynb
yitchen-tim Nov 15, 2024
b52aaad
Update examples/nvidia_cuda_q/0_hello_cudaq_jobs.ipynb
yitchen-tim Nov 15, 2024
b5798e2
Update examples/nvidia_cuda_q/0_hello_cudaq_jobs.ipynb
yitchen-tim Nov 15, 2024
f6f2261
Update examples/nvidia_cuda_q/2_parallel_simulations.ipynb
yitchen-tim Nov 15, 2024
dc59c3c
Update examples/nvidia_cuda_q/0_hello_cudaq_jobs.ipynb
yitchen-tim Nov 15, 2024
e77483b
Update README.md
yitchen-tim Nov 15, 2024
1cf2a3a
Update examples/nvidia_cuda_q/1_simulation_with_GPUs.ipynb
yitchen-tim Nov 15, 2024
7c7be90
Update README.md
yitchen-tim Nov 15, 2024
08b5c27
Update examples/nvidia_cuda_q/0_hello_cudaq_jobs.ipynb
yitchen-tim Nov 15, 2024
182fed5
Update examples/nvidia_cuda_q/1_simulation_with_GPUs.ipynb
yitchen-tim Nov 15, 2024
e426654
Update examples/nvidia_cuda_q/1_simulation_with_GPUs.ipynb
yitchen-tim Nov 15, 2024
62edfb3
Update examples/nvidia_cuda_q/1_simulation_with_GPUs.ipynb
yitchen-tim Nov 15, 2024
aed89f6
Update requirements.txt
yitchen-tim Nov 15, 2024
be542d1
Update README.md
yitchen-tim Nov 15, 2024
8d18646
add chmod to the shell script
yitchen-tim Nov 15, 2024
06c838a
update notebooks
yitchen-tim Nov 19, 2024
3832a0c
Update 2_parallel_simulations.ipynb
yitchen-tim Nov 19, 2024
a2d8c6f
fix linting
yitchen-tim Nov 19, 2024
e1ac925
remove seeds
yitchen-tim Nov 20, 2024
f962bff
update dependency name from "cuda-quantum" to "cudaq"
yitchen-tim Nov 27, 2024
43ae92b
update notebooks
yitchen-tim Nov 27, 2024
c082d89
byoc with cudaq wheel file
yitchen-tim Nov 27, 2024
c5d236b
clear notebook outputs
yitchen-tim Nov 27, 2024
d59a3f3
fix: linting
yitchen-tim Nov 27, 2024
6d149d2
Merge branch 'main' into feature/cudaq-byoc
rmshaffer Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update 2_parallel_simulations.ipynb
yitchen-tim committed Oct 11, 2024

Verified

This commit was signed with the committer’s verified signature.
bryanculver Bryan Culver
commit 1c07093bd26e2a658f3d4bf326f38dae8a88bfc3
31 changes: 26 additions & 5 deletions examples/cuda_quantum/byoc_job/2_parallel_simulations.ipynb
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@
"source": [
"# Parallel simulations on multiple GPUs\n",
"\n",
"For a circuit with a large qubit count, a single GPU may not be able to host a statevector due to the memory constraint. CUDA-Q supports distribution of a statevector over multiple GPUs and nodes. In addition, many quantum algorithms require sampling a batch of circuits. For example, evaluating a Hamiltonian requires evaluating many terms of the Hamiltonian. For variational algorithms, it often requires sampling a parametric circuit with many different sets of parameters. For error mitigation algorithms, it often requires sampling a large number of unrelated circuits. \n",
"Many quantum algorithms require sampling a batch of circuits and observables. For example, evaluating a Hamiltonian requires evaluating many terms of the Hamiltonian. For variational algorithms, it often requires sampling a parametric circuit with many different sets of parameters. For error mitigation algorithms, it often requires sampling a large number of unrelated circuits. \n",
"\n",
"In this notebook, you will learn how to use parallelization to tackle these challenges. With CUDA-Q and Braket Jobs, simulations of statevectors and circuit batches can be parallelized over multiple GPUs.\n"
"In this notebook, you will learn how to use parallelization to tackle these challenges. With CUDA-Q and Braket Jobs, the simulation of a batch of observables and circuits can be parallelized over multiple GPUs.\n"
]
},
{
@@ -135,9 +135,9 @@
"id": "083df36f-8ec4-468d-8e68-36c1fc1f4f5c",
"metadata": {},
"source": [
"## Distribution of a statevector over multiple GPUs\n",
"## Parallelize the simulation of a batch of observables\n",
"\n",
"Let's tackle the same problem again. But this time, we will run the simulation on multiple GPUs across multiple nodes using the [MPI interface](https://nvidia.github.io/cuda-quantum/latest/using/install/data_center_install.html#mpi). To do so, you add the keyword argument `execution=cudaq.parallel.mpi` to the `cudaq.observe()` call. With this keyword argument, CUDA-Q will distribute the simulation over the GPUs.\n",
"Let's tackle the same problem again. But this time, we will run the simulation on multiple GPUs across multiple nodes using the [MPI interface](https://nvidia.github.io/cuda-quantum/latest/using/install/data_center_install.html#mpi). To do so, you add the keyword argument `execution=cudaq.parallel.mpi` to the `cudaq.observe()` call. With this keyword argument, CUDA-Q will distribute the simulation over the GPUs available in a job.\n",
"\n",
"In order for CUDA-Q to distribute the simulation, there are some prerequisites. First, the job needs to run on instances that have many GPUs. To achieve this, you can specify the instance type that has multiple GPUs (e.g., ml.p3.8xlarge). If the number of GPUs on a single instance is not enough, you can extend the parallelization to multiple nodes by specifying `instanceCount` being larger than 1. Then, you need to add a hyperparameter `sagemaker_mpi_enabled=True` to the job which will initialize the job environment to support parallelization with MPI. Next, you need to select a CUDA-Q backend that supports distribution (e.g., `nvidia` backend with the `mqpu` option). Finally, you need to initialize the MPI interface in your CUDA-Q code. The code snippet below provides example of all these steps."
]
@@ -244,7 +244,7 @@
"id": "08ab1628-4622-4e24-8cdd-f4a686b05e5a",
"metadata": {},
"source": [
"In this example, the circuit batch is formed by a single parametric circuit with many different sets of parameters. To assign a parameter set to a particular GPU, you can use the `qpu_id` keyword in the `cudaq.observe_async()` call. For example, to assign a simulation to GPU with rank 5, you set `qpu_id=5`."
"In this example, the circuit batch is formed by a single parametric circuit with many different sets of parameters. To assign a parameter set to a particular GPU, you can use the `qpu_id` keyword in the `cudaq.observe_async()` call. For example, to assign a simulation to GPU with rank 5, you set `qpu_id=5`. "
]
},
{
@@ -328,6 +328,27 @@
"print(\"Job ARN: \", parallel_batch_job.arn)"
]
},
{
"cell_type": "markdown",
"id": "4a30ffdb-dbc5-4000-af8e-c63dd713d153",
"metadata": {},
"source": [
"Currently, `observe_async()` only supports distribution over GPUs on the same node, so the `qpu_id` needs to be econsistent with the number of GPUs of a single instance used in the job. However, if you wish to distribution the circuit batch over multiple nodes, you can manually assign different circuit batch to different node with the following MPI logic:\n",
"```\n",
"ngpu_per_node = ... # number of gpus per node\n",
"circuit_batch_0 = ... # circuit batch for node 0\n",
"circuit_batch_1 = ... # circuit batch for node 1\n",
"\n",
"if cudaq.mpi.rank()//ngpu_per_node==0:\n",
" for circuit in circuit_batch_0:\n",
" cudaq.observe_async(circuit, hamiltonian, shots_count=n_shots, qpu_id=qpu_id)\n",
"if cudaq.mpi.rank()//ngpu_per_node==1:\n",
" for circuit in circuit_batch_1:\n",
" cudaq.observe_async(circuit, hamiltonian, shots_count=n_shots, qpu_id=qpu_id)\n",
" \n",
"```"
]
},
{
"cell_type": "markdown",
"id": "18004fe8-24a0-4316-ab0a-a4e0aac6ba1e",