Skip to content

Commit f9b611c

Browse files
committed
Merge branch 'amc-apply.noise' into amc-apply.noise-bmh
2 parents debfb00 + 3756f44 commit f9b611c

14 files changed

+171
-19
lines changed

.github/workflows/dev_environment.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ jobs:
218218
uses: docker/setup-buildx-action@v3
219219
with:
220220
endpoint: builder_context
221-
driver-opts: network=host
221+
version: v0.19.0
222+
driver-opts: |
223+
network=host
224+
image=moby/buildkit:v0.19.0
222225
223226
- name: Log in to DockerHub
224227
uses: docker/login-action@v3

.github/workflows/docker_images.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ jobs:
161161
uses: docker/setup-buildx-action@v3
162162
with:
163163
endpoint: builder_context
164-
driver-opts: network=host
164+
version: v0.19.0
165+
driver-opts: |
166+
network=host
167+
image=moby/buildkit:v0.19.0
165168
166169
- name: Build Open MPI
167170
id: docker_build
@@ -308,7 +311,10 @@ jobs:
308311
uses: docker/setup-buildx-action@v3
309312
with:
310313
endpoint: builder_context
311-
driver-opts: network=host
314+
version: v0.19.0
315+
driver-opts: |
316+
network=host
317+
image=moby/buildkit:v0.19.0
312318
313319
- name: Extract metadata
314320
id: metadata
@@ -512,7 +518,10 @@ jobs:
512518
uses: docker/setup-buildx-action@v3
513519
with:
514520
endpoint: builder_context
515-
driver-opts: network=host
521+
version: v0.19.0
522+
driver-opts: |
523+
network=host
524+
image=moby/buildkit:v0.19.0
516525
517526
- name: Extract cuda-quantum-dev metadata
518527
id: cudaqdev_metadata

.github/workflows/generate_cc.yml

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ jobs:
6060
uses: docker/setup-buildx-action@v3
6161
with:
6262
endpoint: builder_context
63+
version: v0.19.0
64+
driver-opts: |
65+
image=moby/buildkit:v0.19.0
6366
6467
- name: Build CUDA Quantum
6568
id: cudaq_build

.github/workflows/gh_registry.yml

+3
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ jobs:
121121
uses: docker/setup-buildx-action@v3
122122
with:
123123
endpoint: builder_context
124+
version: v0.19.0
125+
driver-opts: |
126+
image=moby/buildkit:v0.19.0
124127
125128
- name: Prepare push
126129
id: metadata

.github/workflows/integration_tests.yml

+6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ jobs:
121121
uses: docker/setup-buildx-action@v3
122122
with:
123123
endpoint: builder_context
124+
version: v0.19.0
125+
driver-opts: |
126+
image=moby/buildkit:v0.19.0
124127
125128
- name: Extract metadata
126129
id: metadata
@@ -195,6 +198,9 @@ jobs:
195198
uses: docker/setup-buildx-action@v3
196199
with:
197200
endpoint: builder_context
201+
version: v0.19.0
202+
driver-opts: |
203+
image=moby/buildkit:v0.19.0
198204
199205
- name: Login to NGC container registry
200206
uses: docker/login-action@v3

.github/workflows/prebuilt_binaries.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ jobs:
127127
uses: docker/setup-buildx-action@v3
128128
with:
129129
endpoint: builder_context
130-
driver-opts: network=host
130+
version: v0.19.0
131+
driver-opts: |
132+
network=host
133+
image=moby/buildkit:v0.19.0
131134
132135
- name: Extract metadata
133136
id: metadata
@@ -225,6 +228,9 @@ jobs:
225228
uses: docker/setup-buildx-action@v3
226229
with:
227230
endpoint: builder_context
231+
version: v0.19.0
232+
driver-opts: |
233+
image=moby/buildkit:v0.19.0
228234
229235
- name: Log in to DockerHub
230236
uses: docker/login-action@v3

.github/workflows/publishing.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ jobs:
430430

431431
- name: Set up buildx runner
432432
uses: docker/setup-buildx-action@v3
433+
with:
434+
version: v0.19.0
435+
driver-opts: |
436+
image=moby/buildkit:v0.19.0
433437
434438
- name: Extract cuda-quantum metadata
435439
id: metadata
@@ -586,6 +590,10 @@ jobs:
586590

587591
- name: Set up buildx runner
588592
uses: docker/setup-buildx-action@v3
593+
with:
594+
version: v0.19.0
595+
driver-opts: |
596+
image=moby/buildkit:v0.19.0
589597
590598
- name: Build installer
591599
uses: docker/build-push-action@v5
@@ -696,7 +704,10 @@ jobs:
696704
uses: docker/setup-buildx-action@v3
697705
with:
698706
endpoint: builder_context
699-
driver-opts: network=host
707+
version: v0.19.0
708+
driver-opts: |
709+
network=host
710+
image=moby/buildkit:v0.19.0
700711
701712
- name: Build cuda-quantum wheel
702713
id: build_wheel

