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

Device tests run in tape #1026

Merged
merged 15 commits into from
Jan 25, 2021
Merged

Device tests run in tape #1026

merged 15 commits into from
Jan 25, 2021

Conversation

antalszava
Copy link
Contributor

Context:

The device test suite runs in tape mode.

Description of the Change:

  • Adds the needed fixture to the dedicated conftest.py file of the device test suite
  • Adds the fixtures
  • Operations that were not instantiated within a QNode are queued
  • Moves the return type ref (e.g., qml.expval) in the test functions such that the tape version can also be fetched

@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.

@codecov
Copy link

codecov bot commented Jan 22, 2021

Codecov Report

Merging #1026 (e538c79) into master (cf3cdb1) will increase coverage by 2.49%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1026      +/-   ##
==========================================
+ Coverage   95.44%   97.93%   +2.49%     
==========================================
  Files         153      153              
  Lines       11392    11392              
==========================================
+ Hits        10873    11157     +284     
+ Misses        519      235     -284     
Impacted Files Coverage Δ
pennylane/beta/devices/default_tensor_tf.py 90.69% <0.00%> (+1.16%) ⬆️
pennylane/math/tensorbox.py 95.97% <0.00%> (+1.34%) ⬆️
pennylane/beta/devices/default_tensor.py 95.23% <0.00%> (+1.70%) ⬆️
pennylane/tape/qnode.py 98.33% <0.00%> (+2.08%) ⬆️
pennylane/interfaces/tf.py 90.00% <0.00%> (+2.50%) ⬆️
pennylane/math/numpy_box.py 98.55% <0.00%> (+2.89%) ⬆️
pennylane/devices/default_qubit_tf.py 91.04% <0.00%> (+2.98%) ⬆️
pennylane/tape/interfaces/torch.py 100.00% <0.00%> (+3.77%) ⬆️
pennylane/interfaces/torch.py 93.06% <0.00%> (+3.96%) ⬆️
pennylane/tape/interfaces/tf.py 96.22% <0.00%> (+5.66%) ⬆️
... and 8 more

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 cf3cdb1...e538c79. Read the comment docs.

@@ -46,7 +46,7 @@
"CSWAP": qml.CSWAP(wires=[0, 1, 2]),
"CZ": qml.CZ(wires=[0, 1]),
"CY": qml.CY(wires=[0, 1]),
"DiagonalQubitUnitary": qml.DiagonalQubitUnitary(np.eye(2), wires=[0]),
"DiagonalQubitUnitary": qml.DiagonalQubitUnitary(np.array([1, 1]), wires=[0]),
Copy link
Member

Choose a reason for hiding this comment

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

nice catch :)

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.

💯 Looks great Antal!

Copy link
Contributor

@thisac thisac 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 @antalszava! 🚀

Comment on lines 267 to 272
@pytest.fixture
def in_tape_mode():
"""Run the test in tape mode"""
qml.enable_tape()
yield
qml.disable_tape()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ever used in devices/tests? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, good catch! Removed.

@@ -106,7 +106,7 @@ def circuit(theta, phi):
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])
@pytest.mark.parametrize("ret", ["expval", "var"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change? Did it not work before or is this just better/safer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tape mode was activated after ret got its value, so non-tape qml.expval and qml.var were pulled in.

@josh146 josh146 merged commit 3aa6f47 into master Jan 25, 2021
@josh146 josh146 deleted the device_tests_tape branch January 25, 2021 14:42
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

3 participants