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

[QIM-8] Add quantum_fisher #2676

Closed
wants to merge 261 commits into from
Closed

[QIM-8] Add quantum_fisher #2676

wants to merge 261 commits into from

Conversation

Qottmann
Copy link
Contributor

@Qottmann Qottmann commented Jun 7, 2022

Context:

Added a dummy function qml.qinfo.quantum_fisher that internally calls qml.metric_tensor and multiplies the result by 4 to have the same scaling factor as in eq. (27) in 2103.15191.

Additionally, I modified the doc-string of qml.metric_tensor accordingly.

@Qottmann Qottmann changed the title Quantumfisher [WIP] [QIM-8] Add quantum_fisher Jun 7, 2022
@codecov
Copy link

codecov bot commented Jun 7, 2022

Codecov Report

Merging #2676 (1839729) into classicalfisher (3bddb42) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@                 Coverage Diff                 @@
##           classicalfisher    #2676      +/-   ##
===================================================
- Coverage            99.59%   99.59%   -0.01%     
===================================================
  Files                  253      253              
  Lines                20375    20384       +9     
===================================================
+ Hits                 20293    20301       +8     
- Misses                  82       83       +1     
Impacted Files Coverage Δ
pennylane/transforms/metric_tensor.py 100.00% <ø> (ø)
pennylane/qinfo/__init__.py 100.00% <100.00%> (ø)
pennylane/qinfo/fisher.py 100.00% <100.00%> (ø)
pennylane/_qubit_device.py 98.85% <0.00%> (-0.29%) ⬇️
pennylane/math/quantum.py 100.00% <0.00%> (ø)
pennylane/measurements.py 99.61% <0.00%> (ø)
pennylane/qinfo/entropies.py 100.00% <0.00%> (ø)
pennylane/devices/default_mixed.py 100.00% <0.00%> (ø)
pennylane/devices/default_qubit.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

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

@josh146
Copy link
Member

josh146 commented Jun 7, 2022

🎉

pennylane/transforms/metric_tensor.py Outdated Show resolved Hide resolved
tests/qinfo/test_fisher.py Outdated Show resolved Hide resolved
pennylane/transforms/metric_tensor.py Show resolved Hide resolved
@Qottmann Qottmann changed the title [WIP] [QIM-8] Add quantum_fisher [QIM-8] Add quantum_fisher Jun 8, 2022
Qottmann and others added 15 commits June 8, 2022 17:28
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
@rmoyard rmoyard self-requested a review June 9, 2022 15:33
Copy link
Contributor

@eddddddy eddddddy 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 @Qottmann! 💯

@@ -236,3 +237,27 @@ def _make_probs(tape, wires=None, post_processing_fn=None):
post_processing_fn = lambda x: qml.math.squeeze(qml.math.stack(x))

return [new_tape], post_processing_fn


def quantum_fisher(*args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Side note (no action needed): qml.metric_tensor is differentiable, so all the more reason to support differentiability of classical_fisher in the near future.

- \langle \partial_i \psi(\bm{\theta}) | \psi(\bm{\theta}) \rangle \langle \psi(\bm{\theta}) | \partial_j \psi(\bm{\theta}) \rangle \right]

with short notation :math:`| \partial_j \psi(\bm{\theta}) \rangle := \frac{\partial}{\partial \theta_j}| \psi(\bm{\theta}) \rangle`.
It is closely related to the quantum fisher information matrix, see :func:`~.pennylane.qinfo.quantum_fisher` and eq. (27) in `arxiv:2103.15191 <https://arxiv.org/abs/2103.15191>`_.
Copy link
Contributor

Choose a reason for hiding this comment

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

The link to pennylane.qinfo.quantum_fisher doesn't seem to be working. Same with the one in the seealso.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep I also noticed that. Any idea on how to fix it?

Copy link
Contributor

Choose a reason for hiding this comment

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

No idea 😆

.. seealso::
:func:`~.pennylane.adjoint_metric_tensor`; ``quantum_fisher()`` is simply calling :func:`~.pennylane.metric_tensor` with a prefactor of 4. Please refer there for implementation details.
"""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be good to add a check here for the shots in tape, such that metric_tensor can be passed if they are finite and adjoint_metric_tensor when they are None. Is that possible for transforms like these?

Copy link
Member

Choose a reason for hiding this comment

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

That's a really good idea! This isn't currently possible, but we would like to overhaul how shots are architected internally, so that this does become possible.

Currently, shots are stored at the device, not at the transform level

Copy link
Contributor Author

@Qottmann Qottmann Jun 9, 2022

Choose a reason for hiding this comment

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

So for the moment maybe add a boolean variable hardware (or something better) and just do an if-clause?

Base automatically changed from classicalfisher to master June 10, 2022 07:39
@Qottmann
Copy link
Contributor Author

Due to many changes in the base branch started a new PR to simplify things: #2684

@Qottmann Qottmann closed this Jun 10, 2022
@trbromley trbromley deleted the quantumfisher branch March 4, 2024 14:12
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.

6 participants