Skip to content

Commit 3229c5d

Browse files
Docs preview for PR #2632.
1 parent 7ffc639 commit 3229c5d

File tree

113 files changed

+979
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+979
-161
lines changed

pr-2632/_images/qpus.png

95.4 KB
Loading

pr-2632/_sources/api/languages/python_api.rst.txt

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ Noisy Simulation
218218

219219
.. autoclass:: cudaq::NoiseModel
220220
:members:
221+
:exclude-members: register_channel
221222
:special-members: __init__
222223

223224
.. autoclass:: cudaq::BitFlipChannel

pr-2632/_sources/specification/cudaq/algorithmic_primitives.rst.txt

+60-24
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,16 @@ extract the result information in the following manner:
130130
};
131131
}
132132
133-
**[7]** The :code:`sample_result` type enables one to encode measurement results from a
134-
quantum circuit sampling task. It keeps track of a list of sample results, each
135-
one corresponding to a measurement action during the sampling process and represented
136-
by a unique register name. It also tracks a unique global register, the implicit sampling
137-
of the state at the end of circuit execution. The API gives fine-grain access
138-
to the measurement results for each register. To illustrate this, observe
133+
**[7]** By default the :code:`sample_result` type enables one to encode
134+
measurement results from a quantum circuit sampling task. It keeps track of a
135+
list of sample results, each one corresponding to a measurement action during
136+
the sampling process and represented by a unique register name. It also tracks
137+
a unique global register, which by default, contains the implicit sampling of
138+
the state at the end of circuit execution. If the :code:`explicit_measurements`
139+
sample option is enabled, the global register contains all measurements
140+
concatenated together in the order the measurements occurred in the kernel.
141+
The API gives fine-grain access to the measurement results for each register.
142+
To illustrate this, observe
139143

140144
.. tab:: C++
141145

@@ -148,8 +152,14 @@ to the measurement results for each register. To illustrate this, observe
148152
reset (q);
149153
x(q);
150154
};
155+
156+
printf("Default - no explicit measurements\n");
151157
cudaq::sample(kernel).dump();
152158
159+
cudaq::sample_options options{.explicit_measurements = true};
160+
printf("Setting `explicit_measurements` option\n");
161+
cudaq::sample(options, kernel).dump();
162+
153163
.. tab:: Python
154164

155165
.. code-block:: python
@@ -162,30 +172,41 @@ to the measurement results for each register. To illustrate this, observe
162172
reset(q)
163173
x(q)
164174
175+
print("Default - no explicit measurements")
165176
cudaq.sample(kernel).dump()
166177
178+
print("Setting `explicit_measurements` option")
179+
cudaq.sample(kernel, explicit_measurements=True).dump()
180+
167181
should produce
168182

169183
.. code-block:: bash
170184
185+
Default - no explicit measurements
171186
{
172187
__global__ : { 1:1000 }
173-
reg1 : { 0:501 1:499 }
188+
reg1 : { 0:506 1:494 }
174189
}
175190
191+
Setting `explicit_measurements` option
192+
{ 0:479 1:521 }
193+
176194
Here we see that we have measured a qubit in a uniform superposition to a
177195
register named :code:`reg1`, and followed it with a reset and the application
178-
of an NOT operation. The :code:`sample_result` returned for this sampling
179-
tasks contains the default :code:`__global__` register as well as the user
180-
specified :code:`reg1` register.
196+
of an NOT operation. By default the :code:`sample_result` returned for this
197+
sampling tasks contains the default :code:`__global__` register as well as the
198+
user specified :code:`reg1` register.
181199
182200
The contents of the :code:`__global__` register will depend on how your kernel
183201
is written:
184202
185-
1. If no measurements appear in the kernel, then the :code:`__global__`
186-
register is formed with implicit measurements being added for *all* the
187-
qubits defined in the kernel, and the measurements all occur at the end of
188-
the kernel. The order of the bits in the bitstring corresponds to the qubit
203+
1. If no measurements appear in the kernel, then the :code:`__global__`
204+
register is formed with implicit measurements being added for *all* the
205+
qubits defined in the kernel, and the measurements all occur at the end of
206+
the kernel. This is not supported when sampling with the
207+
:code:`explicit_measurements` option; kernels executed with
208+
:code:`explicit_measurements` mode must contain measurements.
209+
The order of the bits in the bitstring corresponds to the qubit
189210
allocation order specified in the kernel. That is - the :code:`[0]` element
190211
in the :code:`__global__` bitstring corresponds with the first declared qubit
191212
in the kernel. For example,
@@ -222,12 +243,15 @@ should produce
222243
2. Conversely, if any measurements appear in the kernel, then only the measured
223244
qubits will appear in the :code:`__global__` register. Similar to #1, the
224245
bitstring corresponds to the qubit allocation order specified in the kernel.
225-
Also (again, similar to #1), the values of the sampled qubits always
226-
correspond to the values *at the end of the kernel execution*. That is - if a
227-
qubit is measured in the middle of a kernel and subsequent operations change
228-
the state of the qubit, the qubit will be implicitly re-measured at the end
229-
of the kernel, and that re-measured value is the value that will appear in
230-
the :code:`__global__` register. For example,
246+
Also (again, similar to #1), the values of the sampled qubits always
247+
correspond to the values *at the end of the kernel execution*, unless the
248+
:code:`explicit_measurements` option is enabled. That is - if a qubit is
249+
measured in the middle of a kernel and subsequent operations change the state
250+
of the qubit, the qubit will be implicitly re-measured at the end of the
251+
kernel, and that re-measured value is the value that will appear in the
252+
:code:`__global__` register. If the sampling option :code:`explicit_measurements`
253+
is enabled, then no re-measurements occur, and the global register contains
254+
the concatenated measurements in the order they were executed in the kernel.
231255
232256
.. tab:: C++
233257
@@ -239,8 +263,14 @@ should produce
239263
mz(b);
240264
mz(a);
241265
};
266+
267+
printf("Default - no explicit measurements\n");
242268
cudaq::sample(kernel).dump();
243269
270+
cudaq::sample_options options{.explicit_measurements = true};
271+
printf("Setting `explicit_measurements` option\n");
272+
cudaq::sample(options, kernel).dump();
273+
244274
.. tab:: Python
245275
246276
.. code-block:: python
@@ -252,15 +282,21 @@ should produce
252282
mz(b)
253283
mz(a)
254284
255-
cudaq.sample(kernel).dump()
285+
print("Default - no explicit measurements")
286+
cudaq.sample(kernel).dump()
287+
288+
print("Setting `explicit_measurements` option")
289+
cudaq.sample(kernel, explicit_measurements=True).dump()
256290
257291
should produce
258292
259293
.. code-block:: bash
260294
261-
{
262-
__global__ : { 10:1000 }
263-
}
295+
Default - no explicit measurements
296+
{ 10:1000 }
297+
298+
Setting `explicit_measurements` option
299+
{ 01:1000 }
264300
265301
.. note::
266302

pr-2632/_sources/using/backends/cloud/braket.rst.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ circuit simulators, and secure, on-demand access to various quantum computers.
99
To get started users must enable Amazon Braket in their AWS account by following
1010
`these instructions <https://docs.aws.amazon.com/braket/latest/developerguide/braket-enable-overview.html>`__.
1111
To learn more about Amazon Braket, you can view the `Amazon Braket Documentation <https://docs.aws.amazon.com/braket/>`__
12-
and `Amazon Braket Examples <https://github.com/amazon-braket/amazon-braket-examples>`__.
12+
and `Amazon Braket Examples <https://github.com/amazon-braket/amazon-braket-examples/tree/main/examples/nvidia_cuda_q>`__.
1313
A list of available devices and regions can be found `here <https://docs.aws.amazon.com/braket/latest/developerguide/braket-devices.html>`__.
1414

1515
Users can run CUDA-Q programs on Amazon Braket with `Hybrid Job <https://docs.aws.amazon.com/braket/latest/developerguide/braket-what-is-hybrid-job.html>`__.
16-
See `this guide <https://docs.aws.amazon.com/braket/latest/developerguide/braket-jobs-first.html>`__ to get started.
16+
See `this guide <https://docs.aws.amazon.com/braket/latest/developerguide/braket-jobs-first.html>`__ to get started with Hybrid Jobs and `this guide <https://docs.aws.amazon.com/braket/latest/developerguide/braket-using-cuda-q.html>`__ on how to use CUDA-Q with Amazon Braket.
1717

1818
Setting Credentials
1919
```````````````````

pr-2632/_sources/using/backends/hardware/neutralatom.rst.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,14 @@ Submitting
133133
Pasqal
134134
++++++++++++++++
135135

136-
Pasqal is a quantum computing hardware company that builds quantum processors from ordered neutral atoms in 2D and 3D arrays to bring a practical quantum advantage to its customers and address real-world problems.
137-
The currently available Pasqal QPUs are analog quantum computers.
136+
Pasqal is a quantum computing hardware company that builds quantum processors from ordered neutral atoms in 2D and 3D
137+
arrays to bring a practical quantum advantage to its customers and address real-world problems.
138+
The currently available Pasqal QPUs are analog quantum computers, and one, named Fresnel, is available through our cloud
139+
portal.
138140

139141
In order to access Pasqal's devices you need an account for `Pasqal's cloud platform <https://portal.pasqal.cloud>`__
140-
and an active project. Although a different interface `Pasqal's Pulser library <https://pulser.readthedocs.io/en/latest/>`__ is a good
141-
way of getting started with analog neutral atom quantum computing. For support you can also use `Pasqal Community <https://community.pasqal.com/>`__.
142+
and an active project. Although a different interface, `Pasqal's Pulser library <https://pulser.readthedocs.io/en/latest/>`__, is a good
143+
resource for getting started with analog neutral atom quantum computing. For support you can also use `Pasqal Community <https://community.pasqal.com/>`__.
142144

143145

144146
.. _pasqal-backend:

pr-2632/_sources/using/backends/sims/noisy.rst.txt

+103-3
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
++++++++++++++++
@@ -70,7 +169,8 @@ To execute a program on the :code:`stim` target, use the following commands:
70169
./program.x
71170
72171
.. note::
73-
CUDA-Q currently executes kernels using a "shot-by-shot" execution approach.
172+
By default CUDA-Q executes kernels using a "shot-by-shot" execution approach.
74173
This allows for conditional gate execution (i.e. full control flow), but it
75174
can be slower than executing Stim a single time and generating all the shots
76175
from that single execution.
176+
Set the `explicit_measurements` flag with `sample` API for efficient execution.

pr-2632/_sources/using/backends/simulators.rst.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ technical details and code examples for using each circuit simulator.
2424
- State Vector
2525
- Testing and small applications
2626
- CPU
27-
- single
27+
- double
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)
@@ -72,7 +72,7 @@ technical details and code examples for using each circuit simulator.
7272
- Density Matrix
7373
- Noisy simulations
7474
- CPU
75-
- single
75+
- double
7676
- < 14
7777
* - `stim`
7878
- Stabilizer

