Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating collections and VQECost to work in tape mode #863

Merged
merged 21 commits into from
Oct 23, 2020

Conversation

josh146
Copy link
Member

@josh146 josh146 commented Oct 21, 2020

Context: Ensures that the QNode collection tests pass in tape mode, ensuring collection features can be used in tape mode.

Description of changes:

  • Minor modification of qml.map to allow it to work in tape mode

  • The tape mode measurement functions are now mocked globally when qml.enable_tape() is called. Previously, they were only mocked within a tape context. However, qml.map() requires the correct measurement function to be known outside of a tape context.

  • An edge case was discovered; the queuing refactor did not take into account observables created outside of a queuing context! A small modification was made to MeasurementProcess.queue() to allow it to work with previously instantiated observables.

  • A bug was discovered in the parameter-shift rule. One of the copied tapes was not having its parameters 'unwrapped', causing tensors/ArrayBoxes to be accidentally passed to devices.

  • interface="numpy" has been deprecated in favour of interface="autograd", so has been removed from the collection tests.

  • Several attributes and methods on the old QNode have a new location on the new QNode/tape. We dynamically mock the new QNode to also have the same attributes and methods within the tape_mode fixture, so that the tests do not have to be modified to support both tape and non-tape mode.

    This also acts as a running list of changes we will need to make to the tests once tape mode is the default.

Benefits:

  • Collections now work in tape mode

  • This should make it easier to support our VQE workflow in tape mode.

  • Several bugs and edge cases were found.

Drawbacks:

  • The final test in test_qnode_collection.py, test_grad_tf, will fail stochastically due to a race condition when using dask with the new queuing refactor. The test constructs and evaluates two QNodes in parallel; the following two cases can happen:

    • The first QNode has both operations and measurements from the two tapes, while the second QNode is correct. The test will fail, since QNode 1 has 4 measurements and QNode 2 has 2 measurements, and the result cannot be stacked.

    • Both QNodes are constructed correctly - test passes

    Both cases seem to occur 50% of the time. I am unsure (a) how to fix this in the queuing.py file, and (b) why it only seems to happen in the TF interface. Both Autograd and Torch appear unaffected.

Comment on lines +77 to +80
mock.patch("pennylane.expval", measure.expval),
mock.patch("pennylane.var", measure.var),
mock.patch("pennylane.probs", measure.probs),
mock.patch("pennylane.sample", measure.sample),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure that the measurement functions are changed globally, not just within tape contexts, when qml.enable_tape() is called.

Comment on lines +175 to +176
self.obs.queue()
qml.tape.QueuingContext.update_info(self.obs, owner=self)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An edge case discovered when attempting to get the qml.map() tests to pass. The new queuing refactor did not take into account observables created outside of a queuing context!

This allows previously instantiated observables to be used within a QNode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the update_info fails above because obs is not in queue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Exactly. It might be a flaw in the queuing refactor design; the queuing refactor explicitly assumes that all nested objects exist in the queue prior to other objects annotating the queue.

@@ -464,6 +464,7 @@ def parameter_shift_var(self, idx, params, **options):

# Get <A>, the expectation value of the tape with unshifted parameters.
evA_tape = self.copy()
evA_tape.set_parameters(params)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bug discovered in the parameter shift rule.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a problem anywhere else?

Copy link
Member Author

@josh146 josh146 Oct 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a the moment (I went through the existing gradient logic looking).

The reason why it needs to be added:

  • The params that have been passed to the gradient methods have been unwrapped to NumPy arrays by the interface

  • However, the tape itself is unmodified and still contains tensors internally.

  • This tape will soon be executed by device.batch_execute, which does not have an interface.

So when we copy the tape, we need to make sure that all internal parameters get replaced with the unwrapped versions, since we are inside the interface.

@@ -38,6 +38,9 @@
Variable = None


pytestmark = pytest.mark.usefixtures("tape_mode")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forces all functions in this test file to be run in both tape and tape mode

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what setting the variable pytestmark does? It looks so strange...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure, I imagine pytest does some weird introspection, and looks for this module variable? If it exists, it applies the mark to all objects in the file. I just learnt to do it from the pytest docs 😆

@@ -190,7 +193,7 @@ def test_passing_kwargs(self):
class TestApply:
"""Tests for the apply function"""

@pytest.mark.parametrize("interface", ["autograd", "numpy", "torch", "tf"])
@pytest.mark.parametrize("interface", ["autograd", "torch", "tf"])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"numpy" has been deprecated in tape mode, so we remove it from the tests

