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

Return qchem Hamiltonians with real dtype coeffs #4639

Merged
merged 9 commits into from Oct 13, 2023
Merged

Conversation

soranjh
Copy link
Contributor

@soranjh soranjh commented Oct 2, 2023

Context:
The qchem Hamiltonians built with the new qml.jordan_wigner function have complex coefficients with zero imaginary components. This PR removes the imaginary part if it is less than a pre-defined tolerance.

Description of the Change:
The qml.jordan_wigner function is modified to optionally remove the imaginary components of the computed qubit operator.

Benefits:

Possible Drawbacks:

Related GitHub Issues:

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2023

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.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.

@soranjh
Copy link
Contributor Author

soranjh commented Oct 2, 2023

[sc-44462]

@soranjh soranjh marked this pull request as ready for review October 5, 2023 14:40
@soranjh soranjh changed the title [wip] return qchem Hamiltonians with real dtype coeffs Return qchem Hamiltonians with real dtype coeffs Oct 5, 2023
@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (ea7e1d4) 99.63% compared to head (3588acd) 99.63%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4639   +/-   ##
=======================================
  Coverage   99.63%   99.63%           
=======================================
  Files         376      376           
  Lines       33672    33678    +6     
=======================================
+ Hits        33548    33554    +6     
  Misses        124      124           
Files Coverage Δ
pennylane/fermi/conversion.py 100.00% <100.00%> (ø)
pennylane/qchem/dipole.py 100.00% <100.00%> (ø)
pennylane/qchem/observable_hf.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Right now tol=0 behaves the same as tol=None; I would expect tol=0 to remove complex terms that were exactly 0, so I think this should be updated.

I guess it's being indirectly tested through the observable_hf test file, but could we add a small test explicitly testing just this for tol of None, 0, and something small? Something that would catch the current behaviour where 0 is treated as None.

Also needs a changelog entry :)

@timmysilv
Copy link
Contributor

I second Lillian's sentiment - keeping the default to None but changing if tol to if tol is not None should meet the requirements you're describing (preferring opt-in over opt-out to this behaviour), and that would work for me

@soranjh
Copy link
Contributor Author

soranjh commented Oct 12, 2023

Right now tol=0 behaves the same as tol=None; I would expect tol=0 to remove complex terms that were exactly 0, so I think this should be updated.

I guess it's being indirectly tested through the observable_hf test file, but could we add a small test explicitly testing just this for tol of None, 0, and something small? Something that would catch the current behaviour where 0 is treated as None.

Also needs a changelog entry :)

Added the test and the changelog.

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

🎉

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.

🚀

@soranjh soranjh merged commit 7af90b4 into master Oct 13, 2023
39 checks passed
@soranjh soranjh deleted the fermi_mapp_realcoeffs branch October 13, 2023 13:27
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