pr-2632/api/api.html

+1
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@
365365
</ul>
366366
</li>
367367
<li class="toctree-l3"><a class="reference internal" href="../using/backends/sims/noisy.html"> Noisy Simulators</a><ul>
368+
<li class="toctree-l4"><a class="reference internal" href="../using/backends/sims/noisy.html#trajectory-noisy-simulation">Trajectory Noisy Simulation</a></li>
368369
<li class="toctree-l4"><a class="reference internal" href="../using/backends/sims/noisy.html#density-matrix">Density Matrix</a></li>
369370
<li class="toctree-l4"><a class="reference internal" href="../using/backends/sims/noisy.html#stim">Stim</a></li>
370371
</ul>

pr-2632/api/default_ops.html

+1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@
367367
</ul>
368368
</li>
369369
<li class="toctree-l3"><a class="reference internal" href="../using/backends/sims/noisy.html"> Noisy Simulators</a><ul>
370+
<li class="toctree-l4"><a class="reference internal" href="../using/backends/sims/noisy.html#trajectory-noisy-simulation">Trajectory Noisy Simulation</a></li>
370371
<li class="toctree-l4"><a class="reference internal" href="../using/backends/sims/noisy.html#density-matrix">Density Matrix</a></li>
371372
<li class="toctree-l4"><a class="reference internal" href="../using/backends/sims/noisy.html#stim">Stim</a></li>
372373
</ul>

0 commit comments

Comments
 (0)