@codecov
Copy link

codecov bot commented Oct 21, 2020

Codecov Report

Merging #863 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #863   +/-   ##
=======================================
  Coverage   97.83%   97.83%           
=======================================
  Files         137      137           
  Lines        9373     9383   +10     
=======================================
+ Hits         9170     9180   +10     
  Misses        203      203           
Impacted Files Coverage Δ
pennylane/collections/qnode_collection.py 100.00% <ø> (ø)
pennylane/__init__.py 98.82% <100.00%> (ø)
pennylane/collections/map.py 100.00% <100.00%> (ø)
pennylane/tape/__init__.py 100.00% <100.00%> (ø)
pennylane/tape/measure.py 97.29% <100.00%> (+0.15%) ⬆️
pennylane/tape/tapes/cv_param_shift.py 99.34% <100.00%> (+<0.01%) ⬆️
pennylane/tape/tapes/qubit_param_shift.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0852056...8a7b666. Read the comment docs.

@josh146 josh146 changed the title [WIP] Updating collections to work in tape mode Updating collections to work in tape mode Oct 21, 2020
@josh146 josh146 changed the title Updating collections to work in tape mode Updating collections and VQECost to work in tape mode Oct 21, 2020
@@ -487,6 +487,7 @@ def test_arithmetic_errors(self):
H -= A


@pytest.mark.usefixtures("tape_mode")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After fixing qml.map, VQECost tests pass with minor test modification, and no source code changes 😄

Comment on lines +171 to +174
mocker.patch("pennylane.tape.QNode.ops", property(lambda self: self.qtape.operations + self.qtape.observables), create=True)
mocker.patch("pennylane.tape.QNode.h", property(lambda self: self.diff_options["h"]), create=True)
mocker.patch("pennylane.tape.QNode.order", property(lambda self: self.diff_options["order"]), create=True)
mocker.patch("pennylane.tape.QNode.jacobian", lambda self: self.qtape.jacobian, create=True)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several attributes and methods on the old QNode have a new location on the new QNode/tape. Here, we dynamically mock so that the tests do not have to be modified to support both tape and non-tape mode.

This also acts as a running list of changes we will need to make to the tests once tape mode is the default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever!

@josh146 josh146 added the review-ready 👌 PRs which are ready for review by someone from the core team. label Oct 22, 2020
raise ImportError(
"Dask must be installed for parallel evaluation. "
"\nDask can be installed using pip:"
"\n\npip install dask[delayed]"
)
) from e
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pylint was complaining

Comment on lines 108 to 110
def tape_mode_active():
"""Returns whether tape mode is enabled."""
return bool(_mock_stack)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful for tests and core components.

@mariaschuld
Copy link
Contributor

@josh146 , amazing what little subtleties you uncovered. And I cannot wait until we don't need the limbo of supporting two cores any more.

Did I see right that you did not need to change much in the collections themselves?

Do you want to merge this in, or try to solve the outstanding issue first?

@josh146
Copy link
Member Author

josh146 commented Oct 22, 2020

Did I see right that you did not need to change much in the collections themselves?

Yep, the changes in the codebase were very minimal! It was mostly fixing the test fixtures etc. Which is great.

Do you want to merge this in, or try to solve the outstanding issue first?

The race condition? That will take a while to solve (and probably require major changes to queuing), so better to leave it for a second PR?

Copy link
Contributor

@mariaschuld mariaschuld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, after CodeFactor issues fixed...

@josh146 josh146 merged commit 758c9ad into master Oct 23, 2020
@josh146 josh146 deleted the tape-mode-collections branch October 23, 2020 08:50
alejomonbar pushed a commit to alejomonbar/pennylane that referenced this pull request Dec 1, 2020
* backup

* add fixture

* polish

* polish2

* Update tests/templates/test_integration.py

* [WIP] Updating collections to work in tape mode

* more

* black and linting

* skip test with race condition

* Add VQECost support

* add more tests

* update changelog

* Update pennylane/collections/map.py

* Update pennylane/tape/__init__.py

* suggested changes

* suggested changes

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
antalszava added a commit that referenced this pull request Dec 9, 2020
* Test for comparing different devices with the default device

* Update test_compare_default_qubit.py with the suggestions of Pennylane team

* Test for comparing different devices with the default device

* Update test_compare_default_qubit.py with the suggestions of Pennylane team

