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

Update handling statevector data types in Python #290

Merged
merged 16 commits into from
May 10, 2022
Merged

Conversation

chaeyeunpark
Copy link
Contributor

@chaeyeunpark chaeyeunpark commented May 6, 2022

Before submitting

Please complete the following checklist when submitting a PR:

  • All new features must include a unit test.
    If you've fixed a bug or added code that should be tested, add a test to the
    tests directory!

  • All new functions and code must be clearly commented and documented.
    If you do make documentation changes, make sure that the docs build and
    render correctly by running make docs.

  • Ensure that the test suite passes, by running make test.

  • Add a new entry to the .github/CHANGELOG.md file, summarizing the
    change, and including a link back to the PR.

  • Ensure that code is properly formatted by running make format.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Context: With recent change in PennyLane, default.qubit which is the parent class of lightning.qubit, now accepts datatypes for a statevector. This PR updates lightning.qubit device to utilize this new feature.

@github-actions
Copy link
Contributor

github-actions bot commented May 6, 2022

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.

@github-actions
Copy link
Contributor

github-actions bot commented May 6, 2022

Test Report (C++) on Ubuntu

           1 files  ±0             1 suites  ±0   0s ⏱️ ±0s
       764 tests ±0         764 ✔️ ±0  0 💤 ±0  0 ±0 
228 568 runs  ±0  228 568 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 3ba6b18. ± Comparison against base commit f847205.

♻️ This comment has been updated with latest results.

@chaeyeunpark chaeyeunpark marked this pull request as ready for review May 9, 2022 23:09
return LightningQubit(wires=1)
@pytest.fixture(scope="function", params=[np.complex64, np.complex128])
def qubit_device_1_wire(request):
return LightningQubit(wires=1, c_dtype=request.param)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of inserting datatype directly to a statevector, we now set the device datatypes. Test suits are updated accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

Great job on adding this change

@chaeyeunpark chaeyeunpark requested review from maliasadi and mlxd and removed request for maliasadi May 9, 2022 23:49
@codecov
Copy link

codecov bot commented May 9, 2022

Codecov Report

Merging #290 (3ba6b18) into master (f847205) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #290      +/-   ##
==========================================
- Coverage   99.19%   99.18%   -0.02%     
==========================================
  Files          28       28              
  Lines        3105     3060      -45     
==========================================
- Hits         3080     3035      -45     
  Misses         25       25              
Impacted Files Coverage Δ
pennylane_lightning/_version.py 100.00% <100.00%> (ø)
pennylane_lightning/lightning_qubit.py 100.00% <100.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 f847205...3ba6b18. Read the comment docs.

@chaeyeunpark
Copy link
Contributor Author

Codecov reports failure as some lines are removed (thus decreasing covered in covered/(covered+not covered)).

@chaeyeunpark chaeyeunpark changed the title Update handling data types in Python Update handling statevector data types in Python May 10, 2022
Copy link
Member

@mlxd mlxd 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 on this @chaeyeunpark
It'll be great to finally have complete fp32 support across the board.

return LightningQubit(wires=1)
@pytest.fixture(scope="function", params=[np.complex64, np.complex128])
def qubit_device_1_wire(request):
return LightningQubit(wires=1, c_dtype=request.param)
Copy link
Member

Choose a reason for hiding this comment

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

Great job on adding this change


def test_interface_torch(self, dev):
"""Test if gradients agree between the adjoint and finite-diff methods when using the
Torch interface"""
if dev.R_DTYPE == np.float32 and not lq._CPP_BINARY_AVAILABLE:
pytest.skip("Skip as default.qubit with a single precision floating point works poorly")
Copy link
Member

Choose a reason for hiding this comment

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

Is there a better descriptor here for what is wrong? Rather than "works poorly",maybe reduced performance, unsupported operations, etc? I don't think this is an issue, but may be useful to know the problem for future fixes.

Copy link
Contributor Author

@chaeyeunpark chaeyeunpark May 10, 2022

Choose a reason for hiding this comment

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

Sure. It is basically finite-diff with a single-precision floating-point type produces a huge error. By adjusting h, I could make it better for lightning.qubit but not for default.qubit. Proably, the gate implementations in default.qubit are not much error stable. Anyway, I will update the message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay it seems like setting h=2e-3 in finte-diff reduces errors. I will use this set-up.

@chaeyeunpark chaeyeunpark merged commit b58394e into master May 10, 2022
@chaeyeunpark chaeyeunpark deleted the fix_dtype_py branch May 10, 2022 16:15
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.

2 participants