Skip to content

Commit

Permalink
merge 0.31 RC branch to master (#4305)
Browse files Browse the repository at this point in the history
* Support `HardwareHamiltonian` pulses in `stoch_pulse_grad` (#4215)

* single out gradient transform checks

* rename stochastic pulse gradient file

* unify gradient_analysis and grad_method_validation

* continue restructure of analysis+validation

* CV

* black

* modularize more

* more modularizing

* black

* tiny [skip ci]

* [skip ci] lint

* remove dummy test

* test fix

* add test file to linting test file

* test fixes, docstrings

* code review

* docstring gradient_analysis_and_grad_method_validation

* move first fun

* code review:move functions

* test regex

* regexs

* move and promote reorder_grads

* tmp

* more tmp

* test cases, contractions

* lint

* docstring

* even more tmp

* cleanup

* black

* tmp

* lint

* move stoch_pulse_gradient.. files back to pulse_gradient...

* move stoch_pulse_gradient.. files back to pulse_gradient...

* lint

* rename

* extend functions and tests

* lint and black

* changelog

* improve

* update example to include non-Pauli word generator

* add jit test with pauli sentence

* tmp

* debugging, docstring, extend test

* review

* optimize for Pauli words

* Apply suggestions from code review

Co-authored-by: Romain Moyard <rmoyard@gmail.com>

* test cases code review

* fix parametrization

* drafting

* working prototype

* finish merge; cleanup

* changelog

* comments

* [skip ci]

* raising an error; cleanup [skip ci]

* Apply suggestions from code review

Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>

* change contraction idea

* typo in docs

* tests

* remove prints

* fix test

* test descriptions

* fix merge

* format

* code review; test coverage

* coverage reordering

* fix

* trigger CI

* trigger

* clear caches

* trigger

* trigger

---------

Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>
Co-authored-by: Korbinian Kottmann <Korbinian.Kottmann@gmail.com>

* Fix batching of derivative tapes in autograd (#4245)

* Fix `expval` of `Sum` with broadcasting (#4275)

* fix bug and add test

* changelog addition

* Various doc fixes (#4268)

* Various things while validating changes for 0.31 (#4279)

* change link in setup.py

* fix qchem docs

* fix qcut docs

* rename string function (#4278)

* Update docs (#4269)

* Incrementing the version number to `v0.32.0-dev` (#4266)

* pre-release for v0.31.0

* Update doc/releases/changelog-0.31.0.md

* Incrementing the version number to v0.32.0-dev

* Update installation.rst (#4247)

Update Python version to 3.8

Co-authored-by: Romain Moyard <rmoyard@gmail.com>

* docs typos

* don't include updating versioning from master

* don't include python requirements from master

* update example output for shot_vector

* Update pennylane/operation.py

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* fix entirely unrelated rendering issue

---------

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
Co-authored-by: Catalina Albornoz <albornoz.catalina@hotmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>

* Minor fixes for v0.31 (#4280)

* Added fixes

* Update pennylane/ops/qubit/matrix_ops.py

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* Update pennylane/ops/qubit/matrix_ops.py

---------

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* add graphviz to RTD apt packages (#4284)

* Pulse gradient methods docs polish (#4282)

* stoch pulse docs update

* generator method docs update

* small fixes / typos

* Update pennylane/gradients/pulse_generator_gradient.py

Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>

* Update pennylane/gradients/pulse_generator_gradient.py

Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>

* Update pennylane/gradients/pulse_generator_gradient.py

Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>

* code review

* Update pennylane/gradients/pulse_gradient.py

Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>

* code review

* Update pennylane/gradients/pulse_generator_gradient.py

Co-authored-by: Frederik Wilde <42576579+frederikwilde@users.noreply.github.com>

* large |

* add equal to

---------

Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>
Co-authored-by: Frederik Wilde <42576579+frederikwilde@users.noreply.github.com>

* 0.31 release notes (#4218)

* Add categories

* First pass at categorization

* More categorization

* More categorization

* Typo

* Add first half of resource estimation text

* Improvements

* Add custom ops resource estimation

* Update wording

* Improve entry

* Move

* Move

* Move

* Update

* Add details about Torch and Keras

* Add entry

* Add contributor

* Add to Keras and Torch layer section

* Add saving and loading details

* Add entry

* Add contributor

* Add contributor

* Add qutrit basis state example

* first round of edits

* Remove

* Add entry for one_qubit_decompostition

* more changes

* Reorder sections

* fermi blurb

* minor

* Update

* Add

* Update doc/releases/changelog-dev.md

Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>

* Update doc/releases/changelog-dev.md

Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>

* update fermionic code examples

* additions

* minor

* restructure sections

* minor

* minor

* reorder fermi section

* fixed fermi section

* various small changes

* Tweaks to fermionic

* Tweaks to resource and UH sections

* Improvements

* Move

* Update doc/releases/changelog-0.31.0.md

* minior

* minor

* minor

* minor

* minor

* Update

* minor

* use from_string for fermi ops

* Add link

* Update doc/releases/changelog-0.31.0.md

* added links and other minor things

* Update doc/releases/changelog-0.31.0.md

* Update doc/releases/changelog-0.31.0.md

* minor

* minor

* deleted extraneous notebook

* Apply suggestions from code review

Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>

---------

Co-authored-by: Isaac De Vlugt <isaacdevlugt@gmail.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: soranjh <soranjh@yahoo.com>

* Allow updating dense kwarg in call of ParametrizedEvolution (#4285)

* add dense kwarg to call

* update changelog

* update changelog better

* changelog formatting

---------

Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>

* Remove line in code example to make docs render properly. (#4290)

* Pin autograd to <= 1.5 (#4289)

* pin autograd to 1.5 or less

* allow autograd 1.4 as well

* pin for doc build as well

* Add dm_from_state_vector function to qml.math docs page. (#4291)

* Fix `ShotAdaptiveOptimizer` to prevent removing shot vector axes (#4240)

* Updated `ShotAdaptiveOpt` per suggestion in issue

* Reformatting

* Testing changes

* Fixed bug

* Updated min to max

* Allow classical shadow measurements in new device (#4162)

* Support classical shadow measurements

* Add shot vector tests

* Address comments

* Add comment for diag_list

* Apply suggestions from code review

Co-authored-by: Christina Lee <christina@xanadu.ai>

* Fix

* Add unit tests for process_state_with_shots

* Update preprocessing

* Apply suggestions from code review

Co-authored-by: Frederik Wilde <42576579+frederikwilde@users.noreply.github.com>

* Address PR comments

* set rng for test

---------

Co-authored-by: Christina Lee <christina@xanadu.ai>
Co-authored-by: Frederik Wilde <42576579+frederikwilde@users.noreply.github.com>

* Add the `fermi` module docs (#4250)

* support trainable Sum observables (#4251)

* support trainable Sum observables (analytic only)

* just use pre-rotated state; use super with finite shots

* fix tests; add test for trainable Sum coeffs

* changelog

* use overlapping wires to prove they work

* add hacky gradient support

* Revert "add hacky gradient support"

This reverts commit 09009c8.

* set interface=None to keep test behaviour

* Integrate experimental device with the `QNode` (#4196)

* integrate qnode with new device

* some diff method improvements

* repr methods

* add tests, always pass config to device

* add tests, always pass config to device

* final test

* pylint

* autograd integration tests

* pylint

* Update pennylane/interfaces/execution.py

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* pass shots through methods

* changelog

* revert set shots change

* Apply suggestions from code review

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* revert executionc hange, pylint:

* pylint again

---------

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>

* pre-release for v0.31.0 (#4265)

* pre-release for v0.31.0

* Update doc/releases/changelog-0.31.0.md

* Support `HardwareHamiltonian` pulses in `stoch_pulse_grad` (#4215)

* single out gradient transform checks

* rename stochastic pulse gradient file

* unify gradient_analysis and grad_method_validation

* continue restructure of analysis+validation

* CV

* black

* modularize more

* more modularizing

* black

* tiny [skip ci]

* [skip ci] lint

* remove dummy test

* test fix

* add test file to linting test file

* test fixes, docstrings

* code review

* docstring gradient_analysis_and_grad_method_validation

* move first fun

* code review:move functions

* test regex

* regexs

* move and promote reorder_grads

* tmp

* more tmp

* test cases, contractions

* lint

* docstring

* even more tmp

* cleanup

* black

* tmp

* lint

* move stoch_pulse_gradient.. files back to pulse_gradient...

* move stoch_pulse_gradient.. files back to pulse_gradient...

* lint

* rename

* extend functions and tests

* lint and black

* changelog

* improve

* update example to include non-Pauli word generator

* add jit test with pauli sentence

* tmp

* debugging, docstring, extend test

* review

* optimize for Pauli words

* Apply suggestions from code review

Co-authored-by: Romain Moyard <rmoyard@gmail.com>

* test cases code review

* fix parametrization

* drafting

* working prototype

* finish merge; cleanup

* changelog

* comments

* [skip ci]

* raising an error; cleanup [skip ci]

* Apply suggestions from code review

Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>

* change contraction idea

* typo in docs

* tests

* remove prints

* fix test

* test descriptions

* fix merge

* format

* code review; test coverage

* coverage reordering

* fix

* trigger CI

* trigger

* clear caches

* trigger

* trigger

---------

Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>
Co-authored-by: Korbinian Kottmann <Korbinian.Kottmann@gmail.com>

* Fix batching of derivative tapes in autograd (#4245)

* Fix `expval` of `Sum` with broadcasting (#4275)

* fix bug and add test

* changelog addition

* Various doc fixes (#4268)

* Various things while validating changes for 0.31 (#4279)

* change link in setup.py

* fix qchem docs

* fix qcut docs

* rename string function (#4278)

* Update docs (#4269)

* Incrementing the version number to `v0.32.0-dev` (#4266)

* pre-release for v0.31.0

* Update doc/releases/changelog-0.31.0.md

* Incrementing the version number to v0.32.0-dev

* Update installation.rst (#4247)

Update Python version to 3.8

Co-authored-by: Romain Moyard <rmoyard@gmail.com>

* docs typos

* don't include updating versioning from master

* don't include python requirements from master

* update example output for shot_vector

* Update pennylane/operation.py

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* fix entirely unrelated rendering issue

---------

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
Co-authored-by: Catalina Albornoz <albornoz.catalina@hotmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>

* Minor fixes for v0.31 (#4280)

* Added fixes

* Update pennylane/ops/qubit/matrix_ops.py

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* Update pennylane/ops/qubit/matrix_ops.py

---------

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* add graphviz to RTD apt packages (#4284)

* Updated test

---------

Co-authored-by: Edward Jiang <34989448+eddddddy@users.noreply.github.com>
Co-authored-by: Christina Lee <christina@xanadu.ai>
Co-authored-by: Frederik Wilde <42576579+frederikwilde@users.noreply.github.com>
Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>
Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>
Co-authored-by: Korbinian Kottmann <Korbinian.Kottmann@gmail.com>
Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>
Co-authored-by: Catalina Albornoz <albornoz.catalina@hotmail.com>

* Make links to qml.eigvals and the eigvals method appear distinctly. (#4292)

* Make links to qml.eigvals and the eigvals method appear distinctly in the docstring of compute_method.

* Make links more informative.

---------

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* Device API review (#4283)

* fix  example

* minor docstring change in `_zyz_decomposition`

* update decomposition examples

* update counts & samples docstrings

* Shots class link

* Fix code block

* Change note

Co-authored-by: Edward Jiang <34989448+eddddddy@users.noreply.github.com>

---------

Co-authored-by: Edward Jiang <34989448+eddddddy@users.noreply.github.com>

* remove duplicate controlled operation entries (#4298)

* Refer to class QNode in ml layers (#4299)

* Specs dict fix (#4286)

* Add copy function to SpecsDict.

* black

* Adjust docs to not throw warnings from deprecated specs keys.

* Formatting fix.

* update doc string

* update doc string

---------

Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>
Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* Fermionic ops in changelog (#4302)

* bump lightning to 0.31 in setup.py, pin scipy to [1.8,1.10] (#4304)

* bump lightning to 0.31 in setup.py

* trigger ci

* pin scipy

* Revert "pin scipy"

This reverts commit 492ad40.

* take Soran's forward fix for scipy fac2

* revert the scipy un-pinning and forward fix - just pin scipy

* remove lower bound in files that didn't have them

* remove autograd lower bound

---------

Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>
Co-authored-by: Korbinian Kottmann <Korbinian.Kottmann@gmail.com>
Co-authored-by: Christina Lee <christina@xanadu.ai>
Co-authored-by: Edward Jiang <34989448+eddddddy@users.noreply.github.com>
Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>
Co-authored-by: Catalina Albornoz <albornoz.catalina@hotmail.com>
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Co-authored-by: Frederik Wilde <42576579+frederikwilde@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <isaacdevlugt@gmail.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: soranjh <soranjh@yahoo.com>
Co-authored-by: BorjaRequena <59647767+BorjaRequena@users.noreply.github.com>
Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>
  • Loading branch information
18 people authored Jun 26, 2023
1 parent d6955cf commit ee47491
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 68 deletions.
2 changes: 1 addition & 1 deletion doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Completed deprecation cycles
- Deprecated in v0.29
- Removed in v0.31

* ``qml.op_sum``` has been removed. Users should use ``qml.sum`` instead.
* ``qml.op_sum`` has been removed. Users should use ``qml.sum`` instead.

- Deprecated in v0.29.
- Removed in v0.31.
Expand Down
6 changes: 3 additions & 3 deletions doc/releases/changelog-0.31.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@
```pycon
>>> word1 = qml.fermi.from_string('0+ 0- 3+ 3-')
>>> word2 = qml.fermi.from_string('3+ 3-')
>>> sentence = 1.2 * word1 - 0.345 * word2
>>> sentence = 1.2 * word1 + 0.345 * word2
>>> sentence
1.2 * a⁺(0) a(0) a⁺(3) a(3)
- 0.345 * a⁺(3) a(3)
+ 0.345 * a⁺(3) a(3)
```

Additionally, any fermionic operator, be it a single fermionic creation/annihilation operator, a Fermi word, or a Fermi sentence,
can be mapped to the qubit basis by using [qml.jordan_wigner](https://docs.pennylane.ai/en/stable/code/api/pennylane.jordan_wigner.html):

```pycon
>>> qml.jordan_wigner(sentence)
((0.1275+0j)*(Identity(wires=[0]))) + ((-0.1275+0j)*(PauliZ(wires=[3]))) + ((-0.3+0j)*(PauliZ(wires=[0]))) + ((0.3+0j)*(PauliZ(wires=[0]) @ PauliZ(wires=[3])))
((0.4725+0j)*(Identity(wires=[0]))) + ((-0.4725+0j)*(PauliZ(wires=[3]))) + ((-0.3+0j)*(PauliZ(wires=[0]))) + ((0.3+0j)*(PauliZ(wires=[0]) @ PauliZ(wires=[3])))
```

Learn how to create fermionic Hamiltonians describing some simple chemical systems by checking
Expand Down
4 changes: 2 additions & 2 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--find-links https://download.pytorch.org/whl/torch_stable.html
pip
appdirs
autograd>=1.4,<=1.5
autograd<=1.5
autoray
jax==0.4.10
jaxlib==0.4.10
Expand All @@ -10,7 +10,7 @@ m2r2
numpy
pygments-github-lexers
semantic_version==2.10
scipy
scipy<=1.10
docutils==0.16
sphinx==3.5; python_version < "3.10"
sphinx==4.2; python_version == "3.10"
Expand Down
4 changes: 2 additions & 2 deletions pennylane/_qubit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ def classical_shadow(self, obs, circuit):
tapes containing randomized Pauli observables. Devices should override this
if they can offer cleaner or faster implementations.
.. seealso:: :func:`~pennylane.classical_shadow`
.. seealso:: :func:`~.pennylane.classical_shadow`
Args:
obs (~.pennylane.measurements.ClassicalShadowMP): The classical shadow measurement process
Expand Down Expand Up @@ -1441,7 +1441,7 @@ def analytic_probability(self, wires=None):
.. note::
:meth:`marginal_prob` may be used as a utility method
:meth:`~.marginal_prob` may be used as a utility method
to calculate the marginal probability distribution.
Args:
Expand Down
6 changes: 3 additions & 3 deletions pennylane/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def snapshots(qnode):
Returns:
A function that has the same argument signature as ``qnode`` and returns a dictionary.
When called, the function will execute the QNode on the registered device and retrieve
the saved snapshots obtained via the ``qml.Snapshot`` operation. Additionally, the snapshot
dictionary always contains the execution results of the QNode, so the use of the tag
"execution_results" should be avoided to prevent conflicting key names.
the saved snapshots obtained via the :class:`~.pennylane.Snapshot` operation. Additionally,
the snapshot dictionary always contains the execution results of the QNode, so the use of
the tag "execution_results" should be avoided to prevent conflicting key names.
**Example**
Expand Down
10 changes: 6 additions & 4 deletions pennylane/devices/experimental/default_qubit_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class DefaultQubit2(Device):
qscripts.append(qs)
>>> dev = DefaultQubit2()
>>> new_batch, post_processing_fn = dev.preprocess(qscripts)
>>> results = dev.execute(new_batch)
>>> new_batch, post_processing_fn, execution_config = dev.preprocess(qscripts)
>>> results = dev.execute(new_batch, execution_config=execution_config)
>>> post_processing_fn(results)
[-0.0006888975950537501,
0.025576307134457577,
Expand All @@ -80,11 +80,13 @@ class DefaultQubit2(Device):
.. code-block:: python
import jax
@jax.jit
def f(x):
qs = qml.tape.QuantumScript([qml.RX(x, 0)], [qml.expval(qml.PauliZ(0))])
new_batch, post_processing_fn = dev.preprocess(qs)
results = dev.execute(new_batch)
new_batch, post_processing_fn, execution_config = dev.preprocess(qs)
results = dev.execute(new_batch, execution_config=execution_config)
return post_processing_fn(results)
>>> f(jax.numpy.array(1.2))
Expand Down
14 changes: 6 additions & 8 deletions pennylane/measurements/counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def counts(op=None, wires=None, all_outcomes=False) -> "CountsMP":
:math:`p(\lambda_i) = |\langle \xi_i | \psi \rangle|^2`, where :math:`| \xi_i \rangle`
is the corresponding basis state from the observable's eigenbasis.
.. note::
Differentiation of QNodes that return ``counts`` is currently not supported. Please refer to
:func:`~.pennylane.sample` if differentiability is required.
**Example**
.. code-block:: python3
Expand Down Expand Up @@ -116,7 +121,7 @@ def circuit():
.. code-block:: python3
@qml.qnode(dev)
def circuit(x):
def circuit():
qml.PauliX(wires=0)
return qml.counts(all_outcomes=True)
Expand All @@ -125,13 +130,6 @@ def circuit(x):
>>> circuit()
{'00': 0, '01': 0, '10': 4, '11': 0}
.. note::
QNodes that return samples cannot, in general, be differentiated, since the derivative
with respect to a sample --- a stochastic process --- is ill-defined. The one exception
is if the QNode uses the parameter-shift method (``diff_method="parameter-shift"``), in
which case ``qml.sample(obs)`` is interpreted as a single-shot expectation value of the
observable ``obs``.
"""
if op is not None and not op.is_hermitian: # None type is also allowed for op
warnings.warn(f"{op.name} might not be hermitian.")
Expand Down
15 changes: 8 additions & 7 deletions pennylane/measurements/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def sample(op: Optional[Operator] = None, wires=None) -> "SampleMP":
:math:`p(\lambda_i) = |\langle \xi_i | \psi \rangle|^2`, where :math:`| \xi_i \rangle`
is the corresponding basis state from the observable's eigenbasis.
.. note::
QNodes that return samples cannot, in general, be differentiated, since the derivative
with respect to a sample --- a stochastic process --- is ill-defined. The one exception
is if the QNode uses the parameter-shift method (``diff_method="parameter-shift"``), in
which case ``qml.sample(obs)`` is interpreted as a single-shot expectation value of the
observable ``obs``.
**Example**
.. code-block:: python3
Expand Down Expand Up @@ -92,13 +100,6 @@ def circuit(x):
[1, 1],
[0, 0]])
.. note::
QNodes that return samples cannot, in general, be differentiated, since the derivative
with respect to a sample --- a stochastic process --- is ill-defined. The one exception
is if the QNode uses the parameter-shift method (``diff_method="parameter-shift"``), in
which case ``qml.sample(obs)`` is interpreted as a single-shot expectation value of the
observable ``obs``.
"""
if op is not None and not op.is_hermitian: # None type is also allowed for op
warnings.warn(f"{op.name} might not be hermitian.")
Expand Down
2 changes: 1 addition & 1 deletion pennylane/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def compute_eigvals(*params, **hyperparams):
Otherwise, no particular order for the eigenvalues is guaranteed.
.. seealso:: :meth:`~.Operator.eigvals` and :func:`~.eigvals`
.. seealso:: :meth:`Operator.eigvals() <.eigvals>` and :func:`qml.eigvals() <pennylane.eigvals>`
Args:
*params (list): trainable parameters of the operator, as stored in the ``parameters`` attribute
Expand Down
2 changes: 2 additions & 0 deletions pennylane/ops/op_math/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
Controlled Operator Classes
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. currentmodule:: pennylane
.. autosummary::
:toctree: api
Expand Down
2 changes: 1 addition & 1 deletion pennylane/qnn/keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


class KerasLayer(Layer):
"""Converts a :func:`~.QNode` to a Keras
"""Converts a :class:`~.QNode` to a Keras
`Layer <https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer>`__.
The result can be used within the Keras
Expand Down
2 changes: 1 addition & 1 deletion pennylane/qnn/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


class TorchLayer(Module):
r"""Converts a :func:`~.QNode` to a Torch layer.
r"""Converts a :class:`~.QNode` to a Torch layer.
The result can be used within the ``torch.nn``
`Sequential <https://pytorch.org/docs/stable/nn.html#sequential>`__ or
Expand Down
4 changes: 4 additions & 0 deletions pennylane/tape/qscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,10 @@ def __getitem__(self, item):
)
return super().__getitem__(item)

def copy(self):
"""Custom copy function to return a SpecsDict instead of a dict."""
return SpecsDict(self.items())


def make_qscript(fn, shots: Optional[Union[int, Sequence, Shots]] = None):
"""Returns a function that generates a qscript from a quantum function without any
Expand Down
42 changes: 21 additions & 21 deletions pennylane/transforms/decompositions/single_qubit_unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ def _zyz_decomposition(U, wire, return_global_phase=False):
>>> U = np.array([[-0.28829348-0.78829734j, 0.30364367+0.45085995j],
... [ 0.53396245-0.10177564j, 0.76279558-0.35024096j]])
>>> decomp = zyz_decomposition(U, 0, return_global_phase=True)
>>> decomp = _zyz_decomposition(U, 0, return_global_phase=True)
>>> decomp
[RZ(tensor(-0.2420953, requires_grad=True), wires=[0]),
RY(tensor(1.14938178, requires_grad=True), wires=[0]),
RZ(tensor(1.73305815, requires_grad=True), wires=[0]),
(0.38469215914523336-0.9230449299422961j)*(Identity(wires=[0]))]
[RZ(12.32427531154459, wires=[0]),
RY(1.1493817771511352, wires=[0]),
RZ(1.733058145303424, wires=[0]),
(0.38469215914523336-0.9230449299422961j)*(Identity(wires=[0]))]
"""

# Cast to batched format for more consistent code
Expand Down Expand Up @@ -269,10 +269,10 @@ def xyx_decomposition(U, wire, return_global_phase=False):
... [ 0.53396245-0.10177564j, 0.76279558-0.35024096j]])
>>> decomp = xyx_decomposition(U, 0, return_global_phase=True)
>>> decomp
[RX(tensor(-1.72101925, requires_grad=True), wires=[0]),
RY(tensor(1.39749741, requires_grad=True), wires=[0]),
RX(tensor(0.45246584, requires_grad=True), wires=[0]),
(0.38469215914523336-0.9230449299422961j)*(Identity(wires=[0]))]
[RX(10.845351366405708, wires=[0]),
RY(1.3974974118006174, wires=[0]),
RX(0.45246583660683803, wires=[0]),
(0.38469215914523336-0.9230449299422961j)*(Identity(wires=[0]))]
"""
warnings.warn(
"The xyx_decomposition function is deprecated and will be removed soon. Use :func:`one_qubit_decomposition` "
Expand Down Expand Up @@ -303,12 +303,12 @@ def _xyx_decomposition(U, wire, return_global_phase=False):
>>> U = np.array([[-0.28829348-0.78829734j, 0.30364367+0.45085995j],
... [ 0.53396245-0.10177564j, 0.76279558-0.35024096j]])
>>> decomp = xyx_decomposition(U, 0, return_global_phase=True)
>>> decomp = _xyx_decomposition(U, 0, return_global_phase=True)
>>> decomp
[RX(array(0.45246584), wires=[0]),
RY(array(1.39749741), wires=[0]),
RX(array(-1.72101925), wires=[0]),
(0.38469215914523336-0.9230449299422961j)*(Identity(wires=[0]))]
[RX(10.845351366405708, wires=[0]),
RY(1.3974974118006174, wires=[0]),
RX(0.45246583660683803, wires=[0]),
(0.38469215914523336-0.9230449299422961j)*(Identity(wires=[0]))]
"""

# Small number to add to denominators to avoid division by zero
Expand Down Expand Up @@ -368,11 +368,11 @@ def _zxz_decomposition(U, wire, return_global_phase=False):
>>> U = np.array([[-0.28829348-0.78829734j, 0.30364367+0.45085995j],
... [ 0.53396245-0.10177564j, 0.76279558-0.35024096j]])
>>> decomp = zxz_decomposition(U, 0, return_global_phase=True)
>>> decomp = _zxz_decomposition(U, 0, return_global_phase=True)
>>> decomp
[RZ(tensor(-1.81289163, requires_grad=True), wires=[0]),
RX(tensor(1.14938178, requires_grad=True), wires=[0]),
RZ(tensor(-2.97933083, requires_grad=True), wires=[0]),
[RZ(10.753478981934784, wires=[0]),
RX(1.1493817777940705, wires=[0]),
RZ(3.3038544749132295, wires=[0]),
(0.38469215914523336-0.9230449299422961j)*(Identity(wires=[0]))]
"""

Expand Down Expand Up @@ -440,9 +440,9 @@ def one_qubit_decomposition(U, wire, rotations="ZYZ", return_global_phase=False)
... [ 0.53396245-0.10177564j, 0.76279558-0.35024096j]])
>>> decomp = one_qubit_decomposition(U, 0, "ZXZ", return_global_phase=True)
>>> decomp
[RZ(tensor(-1.81289163, requires_grad=True), wires=[0]),
RX(tensor(1.14938178, requires_grad=True), wires=[0]),
RZ(tensor(-2.97933083, requires_grad=True), wires=[0]),
[RZ(10.753478981934784, wires=[0]),
RX(1.1493817777940705, wires=[0]),
RZ(3.3038544749132295, wires=[0]),
(0.38469215914523336-0.9230449299422961j)*(Identity(wires=[0]))]
"""
supported_rotations = {
Expand Down
4 changes: 2 additions & 2 deletions pennylane/transforms/optimization/pattern_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ def circuit():
In our case, it is possible to find three CNOTs and replace this pattern with only two CNOTs and therefore
optimizing the circuit. The number of CNOTs in the circuit is reduced by one.
>>> qml.specs(qnode)()["gate_types"]["CNOT"]
>>> qml.specs(qnode)()["resources"].gate_types["CNOT"]
4
>>> qml.specs(optimized_qnode)()["gate_types"]["CNOT"]
>>> qml.specs(optimized_qnode)()["resources"].gate_types["CNOT"]
3
>>> print(qml.draw(qnode)())
Expand Down
19 changes: 11 additions & 8 deletions pennylane/transforms/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,23 @@ def specs_qnode(*args, **kwargs):
"""Returns information on the structure and makeup of provided QNode.
Dictionary keys:
* ``"num_operations"``
* ``"num_observables"``
* ``"num_diagonalizing_gates"``
* ``"gate_sizes"``: dictionary mapping gate number of wires to number of occurances
* ``"gate_types"``: dictionary mapping gate types to number of occurances
* ``"num_operations"`` number of operations in the qnode
* ``"num_observables"`` number of observables in the qnode
* ``"num_diagonalizing_gates"`` number of diagonalizing gates required for execution of the qnode
* ``"resources"``: a :class:`~.resource.Resources` object containing resource quantities used by the qnode
* ``"num_used_wires"``: number of wires used by the circuit
* ``"num_device_wires"``: number of wires in device
* ``"depth"``: longest path in directed acyclic graph representation
* ``"dev_short_name"``: name of QNode device
* ``"diff_method"``
* ``"device_name"``: name of QNode device
* ``"expansion_strategy"``: string specifying method for decomposing operations in the circuit
* ``"gradient_options"``: additional configurations for gradient computations
* ``"interface"``: autodiff framework to dispatch to for the qnode execution
* ``"diff_method"``: a string specifying the differntiation method
* ``"gradient_fn"``: executable to compute the gradient of the qnode
Potential Additional Information:
* ``"num_trainable_params"``: number of individual scalars that are trainable
* ``"num_parameter_shift_executions"``: number of times circuit will execute when
* ``"num_gradient_executions"``: number of times circuit will execute when
calculating the derivative
Returns:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
numpy<1.24
scipy~=1.8
scipy>=1.8,<=1.10
cvxpy~=1.2
cvxopt~=1.3.0
cachetools~=5.0.0
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

requirements = [
"numpy<1.24",
"scipy",
"scipy<=1.10",
"networkx",
"rustworkx",
"autograd>=1.4,<=1.5",
"autograd<=1.5",
"toml",
"appdirs",
"semantic-version>=2.7",
"autoray>=0.3.1",
"cachetools",
"pennylane-lightning>=0.30",
"pennylane-lightning>=0.31",
"requests",
]

Expand Down
10 changes: 10 additions & 0 deletions tests/tape/test_qscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,16 @@ def test_specs_tape(self, make_script):
assert specs["num_trainable_params"] == 5
assert specs["depth"] == 3

def test_specs_copy(self, make_script):
"""Test that the copy method of specs retuns a SpecsDict."""
qs = make_script
copied_specs = qs.specs.copy()

assert isinstance(copied_specs, qml.tape.qscript.SpecsDict)
with pytest.warns(UserWarning, match="key is deprecated and will be removed"):
for k, v in qs.specs.items():
assert copied_specs[k] == v

@pytest.mark.parametrize(
"shots, total_shots, shot_vector",
[
Expand Down

0 comments on commit ee47491

Please sign in to comment.