* Enable tape mode in tests (#859)

* backup

* add fixture

* polish

* polish2

* Update tests/templates/test_integration.py

* add execution property to Device class for tracking the number of device executions over a QNodes lifetime (#853)

* add execution property to Device class for tracking the number of device executions over a QNodes lifetime, add unit tests for tracking device executions

* reformat files with black, update execution to num_executions, reformat existing exceptions, update num_executions docstring

* Fix typo in test_device_executions docstring

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* move _num_executions counter to execute() method for _device and _qubit_device, move corresponding unit tests to appropriate locations

* update CHANGELOG.md to include num_executions

* Add Anthony Hayes to list of contributers in CHANGEOG.md

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>

* Adds handling of single-qubit Paulis and all-identity Pauli to PauliRot operation.  (#860)

* Fix PauliRot to work for single-qubit case with int-specified wire.

* Fix matrix construction for all-identity Pauli.

* Ensure PauliRot decomposition handles all-identity case.

* Adds tests for single-qubit PauliRot matrix, and identity decomp.

* Updated changelog.

* Removed single-qubit matrix test since this was not the original single-qubit issue.

* Added PR link to changelog.

* Run black formatting.

* Run black through command line.

* Update .github/CHANGELOG.md

Co-authored-by: antalszava <antalszava@gmail.com>

* Reverted stuff that was reformatted by emacs black.

* Fixes decomposition to also handle integer wires.

* Update codecov.yml

* Fixed eigvals to work for all-identity case, and updated tests.

Co-authored-by: Olivia Di Matteo <dimatteo.olivia@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>

* Updating collections and VQECost to work in tape mode (#863)

* backup

* add fixture

* polish

* polish2

* Update tests/templates/test_integration.py

* [WIP] Updating collections to work in tape mode

* more

* black and linting

* skip test with race condition

* Add VQECost support

* add more tests

* update changelog

* Update pennylane/collections/map.py

* Update pennylane/tape/__init__.py

* suggested changes

* suggested changes

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>

* Build many-body observables in PL-QChem using FermionOperator data structure (#854)

* Modify the 'observable' function to build PL observables from a list of FermionOperators

* Modify unit tests for the 'observable' function

* Modify functions 'one_particle' and 'two_particle' to build FermionOperators

* Modify unit tests for 'one_particle' function

* Polish 'one_particle' and 'two_particle' functions

* Modify unit test for the 'two_particle' and 'one_particle' functions

* Add missing contribution due to core orbitals to the 'two_particle' function

* Modify unit tests for 'two_particle' function

* Update 'CHANGELOG.md'

* Remove trailing spaces

* Update 'CHANGELOG.md'

* Polish docstrings

* Apply suggestions from code review

* Polsih the docstring of 'observable'

* Adds basic resource estimation to quantum tapes. (#862)

* Adds resource estimation and depth to quantum tape. (Untested.)

* Fixed depth calculation to include only observables. Added tests.

* Add new feature to changelog.

* Run black.

* Change accessing of graph to satisfy CodeFactor.

* Update pennylane/tape/circuit_graph.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* Update pennylane/tape/circuit_graph.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update pennylane/tape/tapes/tape.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Added usage examples to code doc strings.

* Fixed typo.

* Replaced truncated graph by operation subgraph.

* Full replacement of truncated graph with operation graph.

* Change default values of depth to None, adjust tests.

* Update .github/CHANGELOG.md

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update pennylane/tape/circuit_graph.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update pennylane/tape/circuit_graph.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Switch from properties to methods for resource estimation.

* Update pennylane/tape/circuit_graph.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

Co-authored-by: Olivia Di Matteo <dimatteo.olivia@gmail.com>
Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>

* Updating qnn.TorchLayer to work in tape mode (#865)

* backup

* add fixture

* polish

* polish2

* Update tests/templates/test_integration.py

* [WIP] Updating collections to work in tape mode

* more

* black and linting

* skip test with race condition

* Add VQECost support

* add more tests

* Updating qnn.TorchLayer to work in tape mode

* update changelog

* fixes

* fixes

* Apply suggestions from code review

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

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* Updating qnn.KerasLayer to work in tape mode (#869)

* Update qnn.keras for tape mode

* Add tape mode evaluate

* Work on tests

* Update qnode

* Tests working

* Update changelog

* Fix weird behaviour

* Remove extra attribute

* Add support for backprop

* Apply suggestions from code review

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Apply suggestions

* merge master

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>

* Make caching compatible with batch execution (#851)

* dummy change

* rewrite num_diff method internally

* undo dummy change needed to open pr

* more

* use deep copy

* rewrite param shift method

* more

* more

* backup

* polish param shift method

* docs

* backup

* typos

* backup

* make postprocessing of finite diff depend on order

* fix operation copies

* backup

* attempt to fix tests

* fixing tests

* temporarily fix copying

* finish param shift var

* blacking the code

* blacking the code

* pylint

* fix black

* fix black

* test black

* black

* fix function naming

* all bugs fixed but inverse

* Revert "fix function naming"

This reverts commit c8eb906.

* struggling with tape construction using inverse gates

* try to get reversible to work

* reversible tape working

* refactor cv param shift (expval) method

* remove middle functions in cv param shift -> now variance test failing to call them

* port CV var

* linting

* basic rewrite of jacobian loop

* rewrite jacobian loop

* test jacobian tape passing

* working parameter shift tests

* CV tests passing

* reversible tape working

* all tests passing

* linting

* use a flat tape list

* black

* add batch_execute functions to device and qubit_device

* black

* backup

* docstrings

* remove deepcopying (#845)

* polish

* docstrings

* polishing

* linting

* Update pennylane/operation.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* Update pennylane/operation.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* Update pennylane/tape/tapes/qubit_param_shift.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* Update pennylane/tape/tapes/reversible.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* make tests pass

* add test for batch_execute

* polish

* polish2

* skip tests if interface not imported

* fix test

* Update pennylane/_device.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* update copy semantics

* Josh review

* Update pennylane/tape/tapes/reversible.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* more

* suggested changes

* suggested changes

* Update pennylane/tape/tapes/reversible.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* suggested changes

* added copying tests

* more copying tests

* another test

* Update pennylane/tape/tapes/reversible.py

* Update pennylane/tape/tapes/cv_param_shift.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* backup

* reset fix implemented, still 4 cache tests not passing

* backup

* improve tests

* Use caching in device

* polisg

* Add argument

* Update devs

* Fix jacobian tape

* Fix tests

* Remove extra test

* Only allow caching in tape mode

* Update test docstring

* Move

* Update tests

* Prevent use in backprop mode

* Update changelog

* Update TODO

* Update docstring

* Apply black

* Fix test

* Apply black

* Remove tests and update docstrings

* Update changelog

* Minor improvements

* Remove unused import

* Remove mention of caching in changelog

* Apply suggestions from code review

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* Update changelog

* Rename caching to cache in qubit device

* Rename caching to cache

* Remove extra methods

* Update docstrings

* Apply suggestion

* Remove extra caching line

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>
Co-authored-by: antalszava <antalszava@gmail.com>

* Add the sqrt X gate (#871)

* Add the sqrt X (SX) gate

Issue #868

* Add inverse and fix docs spacing

inverse still isn't testing correctly

* fixing matrix vrs _matrix

* edit changelog

* edit changelog

* grammar fix

Co-authored-by: Josh Izaac <josh146@gmail.com>

* another typo

Co-authored-by: antalszava <antalszava@gmail.com>

* switch decomposition order

* Update .github/CHANGELOG.md

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

* Update .github/CHANGELOG.md

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

* Apply suggestions from code review

Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>

* add to default_mixed, test default_qubit, test decomposition

* Update .github/CHANGELOG.md

Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>

* Small update in DisplacementEmbedding docstring (#879)

* Update displacement.py

* Update pennylane/templates/embeddings/displacement.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update the templates quickstart (#880)

* default_qubit to use the hard-coded inverses (#872)

* default_qubit to use the hard-coded inverses

Issue #870

* Add to changelog

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

* Add representation to MeasurementProcess (#883)

* add repr method

* fix a test

* polish

* Update pennylane/tape/measure.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update pennylane/tape/measure.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Use dense matrices in mottonen state preparation (#864)

* backup

* refactor

* refactor complete

* add angle equation

* polish

* polish

* simplify code more

* black

* polish equation

* Update pennylane/templates/state_preparations/mottonen.py

* Update pennylane/templates/state_preparations/mottonen.py

* Update pennylane/templates/state_preparations/mottonen.py

* reverse wires

* docstrings

* backup

* update qasm

* make all test run

* docstring polish

* backup

* make tests pass

* black

* typo

* one more typo

* delete unused import

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

* polish

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

* Update tests/templates/test_state_preparations.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* speed up theta

* black

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

* black

* update changelog

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>
Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update jacobian_tape.py (#891)

* AngleEmbedding fewer features than qubits temp func (#881)

* Test for AngleEmbedding where there are fewer features than qubits

* Adjust

* Temp func for no shape check broadcast

* Docstring

* TODO

* format

* just limit wires

* black

* check_shape Returns in docstring

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>

* Fixes bug where binary operations on PennyLane tensors results in an incorrect requires_grad attribute (#889)

* Fixes bug where binary operations on PennyLane tensors resulted in an incorrect requires_grad attribute

* linting

* linting

* more

* more

* more

* more

* final bug quashing

* remove prints

* suggested changes

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>

* Support returning commuting observables on the same wire (#882)

* Prevent multiple observables on one wire

* Add test

* Add to changelog

* Update changelog

* Prevent variances as well

* Fix test

* Fix test

* Fix typo

* Update changelog

* Prevent sampling on same wire

* Add prototype version

* Add test

* Remove constant

* Integrate expand in qubit device

* Add to expand_tape

* Revert qnode changes

* Update naming

* Only expand when needed

* Remove test from qnode

* Add to test

* Correct changelog

* Update changelog

* Remove strict checks

* Add comment

* Add error

* Update tests

* Prevent expanding in qnode if using qubit device:

* Run black

* Revert qubit device

* Move functionality to qnode

* Move tests

* Update tests

* Update spacing

* Run black

* Fix tests

* Revert qubit dev

* Only expand observables if they share a wire

* Only expand observables that share a wire

* Fix tests

* Apply isort

* Fix isort

* Apply suggestions from code review

* parametrize test

* Fix CI checks:

* Actually fix CI

* Update test

* Factor out to a method

* Fix test

* Remove new line

* Minor updates

* Change variable name

* Update docstring

* Add hardware-efficient particle-conserving ansatz U1 (#875)

* Add the ParticleConservingU1 template

* Add checks to 'ParticleConservingU1' template

* Add check to 'ParticleConservingU1' template

* Import the new template and add it to the documentation

* Remove trailing space

* Fix typo in the docstring

* Add functions to generate initial parameters for the 'ParticleConservingU1' template

* Remove trailing whitespaces

* Add unit test for ParticleConservingU1 template

* Add comments in the unit test

* Polish unit test

* Complete unit test 'test_particle_conserving_u1_operations'

* Remove qchem dependency from the unit test

* Add test 'test_particle_conserving_u1_exceptions'

* Add test 'test_integration'

* Remove print line

* Add functions 'particle_conserving_u1_normal' and 'particle_conserving_u1_uniform' to INIT_KWARGS_SHAPES in 'test_init.py'

* Add unit tests for the functions 'particle_conserving_u1_uniform' and 'particle_conserving_u1_normal'

* Improve unit tests for 'particle_conserving_u1_uniform` and particle_conserving_u1_normal'

* Polish docstrings

* Add 'ParticleConservingU1' template to the integration tests

* Improve on the docstrings

* Remove trailing space

* Improve on the docstrings and update 'CHANGELOG.md'

* Polish docstrings

* Reduce size of figures in the docstring

* Reduce size of image in the docstring

* Scale image

* Add link to PL's operations page

* Polish docstring

* Apply suggestions from code review

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>

* Apply suggestions from code review

* Remove 'check_type' import

* Adjust size of figure

* Adjust thumbnail image size

* Adjust aspect ratio of thumbnail figure

* Scale thumbnail

* Add new thumbnail

* Apply suggestions from code review

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>

* Apply suggestions from code review

* Increase slightly the size of the figures

* Adjust size of the figures

* Apply suggestions from code review

Co-authored-by: ixfoduap <40441298+ixfoduap@users.noreply.github.com>

* Apply suggestions from code review

* Apply suggestions from code review

* Add new function to test the decomposition of U1ex

* Polish 'test_decomposition_u1ex'

* Apply suggestions from code review

Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: ixfoduap <40441298+ixfoduap@users.noreply.github.com>

* Apply suggestions from code review

* Fix identation in the docstring

* Polish docstring

* Polish docstring

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
Co-authored-by: ixfoduap <40441298+ixfoduap@users.noreply.github.com>
Co-authored-by: antalszava <antalszava@gmail.com>

* Unwrap tensor in random_layer (#893)

* Unwrap in random_layer if necessary; add test

* Docstring, default.qubit

* Test unwrapped gradient; update docstring

* Docstring

* Add qml.density_matrix QNode return with partial trace capabilities (#878)

* First implementation of density matrix for the default_qubit device

* Update with first tests.

* Black formatting.

* Correct default.qubit, add default.mixed and add tests.

* Unecessary enable tape removed

* Update pennylane/_qubit_device.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update pennylane/_qubit_device.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update pennylane/_qubit_device.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update pennylane/devices/default_mixed.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update tests/tape/test_tape_measure.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update pennylane/devices/default_mixed.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update tests/tape/test_tape_measure.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update tests/tape/test_tape_measure.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update tests/tape/test_tape_measure.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Changes from review

* Add test for all wires (density matrix)

* Better coverage

* Update changelod.md

* Update from second review.

* Blank line changelog

* Update changelog

* Update .github/CHANGELOG.md

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update from third review

* Update pennylane/tape/measure.py

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

* Update pennylane/devices/default_mixed.py

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

* Update pennylane/devices/default_qubit.py

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

* Add density_matrix to tape.__init__

Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>

* Adding functions for agnostic tensor manipulations (#886)

* [WIP] Adding a container class for unified array manipulations

* linting

* fix docs

* add tests

* linting

* add autograd tests

* add autograd tests

* add torch tests

* add tf tests

* full coverage

* docstring

* Apply suggestions from code review

* changes

* Change to functional approach

* add more docstrings

* fix docs

* linting

* coverage

* finish tests

* Apply suggestions from code review

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* fix typos

* Apply suggestions from code review

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* bug fix

* Apply suggestions from code review

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>
Co-authored-by: Maria Schuld <mariaschuld@gmail.com>

* Update pennylane/tensorbox/tensorbox.py

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* suggested changes

* suggested changes

* change

* update changelog

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>
Co-authored-by: Maria Schuld <mariaschuld@gmail.com>

* Add tensor unwrapping in BaseQNode for keyword arguments  (#903)

* Fix in BaseQNode

* Add staticmethod for unwrapping (codefactor); remove import

* Change to check that spots init_state difference earlier

* CHANGELOG

* Update

* Use recorder to check gates used

* Test docstrings

* Fix gradient in tape mode when measurements are independent of a parameter (#901)

* Fix batch execution for parameters that are independent of observable

* Add test

* Remove extra indent

* Fixes #709 (#899)

* Fixes #709

* Conform to PEP8

* Fixes formatting using black

* * Added a conditional test for a GPU enabled environment
* Added changelog/contribution.
* Fixed also for the tape mode

* Fixes a condition to run a CUDA related test

* Fixes a bug in test

* Update .github/CHANGELOG.md

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

* Update tests/qnn/test_qnn_torch.py

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

* Update tests/qnn/test_qnn_torch.py

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

* Update tests/qnn/test_qnn_torch.py

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

* Indentation correction

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

* Followup #899 (#906)

Fixes CUDA test

* Fixes bug in the QAOA _diagonal_terms function to take into account the queuing refactor (#905)

* Fixes bug in the QAOA _diagonal_terms function to take into account the queuing refactor

* update changelog

* Update .github/CHANGELOG.md

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

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

* Allow PennyLane to rescan and refresh available plugin devices within the same Python runtime (#907)

* Fix entrypoint colab bug

* more

* more

* final

* linting

* doc fix

* Apply suggestions from code review

* suggested changes

Co-authored-by: antalszava <antalszava@gmail.com>

* Add decomposition for CRot gate (#908)

* Add decomposition

* Add test

* Update decomposition

* Update changelog

* Add more parameter options

* Support in non tape mode

* Update test to accommodate tape mode

* Add comment

* Add hardware-efficient particle-conserving ansatz U2 (#876)

* Add the ParticleConservingU2 template

* VQECost can optimize observables using the grouping module (#902)

* First attempt

* Add first version

* Add test

* Add to test

* Add to tests

* Run black

* Remove trailing whitespace

* Add to documentation

* Add to changelog

* Minor corrections

* Prevent calculation of the metric tensor in optimize mode

* Add test

* Apply checks

* Minor update

* Move to new feature

* Apply suggestions from code review

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Add mention of grouping module in changelog

* Apply suggestiosn

* Fix error in example

* Update .github/CHANGELOG.md

* Update .github/CHANGELOG.md

* Fix changelog

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Rename VQECost to ExpvalCost (#913)

* Rename VQECost to ExpvalCost

* Add VQECost as deprecated

* Add to changelog

* Update PR number

* Revert changes to changelog

* Change a to an

* Add pylint exception

* Remove VQECost from docs

* Reintroduce docstring

* Support returning the metric tensor of ExpvalCost in tape mode (#911)

* First attempt

* Support old qnode in tape mode

* Add test

* Switch to disabling and re-enabling tape

* Try with tests

* Make warnings appear for users

* Fix test

* Remove the _wires arg

* Remove reference to VQECost

* Add to changelog

* Rename

* Fix CI checks

* Apply suggestions from code review

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Add hard-coded expected val

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Modify qml.grad so that it stores and makes accessible the value of the intermediate forward pass (#914)

* Modify qml.grad so that it stores and makes accessible the value of the intermediate forward pass

* fix

* linting

* fix docs

* add tests

* update changelog

* Update pennylane/__init__.py

* suggested changes

* Update pennylane/__init__.py

Co-authored-by: Theodor <theodor@xanadu.ai>

Co-authored-by: Theodor <theodor@xanadu.ai>

* Remove mention of travis (#917)

* Define the generator for the MultiRZ operation (#912)

* [WIP] Define the generator for the MultiRZ operation

* Save recalculating generator

* Apply black

* Add test

* Add to changelog

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

* Support for MultiRZ and CRot in default.qubit.tf (#921)

* Adding MultiRZ default.tensor.tf func

* Add tests; docstrings; update

* String compare

* Temporarily remove CRot support so that it gets decomposed

* Formatting

* Fix

* Integration tests for parametrized gates taking a tf variable

* Update pennylane/devices/tf_ops.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Changelog

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Fixes bug in tape.set_parameters() (#923)

* Fixes bug in tape.set_parameters()

* add test

* re add test

* suggested changes

* Allow optimizers to return cost function output via opt step (#916)

* Modify qml.grad so that it stores and makes accessible the value of the intermediate forward pass

* fix

* linting

* fix docs

* add tests

* update changelog

* Update pennylane/__init__.py

* suggested changes

* Update pennylane/__init__.py

Co-authored-by: Theodor <theodor@xanadu.ai>

* Move grad and jacobian

* Fix optimizers

* Fix for user-defined gradients

* Run black

* Fix pylint issues

* Remove autograd functions from docs

* Apply suggestions from code review

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Simplify compute_gradient

* Raise error in step_and_cost for gradient-free opts

* Remove step_and_cost from rotosolve/-select

* Add simple tests

* update changelog

* Revert changes

* Add example to changelog

* Apply suggestions from code review

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

* Apply suggestions from code review

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

* Update step calculations

* Fix tests

* Add rotosolve/-select

* Apply suggestions from code review

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Apply suggestions from code review

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

* Update docstring

* Fix docstrings

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

* Add support for arbitrary linear combination gradient recipes (#909)

* Have positive and negative multiplier and shift values

* No print

* Formatting

* 3 element terms for grad_recipes; qubit okay; CV draft

* CV for tape mode

* Comments

* Remove unused

* Formatting

* Solve casting by specifying dtype at creation

* No casting needed for shifted

* Update module docstring and Operation.grad_recipe docstring

* Development guide update

* Wording

* Adding tests; adding error raised for unsupported logic for tape second-order CV case

* No f strings

* Update pennylane/qnodes/cv.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update pennylane/tape/tapes/cv_param_shift.py

* Simplify using np.dot in CV param shift tape

* Update tests/qnodes/test_qnode_cv.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* get_parameter_shift in tape mode as per Josh's suggestion; use that

* Changelog

* Update tests/tape/tapes/test_cv_param_shift.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update .github/CHANGELOG.md

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

* merge in changes from 915

* Update pennylane/operation.py

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

* Update grad recipe formulae as per Tom's suggestions

* Update other formula in comment

* CHANGELOG

* Add rendering img url approach

* Plus

* Update pennylane/operation.py

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

* Applying review suggestions

* Update doc/development/plugins.rst

* Update pennylane/operation.py

* equation formatting fixes

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

* Adding controlled rotation gradients (#915)

* Have positive and negative multiplier and shift values

* No print

* Formatting

* 3 element terms for grad_recipes; qubit okay; CV draft

* CV for tape mode

* Comments

* Remove unused

* Formatting

* Solve casting by specifying dtype at creation

* No casting needed for shifted

* Update module docstring and Operation.grad_recipe docstring

* Development guide update

* Wording

* Adding tests; adding error raised for unsupported logic for tape second-order CV case

* No f strings

* adding CX gradient recipe

* Update pennylane/qnodes/cv.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update pennylane/tape/tapes/cv_param_shift.py

* more

* more

* more tests

* fix typo

* Apply suggestions from code review

Co-authored-by: antalszava <antalszava@gmail.com>

* Simplify using np.dot in CV param shift tape

* Update tests/qnodes/test_qnode_cv.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* get_parameter_shift in tape mode as per Josh's suggestion; use that

* Changelog

* Update tests/tape/tapes/test_cv_param_shift.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Use get_parameter_shift in qubit param shift

* Specify the shift kwarg

* Further docstrings

* CHANGELOG

* Update .github/CHANGELOG.md

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

* Apply suggestions from code review

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

* merge in changes from 915

* suggested changes

* black

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

* Support multiple devices with ExpvalCost (#927)

* Fix multiple devices in ExpvalCost in tape mode

* Extend test to non-tape mode

* Fix typo

* Apply suggestions

* Applied suggestions

* Fix CI

* Update pennylane/vqe/vqe.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Fix incorrect exception message for unknown interfaces (#930)

* Fix incorrect exception message for unknown interfaces

* changelog

* Update qchem._terms_to_qubit_operator function to handle tensors with identities (#928)

* QChem _terms_to_qubit_operator identity cases

* Formatting

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Pin pyscf<1.7.4 to allow scipy>=1.5 in QChem (#926)

* Remove the pinning for scipy and add pinning for pyscf

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Update requirements.txt

* Pin pyscf==1.7.2

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update requirements.txt

* Update changelog for the next release (#932)

* Update changelog for the next release

* Update CHANGELOG.md

* Apply suggestions from code review

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* suggested changes

* reword tricks

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* Improve the reliability of multi-threaded QNodeCollection execution by adding thread locking during queuing (#918)

* Fixes #910

* Added re-entrant lock guard before/after with block of QuantumTape.
* Fixes a PyTorch test failure caused by numerical precision.

* Modified the change log

* Fixes typo

* Remove dependency to template circuits from parallel test

* Added enable/disable tape mode guard for QNodeCollection test

* Added fixture param for the problematic test

* Update .github/CHANGELOG.md

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update tests/tape/tapes/test_qnode.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Fixed potential deadlock because of exception in QuantumTape

* Fixed unused variable error

* Assert if QNodeCollection instantiation does not throw

* Update tests/tape/tapes/test_qnode.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update docstrings (#934)

* Update readme (#933)

* Update readme

* Update readme

* Update readme

* Update readme

* Update readme

* Update readme

* Update readme

* Update readme

* Update readme

* Update readme

* more

* more

* more

* more

* more

* more

* more

* more

* more

* more

* more

* more

* test

* test

* more

* Apply suggestions from code review

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* Update README.md

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>

* add new readme

* add new readme

* remove old readme

* Added gif

* remove file

* update gif

* crop gif

* Apply suggestions from code review

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

* revert images

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

* Bump version number to v0.13 (#935)

* Bump version number to v0.13

* Apply suggestions from code review

Co-authored-by: antalszava <antalszava@gmail.com>

* fixes

Co-authored-by: antalszava <antalszava@gmail.com>

* typo

* fix missing images

* Bump version number to v0.14-dev (#939)

* Bump version number to v0.14-dev

* fix

* Solving issues with black using the standard black l-100. Also, I used isort to sort the libraries.

* CI

* fix

* Apply suggestions from code review

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

* Update pennylane/devices/tests/test_compare_default_qubit.py

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

* Apply suggestions from code review

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

* Update CHANGELOG.md

Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
Co-authored-by: anthayes92 <34694788+anthayes92@users.noreply.github.com>
Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>
Co-authored-by: Olivia Di Matteo <dimatteo.olivia@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: agran2018 <45397799+agran2018@users.noreply.github.com>
Co-authored-by: Christina Lee <chrissie.c.l@gmail.com>
Co-authored-by: ixfoduap <40441298+ixfoduap@users.noreply.github.com>
Co-authored-by: rmoyard <36766072+rmoyard@users.noreply.github.com>
Co-authored-by: Shumpei Kobayashi <skonb@me.com>
Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
Co-authored-by: Theodor <theodor@xanadu.ai>
Co-authored-by: trbromley <brotho02@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-ready 👌 PRs which are ready for review by someone from the core team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants