Skip to content

Commit 7b4262c

Browse files
Updating the documentation of qml.device (#8294)
**Context:** The documentation of `qml.device` was outdated, so this PR updates it. **Description of the Change:** As above. **Benefits:** The example are compatible with latest PL. **Possible Drawbacks:** None that I can think of. **Related GitHub Issues:** #7992 [sc-99473]
1 parent 404b192 commit 7b4262c

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

doc/releases/changelog-dev.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,9 @@
11091109

11101110
<h3>Documentation 📝</h3>
11111111

1112+
* The documentation of `qml.device` has been updated.
1113+
[(#8294)](https://github.com/PennyLaneAI/pennylane/pull/8294)
1114+
11121115
* The "Simplifying Operators" section in the :doc:`Compiling circuits </introduction/compiling_circuits>` page was pushed further down the page to show more relevant sections first.
11131116
[(#8233)](https://github.com/PennyLaneAI/pennylane/pull/8233)
11141117

pennylane/devices/device_constructor.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,12 @@ def device(name, *args, **kwargs):
9797
9898
Args:
9999
name (str): the name of the device to load
100-
wires (int): the number of wires (subsystems) to initialise
101-
the device with. Note that this is optional for certain
102-
devices, such as ``default.qubit``
100+
wires (Wires): the wires (subsystems) to initialize the device with.
101+
Note that this is optional for certain devices, such as ``default.qubit``
103102
104103
Keyword Args:
105104
config (pennylane.Configuration): a PennyLane configuration object
106-
that contains global and/or device specific configurations.
105+
that contains global and/or device-specific configurations.
107106
custom_decomps (Dict[Union(str, Operator), Callable]): Custom
108107
decompositions to be applied by the device at runtime.
109108
@@ -140,39 +139,35 @@ def circuit():
140139
141140
>>> dev = qml.device("default.qubit")
142141
143-
Most devices accept a ``shots`` argument which specifies how many circuit executions
144-
are used to estimate stochastic return values. As an example, ``qml.sample()`` measurements
145-
will return as many samples as specified in the shots argument. The shots argument can be
146-
changed on a per-call basis using the built-in ``shots`` keyword argument. Note that the
147-
``shots`` argument can be a single integer or a list of shot values.
142+
When executing quantum circuits on a device, we can specify the number of times the circuit must be executed
143+
to estimate stochastic return values by using the :func:`~pennylane.set_shots` transform.
144+
As an example, ``qml.sample()`` measurements will return as many samples as the number of shots specified.
145+
Note that ``shots`` can be a single integer or a list of shot values.
148146
149147
.. code-block:: python
150148
151-
from functools import partial
152-
153149
dev = qml.device('default.qubit', wires=1)
154150
155-
@partial(qml.set_shots, shots=10)
151+
@qml.set_shots(10)
156152
@qml.qnode(dev)
157153
def circuit(a):
158154
qml.RX(a, wires=0)
159155
return qml.sample(qml.Z(0))
160156
161157
>>> circuit(0.8) # 10 samples are returned
162158
array([ 1, 1, 1, 1, -1, 1, 1, -1, 1, 1])
163-
>>> circuit(0.8, shots=[3, 4, 4]) # default is overwritten for this call
164-
(array([1, 1, 1]), array([ 1, -1, 1, 1]), array([1, 1, 1, 1]))
165-
>>> circuit(0.8) # back to default of 10 samples
166-
array([ 1, -1, 1, 1, -1, 1, 1, 1, 1, 1])
159+
>>> new_circuit = qml.set_shots(circuit, shots=[3, 4, 4])
160+
>>> new_circuit(0.8) # 3, 4, and 4 samples are returned respectively
161+
(array([1., 1., 1.]), array([ 1., 1., 1., -1.]), array([ 1., 1., -1., 1.]))
167162
168163
When constructing a device, we may optionally pass a dictionary of custom
169164
decompositions to be applied to certain operations upon device execution.
170165
This is useful for enabling support of gates on devices where they would normally
171166
be unsupported.
172167
173-
For example, suppose we are running on an ion trap device which does not
168+
For example, suppose we are running on an ion trap device that does not
174169
natively implement the CNOT gate, but we would still like to write our
175-
circuits in terms of CNOTs. On a ion trap device, CNOT can be implemented
170+
circuits in terms of CNOTs. On an ion trap device, CNOT can be implemented
176171
using the ``IsingXX`` gate. We first define a decomposition function
177172
(such functions have the signature ``decomposition(*params, wires)``):
178173
@@ -187,7 +182,7 @@ def ion_trap_cnot(wires, **_):
187182
qml.RY(-np.pi/2, wires=wires[1])
188183
]
189184
190-
Next, we create a device, and a QNode for testing. When constructing the
185+
Next, we create a device and a QNode for testing. When constructing the
191186
QNode, we can set the expansion strategy to ``"device"`` to ensure the
192187
decomposition is applied and will be viewable when we draw the circuit.
193188
Note that custom decompositions should accept keyword arguments even when

0 commit comments

Comments
 (0)