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

qml.evolve: dispatch function #3706

Merged
merged 48 commits into from
Feb 6, 2023
Merged

qml.evolve: dispatch function #3706

merged 48 commits into from
Feb 6, 2023

Conversation

AlbertMitjans
Copy link
Contributor

@AlbertMitjans AlbertMitjans commented Feb 1, 2023

This PR does the following:

  1. Use singledispatch to dispatch qml.evolve into parametrized_evolution and evolution, each with its necessary arguments.
  2. Add a -1 when using qml.evolve with an Operator, to be consistent with ParametrizedEvolution.
  3. Add a deprecation warning in Evolution.__init__ redirecting users to qml.evolve.
  4. Skip the warning in Evolution.__init__ when using qml.evolve.
  5. Remove unused ParametrizedEvolution.time argument.

@codecov
Copy link

codecov bot commented Feb 1, 2023

Codecov Report

Merging #3706 (eca547f) into master (876bac8) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3706      +/-   ##
==========================================
- Coverage   99.74%   99.73%   -0.01%     
==========================================
  Files         328      328              
  Lines       28662    28695      +33     
==========================================
+ Hits        28588    28619      +31     
- Misses         74       76       +2     
Impacted Files Coverage Δ
pennylane/devices/default_qubit.py 99.69% <ø> (-0.01%) ⬇️
pennylane/pulse/parametrized_evolution.py 95.45% <ø> (-0.11%) ⬇️
pennylane/ops/functions/evolve.py 100.00% <100.00%> (ø)
pennylane/ops/op_math/evolution.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/state_preparation.py 100.00% <100.00%> (ø)
pennylane/devices/default_qubit_tf.py 98.03% <0.00%> (-1.97%) ⬇️

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

@AlbertMitjans AlbertMitjans marked this pull request as draft February 1, 2023 14:39
@AlbertMitjans AlbertMitjans marked this pull request as ready for review February 1, 2023 14:46
@lillian542
Copy link
Contributor

I'm not sure about adding t: for the Evolution operator, it seems to suggest that the coefficient in exp(ixG) is time, as it is set by t=3 in the function call. The Evolution class is described in the docstring as implementing exp(ixG) rather than exp(iHt) because it should be a more general thing that also encompasses, for example, general rotation operators:

>>> theta = np.array(1.23)
>>> op = Evolution(qml.PauliX(0), -0.5 * theta)
>>> qml.math.allclose(op.matrix(), qml.RX(theta, wires=0).matrix())
True

So I'm not convinced it makes things clearer, though I do like having the option to set the param in qml.evolve.

@AlbertMitjans
Copy link
Contributor Author

I'm not sure about adding t: for the Evolution operator, it seems to suggest that the coefficient in exp(ixG) is time

A rotation operator is considered an evolution? When googling "evolution operator" all the links talk about time evolution.

@lillian542
Copy link
Contributor

A rotation operator is considered an evolution? When googling "evolution operator" all the links talk about time evolution.

This was also my initial response, and I think the name is not ideal. The idea with the operator was a generalized exp(ixG), without regard for whether something was being evolved 'in time' or in some other parameter.

On the original shortcut ticket it was called Rotation, but that sounds like it's not for time evolution. So it ended up being called Evolution, which sort of sounds like it's not for rotation (or anything else but time evolution). The description and examples in the docstring attempt to clarify that it is meant as a more general mathematical object exp(ixG). But we couldn't come up with a good general name for exp(ixG). I feel like this could be improved, but I also don't have any good suggestions.

Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

Looks good to me! 🎉

@AlbertMitjans AlbertMitjans enabled auto-merge (squash) February 6, 2023 08:17
@AlbertMitjans AlbertMitjans merged commit 0995dc9 into master Feb 6, 2023
@AlbertMitjans AlbertMitjans deleted the refactor-evolve branch February 6, 2023 08:35
mudit2812 pushed a commit that referenced this pull request Apr 13, 2023
* 🧪 tests (evolve): Fix tests.

* 📝 docs (evolve): Fix docstring.

* 📝 docs (evolve): Fix docstring.

* 🧪 tests (evolve): Add tests.

* ✏️ chore (changelog): Add changelog entry.

* 📝 docs (evolve): Fix docstring.

* 📝 docs (evolve): Fix docstring.

* 🧪 tests (evolve): Fix coverage.

* 🔧 refactor (evolve): Dispatch function.

* 🔧 refactor (evolve): Dispatch function.

* 📝 docs (evolve): Fix docstring.

* 🧪 tests (evolve): Fix tests.

* 📝 docs (evolve): Fix sphinx.

* ⏪ revert (evolve): Remove t and dt from parametrized_evolution.

* 📝 docs (evolve): Fix docstring.

* 📝 docs (evolve): Fix docstring.

* Update pennylane/ops/functions/evolve.py

Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>

* Update pennylane/ops/functions/evolve.py

Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>

* 📝 docs (evolve): Update evolve docstring.

* 📝 docs (evolve): Update evolve docstring.

* 📝 docs (evolve): Fix sphinx.

* 📝 docs (evolve): Test sphinx.

* 📝 docs (evolve): Test sphinx.

* 📝 docs (evolve): Use html.

* 📝 docs (evolve): Fix docstring.

* 📝 docs (evolve): Fix docstring.

* 📝 docs (evolve): Test sphinx.

* 📝 docs (evolve): Test sphinx.

* 📝 docs (evolve): Fix docstring.

* 📝 docs (evolve): Fix docstring.

* 🐛 fix (evolve): Remove op from initial call.

* 📝 docs (evolve): Remove docstrings of dispatched functions.

* 📝 docs (evolve): Change docstring.

* 🔧 refactor (evolve): Add warning.

* Update doc/releases/changelog-dev.md

* ✏️ chore (changelog): Add deprecation entry.

* ✏️ chore (changelog): Add changelog entry.

* 📝 docs (evolve): Change docstring.

* Update pennylane/ops/functions/evolve.py

---------

Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants