Skip to content

Commit

Permalink
Test for comparing different devices with the default device (#897)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: Nathan Killoran <[email protected]>
Co-authored-by: Tom Bromley <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: antalszava <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* Update pennylane/tape/circuit_graph.py

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

* Update pennylane/tape/tapes/tape.py

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

* 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 <[email protected]>

* Update pennylane/tape/circuit_graph.py

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

* Update pennylane/tape/circuit_graph.py

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

* Switch from properties to methods for resource estimation.

* Update pennylane/tape/circuit_graph.py

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

Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Nathan Killoran <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>

* 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 <[email protected]>

Co-authored-by: Maria Schuld <[email protected]>
Co-authored-by: Tom Bromley <[email protected]>
Co-authored-by: Nathan Killoran <[email protected]>

* 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 <[email protected]>

* Apply suggestions

* merge master

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

* 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 <[email protected]>

* Update pennylane/operation.py

Co-authored-by: Nathan Killoran <[email protected]>

* Update pennylane/tape/tapes/qubit_param_shift.py

Co-authored-by: Nathan Killoran <[email protected]>

* Update pennylane/tape/tapes/reversible.py

Co-authored-by: Nathan Killoran <[email protected]>

* 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 <[email protected]>

* update copy semantics

* Josh review

* Update pennylane/tape/tapes/reversible.py

Co-authored-by: Nathan Killoran <[email protected]>

* more

* suggested changes

* suggested changes

* Update pennylane/tape/tapes/reversible.py

Co-authored-by: Nathan Killoran <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: Nathan Killoran <[email protected]>
Co-authored-by: antalszava <[email protected]>

* 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 <[email protected]>

* another typo

Co-authored-by: antalszava <[email protected]>

* switch decomposition order

* Update .github/CHANGELOG.md

Co-authored-by: Tom Bromley <[email protected]>

* Update .github/CHANGELOG.md

Co-authored-by: Tom Bromley <[email protected]>

* Apply suggestions from code review

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

* add to default_mixed, test default_qubit, test decomposition

* Update .github/CHANGELOG.md

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

* Small update in DisplacementEmbedding docstring (#879)

* Update displacement.py

* Update pennylane/templates/embeddings/displacement.py

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

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

* 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 <[email protected]>
Co-authored-by: Tom Bromley <[email protected]>

* Add representation to MeasurementProcess (#883)

* add repr method

* fix a test

* polish

* Update pennylane/tape/measure.py

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

* Update pennylane/tape/measure.py

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

* 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 <[email protected]>

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* polish

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/templates/test_state_preparations.py

Co-authored-by: Nathan Killoran <[email protected]>

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Nathan Killoran <[email protected]>

* Update pennylane/templates/state_preparations/mottonen.py

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

* speed up theta

* black

* Update pennylane/templates/state_preparations/mottonen.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* black

* update changelog

Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Nathan Killoran <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: ixfoduap <[email protected]>

* Apply suggestions from code review

* Fix identation in the docstring

* Polish docstring

* Polish docstring

Co-authored-by: Maria Schuld <[email protected]>
Co-authored-by: ixfoduap <[email protected]>
Co-authored-by: antalszava <[email protected]>

* 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 <[email protected]>

* Update pennylane/_qubit_device.py

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

* Update pennylane/_qubit_device.py

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

* Update pennylane/devices/default_mixed.py

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

* Update tests/tape/test_tape_measure.py

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

* Update pennylane/devices/default_mixed.py

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

* Update tests/tape/test_tape_measure.py

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

* Update tests/tape/test_tape_measure.py

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

* Update tests/tape/test_tape_measure.py

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

* 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 <[email protected]>

* Update from third review

* Update pennylane/tape/measure.py

Co-authored-by: Tom Bromley <[email protected]>

* Update pennylane/devices/default_mixed.py

Co-authored-by: Tom Bromley <[email protected]>

* Update pennylane/devices/default_qubit.py

Co-authored-by: Tom Bromley <[email protected]>

* Add density_matrix to tape.__init__

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

* 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 <[email protected]>

* fix typos

* Apply suggestions from code review

Co-authored-by: Nathan Killoran <[email protected]>

* bug fix

* Apply suggestions from code review

Co-authored-by: Nathan Killoran <[email protected]>
Co-authored-by: Maria Schuld <[email protected]>

* Update pennylane/tensorbox/tensorbox.py

Co-authored-by: Nathan Killoran <[email protected]>

* suggested changes

* suggested changes

* change

* update changelog

Co-authored-by: Nathan Killoran <[email protected]>
Co-authored-by: Maria Schuld <[email protected]>

* 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 <[email protected]>

* Update tests/qnn/test_qnn_torch.py

Co-authored-by: Tom Bromley <[email protected]>

* Update tests/qnn/test_qnn_torch.py

Co-authored-by: Tom Bromley <[email protected]>

* Update tests/qnn/test_qnn_torch.py

Co-authored-by: Tom Bromley <[email protected]>

* Indentation correction

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

* 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 <[email protected]>

Co-authored-by: Tom Bromley <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* Add hard-coded expected val

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

* 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 <[email protected]>

Co-authored-by: Theodor <[email protected]>

* 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 <[email protected]>
Co-authored-by: Tom Bromley <[email protected]>

* 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 <[email protected]>

* Changelog

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

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* Apply suggestions from code review

Co-authored-by: Tom Bromley <[email protected]>

* Update step calculations

* Fix tests

* Add rotosolve/-select

* Apply suggestions from code review

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

* Apply suggestions from code review

Co-authored-by: Tom Bromley <[email protected]>

* Update docstring

* Fix docstrings

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

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* Update .github/CHANGELOG.md

Co-authored-by: Tom Bromley <[email protected]>

* merge in changes from 915

* Update pennylane/operation.py

Co-authored-by: Tom Bromley <[email protected]>

* 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 <[email protected]>

* Applying review suggestions

* Update doc/development/plugins.rst

* Update pennylane/operation.py

* equation formatting fixes

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

* 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 <[email protected]>

* Update pennylane/tape/tapes/cv_param_shift.py

* more

* more

* more tests

* fix typo

* Apply suggestions from code review

Co-authored-by: antalszava <[email protected]>

* Simplify using np.dot in CV param shift tape

* Update tests/qnodes/test_qnode_cv.py

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

* 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 <[email protected]>

* Use get_parameter_shift in qubit param shift

* Specify the shift kwarg

* Further docstrings

* CHANGELOG

* Update .github/CHANGELOG.md

Co-authored-by: Tom Bromley <[email protected]>

* Apply suggestions from code review

Co-authored-by: Tom Bromley <[email protected]>

* merge in changes from 915

* suggested changes

* black

Co-authored-by: antalszava <[email protected]>
Co-authored-by: Tom Bromley <[email protected]>

* 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 <[email protected]>

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

* 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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

* suggested changes

* reword tricks

Co-authored-by: Nathan Killoran <[email protected]>

* 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 <[email protected]>

* Update tests/tape/tapes/test_qnode.py

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

* 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 <[email protected]>

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

* 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 <[email protected]>

* Update README.md

Co-authored-by: Nathan Killoran <[email protected]>

* 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 <[email protected]>

* revert images

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

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

* Bump version number to v0.13

* Apply suggestions from code review

Co-authored-by: antalszava <[email protected]>

* fixes

Co-authored-by: antalszava <[email protected]>

* 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 <[email protected]>

* Update pennylane/devices/tests/test_compare_default_qubit.py

Co-authored-by: Tom Bromley <[email protected]>

* Apply suggestions from code review

Co-authored-by: Tom Bromley <[email protected]>

* Update CHANGELOG.md

Co-authored-by: antalszava <[email protected]>
Co-authored-by: Maria Schuld <[email protected]>
Co-authored-by: anthayes92 <[email protected]>
Co-authored-by: Nathan Killoran <[email protected]>
Co-authored-by: Tom Bromley <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: agran2018 <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: ixfoduap <[email protected]>
Co-authored-by: rmoyard <[email protected]>
Co-authored-by: Shumpei Kobayashi <[email protected]>
Co-authored-by: soranjh <[email protected]>
Co-authored-by: Theodor <[email protected]>
Co-authored-by: trbromley <[email protected]>
  • Loading branch information
17 people authored Dec 9, 2020
1 parent ce7c1de commit e1fb824
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

<h3>Improvements</h3>

* A new test series, pennylane/devices/tests/test_compare_default_qubit.py, has been added, allowing to test if
a chosen device gives the same result as the default device. Three tests are added `test_hermitian_expectation`,
`test_pauliz_expectation_analytic`, and `test_random_circuit`.
[(#848)](https://github.com/PennyLaneAI/pennylane/pull/848)

<h3>Breaking changes</h3>

<h3>Documentation</h3>
Expand All @@ -18,7 +23,7 @@

This release contains contributions from (in alphabetical order):

Josh Izaac
Josh Izaac, Alejandro Montanez

# Release 0.13.0 (current release)

Expand Down
201 changes: 201 additions & 0 deletions pennylane/devices/tests/test_compare_default_qubit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# Copyright 2018-2020 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests that a device gives the same output as the default device."""
# pylint: disable=no-self-use,no-member
import pytest
from flaky import flaky

import pennylane as qml
from pennylane import numpy as np # Import from PennyLane to mirror the standard approach in demos
from pennylane.templates.layers import RandomLayers

pytestmark = pytest.mark.skip_unsupported


@flaky(max_runs=10)
class TestComparison:
"""Test that a device different to default.qubit gives the same result"""

def test_hermitian_expectation(self, device, tol):
"""Test that arbitrary multi-mode Hermitian expectation values are correct"""
n_wires = 2
dev = device(n_wires)
dev_def = qml.device("default.qubit", wires=n_wires)

if not dev.analytic:
pytest.skip("Device is in non-analytical mode.")

if "Hermitian" not in dev.observables:
pytest.skip("Skipped because device does not support the Hermitian observable.")

if dev.name == dev_def.name:
pytest.skip("Device is default.qubit.")

theta = 0.432
phi = 0.123
A_ = np.array(
[
[-6, 2 + 1j, -3, -5 + 2j],
[2 - 1j, 0, 2 - 1j, -5 + 4j],
[-3, 2 + 1j, 0, -4 + 3j],
[-5 - 2j, -5 - 4j, -4 - 3j, -6],
]
)

def circuit(theta, phi):
qml.RX(theta, wires=[0])
qml.RX(phi, wires=[1])
qml.CNOT(wires=[0, 1])
return qml.expval(qml.Hermitian(A_, wires=[0, 1]))

qnode_def = qml.QNode(circuit, dev_def)
qnode = qml.QNode(circuit, dev)

grad_def = qml.grad(qnode_def, argnum=[0, 1])
grad = qml.grad(qnode, argnum=[0, 1])

assert np.allclose(qnode(theta, phi), qnode_def(theta, phi), atol=tol(dev.analytic))
assert np.allclose(grad(theta, phi), grad_def(theta, phi), atol=tol(dev.analytic))

def test_pauliz_expectation_analytic(self, device, tol):
"""Test that the tensor product of PauliZ expectation value is correct"""
n_wires = 2
dev = device(n_wires)
dev_def = qml.device("default.qubit", wires=n_wires)

if dev.name == dev_def.name:
pytest.skip("Device is default.qubit.")

supports_tensor = (
"supports_tensor_observables" in dev.capabilities()
and dev.capabilities()["supports_tensor_observables"]
)

if not supports_tensor:
pytest.skip("Device does not support tensor observables.")

if not dev.analytic:
pytest.skip("Device is in non-analytical mode.")

theta = 0.432
phi = 0.123

def circuit(theta, phi):
qml.RX(theta, wires=[0])
qml.RX(phi, wires=[1])
qml.CNOT(wires=[0, 1])
return qml.expval(qml.PauliZ(wires=0) @ qml.PauliZ(wires=1))

qnode_def = qml.QNode(circuit, dev_def)
qnode = qml.QNode(circuit, dev)

grad_def = qml.grad(qnode_def, argnum=[0, 1])
grad = qml.grad(qnode, argnum=[0, 1])

assert np.allclose(qnode(theta, phi), qnode_def(theta, phi), atol=tol(dev.analytic))
assert np.allclose(grad(theta, phi), grad_def(theta, phi), atol=tol(dev.analytic))

@pytest.mark.parametrize("ret", [qml.expval, qml.var])
def test_random_circuit(self, device, tol, ret):
"""Test that the expectation value of a random circuit is correct"""
n_wires = 2
dev = device(n_wires)
dev_def = qml.device("default.qubit", wires=n_wires)

if dev.name == dev_def.name:
pytest.skip("Device is default.qubit.")

supports_tensor = (
"supports_tensor_observables" in dev.capabilities()
and dev.capabilities()["supports_tensor_observables"]
)

if not supports_tensor:
pytest.skip("Device does not support tensor observables.")

if not dev.analytic:
pytest.skip("Device is in non-analytical mode.")

n_layers = np.random.randint(1, 5)
weights = 2 * np.pi * np.random.rand(n_layers, 1)

def circuit(weights):
RandomLayers(weights, wires=range(n_wires))
return ret(qml.PauliZ(wires=0) @ qml.PauliX(wires=1))

qnode_def = qml.QNode(circuit, dev_def)
qnode = qml.QNode(circuit, dev)

grad_def = qml.grad(qnode_def, argnum=0)
grad = qml.grad(qnode, argnum=0)

assert np.allclose(qnode(weights), qnode_def(weights), atol=tol(dev.analytic))
assert np.allclose(grad(weights), grad_def(weights), atol=tol(dev.analytic))

def test_four_qubit_random_circuit(self, device, tol):
"""Test a four-qubit random circuit with the whole set of possible gates"""
n_wires = 4
dev = device(n_wires)
dev_def = qml.device("default.qubit", wires=n_wires)

if dev.name == dev_def.name:
pytest.skip("Device is default.qubit.")

if not dev.analytic:
pytest.skip("Device is in non-analytical mode.")

gates = [
qml.PauliX,
qml.PauliY,
qml.PauliZ,
qml.S,
qml.T,
qml.RX,
qml.RY,
qml.RZ,
qml.Hadamard,
qml.Rot,
qml.CRot,
qml.Toffoli,
qml.SWAP,
qml.CSWAP,
qml.U1,
qml.U2,
qml.U3,
qml.CRX,
qml.CRY,
qml.CRZ,
]

layers = 3
np.random.seed(1967)
gates_per_layers = [np.random.permutation(gates).numpy() for _ in range(layers)]

def circuit():
"""4-qubit circuit with layers of randomly selected gates and random connections for
multi-qubit gates."""
np.random.seed(1967)
for gates in gates_per_layers:
for gate in gates:
params = list(np.pi * np.random.rand(gate.num_params))
gate(
*params,
wires=np.random.choice(range(n_wires), size=gate.num_wires, replace=False)
)
return qml.expval(qml.PauliZ(0))

qnode_def = qml.QNode(circuit, dev_def)
qnode = qml.QNode(circuit, dev)

assert np.allclose(qnode(), qnode_def(), atol=tol(dev.analytic))
6 changes: 4 additions & 2 deletions pennylane/templates/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ def get_shape(inpt):

try:
shape = inpt.shape
except AttributeError:
raise ValueError("could not extract shape of object of type {}".format(type(inpt)))
except AttributeError as e:
raise ValueError(
"could not extract shape of object of type {}".format(type(inpt))
) from e

# turn result into tuple to avoid type TensorShape
shape = tuple(shape)
Expand Down
2 changes: 1 addition & 1 deletion qchem/pennylane_qchem/qchem/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def read_structure(filepath, outpath="."):
raise RuntimeError(
"Open Babel error. See the following Open Babel "
"output for details:\n\n {}\n{}".format(e.stdout, e.stderr)
)
) from e
else:
copyfile(file_in, file_out)

Expand Down

0 comments on commit e1fb824

Please sign in to comment.