Skip to content

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Oct 6, 2025

Context:

Noticed warnings in the VQE spin sectors demo about having both autograd and jax data. But we shouldn't have ever been dealing with autograd data, so there shouldn't have been a warning. The problem was that molecular_hamiltonian was promoting numpy data to autograd.

Description of the Change:

Doesn't promote data to autograd when it is numpy data.

Raising an error if the data in an unsupported type.

Benefits:

Fewer strange warnings in user workflows.

Possible Drawbacks:

Related GitHub Issues:

[sc-100883]

andrijapau and others added 3 commits October 6, 2025 14:10
Same as last release:
#7798. Created via
automated script.

[sc-100867]
Automatic update of stable requirement files to snapshot valid python
environments.

Because bots are not able to trigger CI on their own, please do so by
pushing an empty commit to this branch using the following command:

```
git commit --allow-empty -m 'trigger ci'
```

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Mudit Pandey <[email protected]>
Copy link
Contributor

github-actions bot commented Oct 6, 2025

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 soranjh self-requested a review October 6, 2025 17:05
Copy link

codecov bot commented Oct 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (v0.43.0-rc0@36136f5). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff               @@
##             v0.43.0-rc0    #8410   +/-   ##
==============================================
  Coverage               ?   99.42%           
==============================================
  Files                  ?      584           
  Lines                  ?    61242           
  Branches               ?        0           
==============================================
  Hits                   ?    60891           
  Misses                 ?      351           
  Partials               ?        0           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

interface_args = [{"like": "autograd", "requires_grad": requires_grad}, {"like": "jax"}][
use_jax
]
interface = qml.math.get_deep_interface((coordinates, alpha, coeff))
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 assuming that all 3 input args have the same type? e.g., what happens if coordinates is np array but one of the others is jnp array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, good catch. I had been thinking get_deep_interface was just get_interface but on leaves. But forgot that is just takes the first interface it finds. Updated.

def test_molecular_hamiltonian_numpy_data():
"""Test that if numpy data is used with molecular hamiltonian, that numpy data is outputted."""
symbols = ["H", "H"]
coordinates = np.array([0.0, 0.0, -0.6614, 0.0, 0.0, 0.6614])
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please also use the more common format as well:
coordinates = np.array([[0.0, 0.0, -0.6614], [0.0, 0.0, 0.6614]])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using the 2D array instead now.

Comment on lines 558 to 564
interface = qml.math.get_deep_interface((coordinates, alpha, coeff))
if interface == "autograd":
interface_args = {"like": "autograd", "requires_grad": requires_grad}
elif interface in {"numpy", "jax"}:
interface_args = {"like": interface}
else:
raise ValueError(f"unsupported interface {interface} for molecular_hamiltonian")
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious how this fixes the numpy to autograd promoting issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before, if it wasn't jax, then it was autograd. Now, if it's numpy, then it stays numpy.

@andrijapau andrijapau added this to the v0.43 milestone Oct 6, 2025
@andrijapau
Copy link
Contributor

Should this be targetting v0.43.0-rc0?

@albi3ro albi3ro changed the base branch from master to v0.43.0-rc0 October 7, 2025 14:24
@albi3ro albi3ro requested a review from a team as a code owner October 7, 2025 14:24
@albi3ro albi3ro requested review from soranjh and astralcai October 7, 2025 14:24
Copy link
Contributor

Choose a reason for hiding this comment

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

You might have to rebase this branch locally, as it's showing changes from master.

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.

4 participants