Skip to content

Commit

Permalink
Remove more analytic occurrences (#1261)
Browse files Browse the repository at this point in the history
* plugin build guide

* test file

* changelog

* no shots when None in test config

* Update .github/CHANGELOG.md

Co-authored-by: Josh Izaac <[email protected]>

Co-authored-by: Josh Izaac <[email protected]>
  • Loading branch information
antalszava and josh146 authored Apr 30, 2021
1 parent ef87a8c commit a436199
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@

<h3>Documentation</h3>

* Removes occurrences of the deprecated device argument ``analytic`` from the documentation.
[(#1261)](https://github.com/PennyLaneAI/pennylane/pull/1261)

* Updated the order of the parameters to the `GaussianState` operation to match
the way that the PennyLane-SF plugin uses them.
[(#1255)](https://github.com/PennyLaneAI/pennylane/pull/1255)
Expand Down
22 changes: 11 additions & 11 deletions doc/development/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ following arguments:
or iterable that contains unique labels for the subsystems as numbers (i.e., ``[-1, 0, 2]``)
and/or strings (``['ancilla', 'q1', 'q2']``).

* ``shots=1000`` (*int*): number of circuit evaluations/random samples used to estimate
expectation values of observables in non-analytic mode.

* ``analytic=True`` (*bool*): If ``True``, the device calculates probability, expectation
values, and variances analytically. If ``False``, a finite number of samples
are used to estimate these quantities. Note that hardware devices should always set
``analytic=False``.
* ``shots=1000`` (*None*, *int* or *List[iint]*): number of circuit
evaluations/random samples used to estimate probabilities, expectation
values, variances of observables in non-analytic mode. If ``None``, the device
calculates probability, expectation values, and variances analytically. If an
integer, it specifies the number of samples to estimate these quantities. If a
list of integers is passed, the circuit evaluations are batched over the list
of shots.

To add your own device arguments, or to override any of the above defaults, simply
overwrite the ``__init__.py`` method. For example, here is a device where the number
Expand All @@ -167,7 +167,7 @@ of low-level hardware control options:
observables = {"PauliZ", "PauliX", "PauliY"}
def __init__(self, shots=1024, hardware_options=None):
super().__init__(wires=24, shots=shots, analytic=False)
super().__init__(wires=24, shots=shots)
self.hardware_options = hardware_options or hardware_defaults
Note that we have also overridden the default shot number.
Expand All @@ -193,7 +193,7 @@ To execute operations on the device, the following methods **must** be defined:

apply

If the device is a statevector simulator (it has an ``analytic`` attribute)
If the device is a statevector simulator (it can perform analytic computations when ``shots=None``)
then it **must** also overwrite:

.. autosummary::
Expand Down Expand Up @@ -241,7 +241,7 @@ your plugin which, by default, performs the following process:
self.apply(circuit.operations, rotations=circuit.diagonalizing_gates)
# generate computational basis samples
if (not self.analytic) or circuit.is_sampled:
if self.shots is not None or circuit.is_sampled:
self._samples = self.generate_samples()
# compute the required statistics
Expand Down Expand Up @@ -410,7 +410,7 @@ test utility:

.. code-block:: console
pl-device-test --device device_shortname --shots 10000 --analytic False
pl-device-test --device device_shortname --shots 10000
In general, as all supported operations have their gradient formula defined and tested by
PennyLane, testing that your device calculates the correct gradients is not required.
Expand Down
2 changes: 0 additions & 2 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
[strawberryfields.global]
hbar = 1
shots = 1000
analytic = true
[strawberryfields.fock]
cutoff_dim = 10
Expand Down

0 comments on commit a436199

Please sign in to comment.