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

Adds basic resource estimation to quantum tapes. #862

Merged
merged 23 commits into from Oct 26, 2020

Conversation

glassnotes
Copy link
Contributor

Context: Resource estimation of circuits is a common task, and the functionality is not currently implemented

Description of the Change: Added two new properties to QuantumTape: resources, and depth. Also adjusted the TapeCircuitGraph to perform the necessary computations.

Benefits: Users can quickly obtain resource counts in an automated manner, which is especially helpful for larger circuits.

Possible Drawbacks: Implementation is only for tape mode and not general QNodes.

Related GitHub Issues: None

@codecov
Copy link

codecov bot commented Oct 20, 2020

Codecov Report

Merging #862 into master will increase coverage by 0.29%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #862      +/-   ##
==========================================
+ Coverage   97.54%   97.84%   +0.29%     
==========================================
  Files         137      137              
  Lines        9387     9413      +26     
==========================================
+ Hits         9157     9210      +53     
+ Misses        230      203      -27     
Impacted Files Coverage Δ
pennylane/tape/circuit_graph.py 100.00% <100.00%> (ø)
pennylane/tape/tapes/tape.py 99.29% <100.00%> (+0.04%) ⬆️
pennylane/beta/devices/default_tensor_tf.py 90.69% <0.00%> (+1.16%) ⬆️
pennylane/beta/devices/default_tensor.py 95.23% <0.00%> (+1.70%) ⬆️
pennylane/interfaces/tf.py 90.00% <0.00%> (+2.50%) ⬆️
pennylane/devices/default_qubit_tf.py 89.83% <0.00%> (+3.38%) ⬆️
pennylane/tape/interfaces/torch.py 100.00% <0.00%> (+3.77%) ⬆️
pennylane/interfaces/torch.py 93.06% <0.00%> (+3.96%) ⬆️
pennylane/tape/interfaces/tf.py 96.22% <0.00%> (+5.66%) ⬆️
pennylane/qnn/cost.py 100.00% <0.00%> (+57.14%) ⬆️

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 9bbf560...d26deb5. Read the comment docs.

Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>
@glassnotes glassnotes marked this pull request as ready for review October 20, 2020 18:20
@glassnotes glassnotes changed the title [WIP] Adds basic resource estimation to quantum tapes. Adds basic resource estimation to quantum tapes. Oct 20, 2020
@glassnotes glassnotes added enhancement ✨ New feature or request review-ready 👌 PRs which are ready for review by someone from the core team. labels Oct 20, 2020
Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

Looks great @glassnotes! I have a couple of questions regarding UI, but they are relatively minor, and another question regarding the additional graph construction.

pennylane/tape/circuit_graph.py Outdated Show resolved Hide resolved
pennylane/tape/circuit_graph.py Outdated Show resolved Hide resolved
Comment on lines 56 to 57
@property
def depth(self):
Copy link
Member

Choose a reason for hiding this comment

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

I tend to like properties when they need to perform some additional validation outside of a simple attribute, but for something a bit more computational intensive (like a graph algorithm), I tend to favour methods.

I find that properties can 'hide' the computation a bit, whereas with a method you expect it. E.g.,

  • tape.depth: this feels like a pre-computed quantity I am extracting, and might be surprised if its not instantaneous

  • tape.get_depth(): I would not be surprised if this takes some time to compute

This is relatively minor, just curious to get peoples thoughts on it

Copy link
Member

Choose a reason for hiding this comment

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

Do we think the computing time will be notable? If not, I'd say tape.depth might be better from a user perspective. If so, then get_depth() communicates the underlying computation clearly, as @josh146 says

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was curious, so I did a really rough timing test for 2 - 10 wires, for some simple random circuits with up to 50000 gates and a single expectation value at the end, so it will compute the truncated graph. Worst case it's like close to 2s. Though this doesn't tell us the whole story, e.g. maybe there are some weird edge case circuits, and these are single circuits at each point and not averages (though the results of a couple runs produced very similar plots). In any case I'm comfortable with tape.depth.

image

Copy link
Member

Choose a reason for hiding this comment

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

I would say that 2s compute time would definitely convince me for get_depth() 😆 But then again, that is for 50000 gates, which isn't a common use case. Happy with either for now, we can always iterate with feedback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After doing some research and querying my in-house software dev oracle, I think this should be switched to get_resources() as well as get_depth() for both TapeCircuitGraph and QuantumTape. If they were things that would be computed upon instantiation, @property would make sense because that content is already there and just being accessed. However for depth and resources, as much as I consider them to be properties of a circuit, here they aren't computed until asked for. Furthermore they will change if you add/remove stuff from the tape, and require recomputation.

Comment on lines 839 to 840
@property
def depth(self):
Copy link
Member

Choose a reason for hiding this comment

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

This one feels/acts more like a property 👍

pennylane/tape/tapes/tape.py Outdated Show resolved Hide resolved
pennylane/tape/tapes/tape.py Show resolved Hide resolved
tests/tape/tapes/test_tape.py Outdated Show resolved Hide resolved
Copy link
Member

@co9olguy co9olguy left a comment

Choose a reason for hiding this comment

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

Thanks @glassnotes!

Just a small comment about attributes using 0 vs None

Comment on lines 56 to 57
@property
def depth(self):
Copy link
Member

Choose a reason for hiding this comment

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

Do we think the computing time will be notable? If not, I'd say tape.depth might be better from a user perspective. If so, then get_depth() communicates the underlying computation clearly, as @josh146 says

pennylane/tape/circuit_graph.py Outdated Show resolved Hide resolved
# expressed in terms of edges, and we want it in terms of nodes.
if self._depth == 0 and len(self.operations) > 0:
if self._operation_graph is None:
self._operation_graph = self.graph.subgraph(self.operations)
Copy link
Member

Choose a reason for hiding this comment

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

💯

pennylane/tape/tapes/tape.py Show resolved Hide resolved
qml.CRX(-2.3, wires=[0, 1])
qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))

Asking for the resources produces a dictionary as shown below:
Copy link
Member

Choose a reason for hiding this comment

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

copy/paste mismatch? "shown below" seems to not point to anything 🤔, and this is the depth function, not the resources function

pennylane/tape/tapes/tape.py Outdated Show resolved Hide resolved
Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

The new subgraph approach does look great! 💯 Left some comments, but all are minor.

Comment on lines 56 to 57
@property
def depth(self):
Copy link
Member

Choose a reason for hiding this comment

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

I would say that 2s compute time would definitely convince me for get_depth() 😆 But then again, that is for 50000 gates, which isn't a common use case. Happy with either for now, we can always iterate with feedback.

.github/CHANGELOG.md Outdated Show resolved Hide resolved
pennylane/tape/circuit_graph.py Outdated Show resolved Hide resolved
pennylane/tape/circuit_graph.py Outdated Show resolved Hide resolved
pennylane/tape/tapes/tape.py Show resolved Hide resolved
pennylane/tape/tapes/tape.py Outdated Show resolved Hide resolved
glassnotes and others added 4 commits October 23, 2020 10:08
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
pennylane/tape/circuit_graph.py Outdated Show resolved Hide resolved
Co-authored-by: Josh Izaac <josh146@gmail.com>
@josh146 josh146 merged commit 48b0c4d into master Oct 26, 2020
@josh146 josh146 deleted the ch1336-qnode-resource-estimation branch October 26, 2020 12:01
alejomonbar pushed a commit to alejomonbar/pennylane that referenced this pull request Dec 1, 2020
* 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>
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
enhancement ✨ New feature or request 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

3 participants