.github/workflows/publishing_stable.yml

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ jobs:
115115
116116
- name: Set up buildx runner
117117
uses: docker/setup-buildx-action@v3
118+
with:
119+
version: v0.19.0
120+
driver-opts: |
121+
image=moby/buildkit:v0.19.0
118122
119123
- name: Update cuda-quantum metadata
120124
id: metadata

.github/workflows/python_wheels.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ jobs:
129129
uses: docker/setup-buildx-action@v3
130130
with:
131131
endpoint: builder_context
132-
driver-opts: network=host
132+
version: v0.19.0
133+
driver-opts: |
134+
network=host
135+
image=moby/buildkit:v0.19.0
133136
134137
- name: Build wheel
135138
id: wheel_build

.github/workflows/test_in_devenv.yml

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ jobs:
6161
uses: docker/setup-buildx-action@v3
6262
with:
6363
endpoint: builder_context
64+
version: v0.19.0
65+
driver-opts: |
66+
image=moby/buildkit:v0.19.0
6467
6568
- name: Build CUDA Quantum
6669
run: |
@@ -191,6 +194,9 @@ jobs:
191194
uses: docker/setup-buildx-action@v3
192195
with:
193196
endpoint: builder_context
197+
version: v0.19.0
198+
driver-opts: |
199+
image=moby/buildkit:v0.19.0
194200
195201
- name: Set up dev environment
196202
id: dev_env

docs/sphinx/using/backends/sims/noisy.rst

+101-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,106 @@
1-
2-
Density Matrix Simulators
1+
Noisy Simulators
32
==================================
43

4+
Trajectory Noisy Simulation
5+
++++++++++++++++++++++++++++++++++
6+
7+
The :code:`nvidia` target supports noisy quantum circuit simulations using
8+
quantum trajectory method across all configurations: single GPU, multi-node
9+
multi-GPU, and with host memory. When simulating many trajectories with small
10+
state vectors, the simulation is batched for optimal performance.
11+
12+
When a :code:`noise_model` is provided to CUDA-Q, the :code:`nvidia` target
13+
will incorporate quantum noise into the quantum circuit simulation according
14+
to the noise model specified.
15+
16+
17+
.. tab:: Python
18+
19+
.. literalinclude:: ../../../snippets/python/using/backends/trajectory.py
20+
:language: python
21+
:start-after: [Begin Docs]
22+
23+
.. code:: bash
24+
25+
python3 program.py
26+
{ 00:15 01:92 10:81 11:812 }
27+
28+
.. tab:: C++
29+
30+
.. literalinclude:: ../../../snippets/cpp/using/backends/trajectory.cpp
31+
:language: cpp
32+
:start-after: [Begin Documentation]
33+
34+
.. code:: bash
35+
36+
nvq++ --target nvidia program.cpp [...] -o program.x
37+
./program.x
38+
{ 00:15 01:92 10:81 11:812 }
39+
40+
41+
In the case of bit-string measurement sampling as in the above example, each measurement 'shot' is executed as a trajectory, whereby Kraus operators specified in the noise model are sampled.
42+
43+
For observable expectation value estimation, the statistical error scales asymptotically as :math:`1/\sqrt{N_{trajectories}}`, where :math:`N_{trajectories}` is the number of trajectories.
44+
Hence, depending on the required level of accuracy, the number of trajectories can be specified accordingly.
45+
46+
.. tab:: Python
47+
48+
.. literalinclude:: ../../../snippets/python/using/backends/trajectory_observe.py
49+
:language: python
50+
:start-after: [Begin Docs]
51+
52+
.. code:: bash
53+
54+
python3 program.py
55+
Noisy <Z> with 1024 trajectories = -0.810546875
56+
Noisy <Z> with 8192 trajectories = -0.800048828125
57+
58+
.. tab:: C++
59+
60+
.. literalinclude:: ../../../snippets/cpp/using/backends/trajectory_observe.cpp
61+
:language: cpp
62+
:start-after: [Begin Documentation]
63+
64+
.. code:: bash
65+
66+
nvq++ --target nvidia program.cpp [...] -o program.x
67+
./program.x
68+
Noisy <Z> with 1024 trajectories = -0.810547
69+
Noisy <Z> with 8192 trajectories = -0.800049
70+
71+
72+
The following environment variable options are applicable to the :code:`nvidia` target for trajectory noisy simulation. Any environment variables must be set
73+
prior to setting the target.
74+
75+
.. list-table:: **Additional environment variable options for trajectory simulation**
76+
:widths: 20 30 50
77+
78+
* - Option
79+
- Value
80+
- Description
81+
* - ``CUDAQ_OBSERVE_NUM_TRAJECTORIES``
82+
- positive integer
83+
- The default number of trajectories for observe simulation if none was provided in the `observe` call. The default value is 1000.
84+
* - ``CUDAQ_BATCH_SIZE``
85+
- positive integer or `NONE`
86+
- The number of state vectors in the batched mode. If `NONE`, the batch size will be calculated based on the available device memory. Default is `NONE`.
87+
* - ``CUDAQ_BATCHED_SIM_MAX_BRANCHES``
88+
- positive integer
89+
- The number of trajectory branches to be tracked simultaneously in the gate fusion. Default is 16.
90+
* - ``CUDAQ_BATCHED_SIM_MAX_QUBITS``
91+
- positive integer
92+
- The max number of qubits for batching. If the qubit count in the circuit is more than this value, batched trajectory simulation will be disabled. The default value is 20.
93+
* - ``CUDAQ_BATCHED_SIM_MIN_BATCH_SIZE``
94+
- positive integer
95+
- The minimum number of trajectories for batching. If the number of trajectories is less than this value, batched trajectory simulation will be disabled. Default value is 4.
96+
97+
.. note::
98+
99+
Batched trajectory simulation is only available on the single-GPU execution mode of the :code:`nvidia` target.
100+
101+
If batched trajectory simulation is not activated, e.g., due to problem size, number of trajectories, or the nature of the circuit (dynamic circuits with mid-circuit measurements and conditional branching), the required number of trajectories will be executed sequentially.
102+
103+
5104
6105
Density Matrix
7106
++++++++++++++++

docs/sphinx/using/backends/simulators.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ technical details and code examples for using each circuit simulator.
2828
- < 28
2929
* - `nvidia`
3030
- State Vector
31-
- General purpose (default)
31+
- General purpose (default); Trajectory simulation for noisy circuits
3232
- Single GPU
3333
- single / double
3434
- < 33 / 32 (64 GB)

lib/Optimizer/CodeGen/ConvertToQIRAPI.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -2081,9 +2081,8 @@ struct QuakeToQIRAPIFinalPass
20812081
auto *ctx = &getContext();
20822082
ModuleOp module = getOperation();
20832083
RewritePatternSet patterns(ctx);
2084-
patterns.insert<MaterializeConstantArrayOpRewrite>(ctx);
2085-
if (api == "base-profile")
2086-
patterns.insert<AnnotateKernelsWithMeasurementStringsPattern>(ctx);
2084+
patterns.insert<MaterializeConstantArrayOpRewrite,
2085+
AnnotateKernelsWithMeasurementStringsPattern>(ctx);
20872086
if (failed(applyPatternsAndFoldGreedily(module, std::move(patterns))))
20882087
signalPassFailure();
20892088
}

runtime/common/NoiseModel.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ isScaledUnitary(const std::vector<std::complex<double>> &mat, double eps) {
2525
RowMajorMatTy;
2626
const int dim = std::log2(mat.size());
2727
Eigen::Map<const RowMajorMatTy> kMat(mat.data(), dim, dim);
28-
if (kMat.isZero())
28+
if (kMat.isZero(eps))
2929
return 0.0;
3030
// Check that (K_dag * K) is a scaled identity matrix
3131
// i.e., the K matrix is a scaled unitary.
3232
auto kdK = kMat.adjoint() * kMat;
33-
if (!kdK.isDiagonal())
33+
if (!kdK.isDiagonal(eps))
3434
return std::nullopt;
3535
// First element
3636
std::complex<double> val = kdK(0, 0);
37-
if (std::abs(val) > eps && std::abs(val.imag()) < eps) {
37+
if (val.real() > eps && std::abs(val.imag()) < eps) {
3838
auto scaledKdK = (std::complex<double>{1.0} / val) * kdK;
3939
if (scaledKdK.isIdentity())
40-
return val.real();
40+
return std::sqrt(val.real());
4141
}
4242
return std::nullopt;
4343
}
@@ -67,8 +67,8 @@ computeUnitaryMixture(
6767
const auto scaledFactor = isScaledUnitary(op, tol);
6868
if (!scaledFactor.has_value())
6969
return std::nullopt;
70-
probs.emplace_back(scaledFactor.value());
71-
mats.emplace_back(scaleMat(op, std::sqrt(scaledFactor.value())));
70+
probs.emplace_back(scaledFactor.value() * scaledFactor.value());
71+
mats.emplace_back(scaleMat(op, scaledFactor.value()));
7272
}
7373

7474
if (std::abs(1.0 - std::reduce(probs.begin(), probs.end())) > tol)

0 commit comments

Comments
 (0)