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

Evolution operator #3375

Merged
merged 40 commits into from
Dec 9, 2022
Merged

Evolution operator #3375

merged 40 commits into from
Dec 9, 2022

Conversation

lillian542
Copy link
Contributor

Context:

  • Exp class does not have generator method or parameter_frequency property defined, even though these could be defined for some instances of Exp.
  • For instances of Exp where the base operator includes parameters (e.g. 0.5*qml.PauliX(0), or any instance of qml.Hamiltonian), the operator has num_params > 1, and standard functions for differentiation via parameter shift, such as qml.generator(op), don't work.

Description of the Change:

  • Add generator and parameter_frequency to Exp class in cases where it is defined (when the coefficient has no real component and the base operator is Hermitian)
  • Add Evolution operator defined to be of the form exp(ixG) with a single, trainable parameter x. This allows differentiation with regards to the parameter x, even in instances where the base operator G contains additional parameters.

@lillian542 lillian542 marked this pull request as ready for review November 16, 2022 22:08
@codecov
Copy link

codecov bot commented Nov 16, 2022

Codecov Report

Merging #3375 (a140b1f) into master (2162274) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3375   +/-   ##
=======================================
  Coverage   99.86%   99.86%           
=======================================
  Files         309      309           
  Lines       27542    27597   +55     
=======================================
+ Hits        27506    27561   +55     
  Misses         36       36           
Impacted Files Coverage Δ
pennylane/devices/default_qubit.py 100.00% <ø> (ø)
pennylane/operation.py 97.39% <100.00%> (ø)
pennylane/ops/op_math/__init__.py 100.00% <100.00%> (ø)
pennylane/ops/op_math/exp.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/hamiltonian.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Nice work so far! Made a few comments, let me know once they are addressed and I can give it another look 👍🏼

pennylane/ops/op_math/__init__.py Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
tests/ops/op_math/test_exp.py Show resolved Hide resolved
Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

Great work @lillian542, just left some suggestions and comments.

pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
tests/ops/op_math/test_exp.py Show resolved Hide resolved
tests/ops/op_math/test_exp.py Show resolved Hide resolved
albi3ro and others added 3 commits December 6, 2022 17:34
* get parameter shift working with evolution operator

* Fix bug in Exp.hash

* Update tests

* Coeff to string in hash

* Update test

Co-authored-by: Lillian Frederiksen <lillian542@gmail.com>
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Great work! Left some comments for you to address.

Just one suggestion, since this operation doesn't have a top level constructor (eg. for Sum class we have a top level qml.op_sum), I think it might be worth while to just make it available top level. This would require adding an import in the PennyLane init file with from ops import Evolution and would unlock the qml.Evolution() UI

You should confirm with Tom or Josh to make sure this is actually what we want. Otherwise I think it looks great!

pennylane/operation.py Show resolved Hide resolved
doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
pennylane/ops/qubit/hamiltonian.py Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Show resolved Hide resolved
pennylane/ops/op_math/exp.py Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
tests/ops/op_math/test_exp.py Outdated Show resolved Hide resolved
tests/ops/op_math/test_exp.py Show resolved Hide resolved
@Jaybsoni Jaybsoni added the merge-ready ✔️ All tests pass and the PR is ready to be merged. label Dec 9, 2022
Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

Leaving some suggestions. I might not be able to take a look again due to limited internet availability but please feel free to get this merged once you have gone through them and carefully checked the rendering for the docs!

pennylane/ops/op_math/exp.py Show resolved Hide resolved
pennylane/ops/op_math/exp.py Show resolved Hide resolved
pennylane/ops/op_math/exp.py Show resolved Hide resolved
pennylane/ops/op_math/exp.py Outdated Show resolved Hide resolved
doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
pennylane/ops/op_math/exp.py Show resolved Hide resolved
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Awesome work!

@Jaybsoni Jaybsoni enabled auto-merge (squash) December 9, 2022 21:44
@Jaybsoni Jaybsoni merged commit f10ad1c into master Dec 9, 2022
@Jaybsoni Jaybsoni deleted the evolution_operator branch December 9, 2022 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-ready ✔️ All tests pass and the PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants