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 Fourier coefficient calculation module #1160

Merged
merged 129 commits into from
May 27, 2021
Merged

Conversation

glassnotes
Copy link
Contributor

@glassnotes glassnotes commented Mar 24, 2021

Context: The Fourier spectrum of a quantum model can be used to gauge its expressivity, as demonstrated in Schuld, Sweke and Meyer (2020) and Vidal and Theis, 2019.

Description of the Change: A new module, fourier, and associated documentation and visualization methods. Note: the visualization tools are being developed in #1198 to keep the review process more manageable.

Benefits: Users now have built-in tools and examples for computing the Fourier spectra and coefficients of quantum circuits.

Possible Drawbacks: Spectra are currently only calculated for a subset of possible operations. Further work is required to extend this.

Related GitHub Issues: N/A

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit .github/CHANGELOG.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

doc/code/qml_fourier.rst Outdated Show resolved Hide resolved
@mariaschuld
Copy link
Contributor

mariaschuld commented May 27, 2021

The module docstring is now like this:

Screenshot from 2021-05-27 10-37-06

Everything is clickable. Maybe we can use the format also for kernels and groupings.

@josh146
Copy link
Member

josh146 commented May 27, 2021

The module docstring is now like this:

It looks fantastic!

@mariaschuld
Copy link
Contributor

mariaschuld commented May 27, 2021

@glassnotes only one failing test, which is not even related to the module:

Traceback (most recent call last):
  File "/home/runner/work/pennylane/pennylane/tests/interfaces/test_qnode_jax.py", line 72, in test_simple_jacobian
    np.testing.assert_allclose(grads, np.array([-0.09784342, -0.19767685]))
  File "/opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/numpy/testing/_private/utils.py", line 1527, in assert_allclose
    assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
  File "/opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/numpy/testing/_private/utils.py", line 840, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Not equal to tolerance rtol=1e-07, atol=0

Mismatched elements: 2 / 2 (100%)
Max absolute difference: 3.83459161e-08
Max relative difference: 2.55436125e-07
 x: array([-0.097843, -0.197677])
 y: array([-0.097843, -0.197677])

Maybe this is caused by config.update("jax_enable_x64", True), and we have to disable it again. Let me try.

@glassnotes
Copy link
Contributor Author

The module docstring is now like this:

Everything is clickable. Maybe we can use the format also for kernels and groupings.

Agreed! I will make an issue for this.

@glassnotes
Copy link
Contributor Author

Maybe this is caused by config.update("jax_enable_x64", True), and we have to disable it again. Let me try.

Yes I think that's the reason. A temporary fix would be to not enable 64-bit support, and just set the equality threshold at something higher, like 1e-6. I'm not a big fan of this, but to get everything to work nicely with JAX requires modifying stuff outside the scope of the PR (see #1363 )

@mariaschuld
Copy link
Contributor

Maybe this is caused by config.update("jax_enable_x64", True), and we have to disable it again. Let me try.

I can locally run the tests :) Let's see if CI is happy.

@mariaschuld
Copy link
Contributor

mariaschuld commented May 27, 2021

@josh146 sorry for the delay. Happy if we merge? The codecov should only be one import line that is not tested (plus the strange omission of seeing that coefficients is covered).

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.

yep go for it!

@mariaschuld mariaschuld merged commit b6781ca into master May 27, 2021
@mariaschuld mariaschuld deleted the fourier_spectrum branch May 27, 2021 14:17
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.

None yet

4 participants