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

Standardize eigvals to be floats #5370

Closed
wants to merge 8 commits into from
Closed

Conversation

lillian542
Copy link
Contributor

@lillian542 lillian542 commented Mar 12, 2024

Context:
The dtype for qml.sample(Identity(0)) doesn't match the dtype for its eigvals, and it breaks JAX-JIT. Some observables use int, some use float, depending on the dtype of eigvals. We're opting to standardize this to be floats.

Description of the Change:
Change eigvals of X, Y, Z and Hadamard to be floats. This will also affect Tensor, which previously was int if it was composed only of those observables.

The generation of samples is modified in _qubit_device and on SampleMP, because it wasn't actually using the eigvals for these 4 operators.

Benefits:
We can do this:

@qml.qnode(qml.device('default.qubit', shots=50))
def circuit(x):
    qml.RX(x, wires=0)
    return qml.sample(op=qml.I(0))
    
jax.jit(circuit)(jax.numpy.array(0.5))

and we are less likely to have similar/related bugs in the future.

Possible Drawbacks:
Samples that used to be int will become float

Related GitHub Issues:
#5369

@lillian542 lillian542 linked an issue Mar 12, 2024 that may be closed by this pull request
1 task
Copy link
Contributor

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.

@lillian542 lillian542 marked this pull request as ready for review March 12, 2024 20:50
@lillian542
Copy link
Contributor Author

[sc-58742]

@lillian542 lillian542 changed the title Make Identity.eigvals dtype int Standardize eigvals to be floats Mar 13, 2024
@trbromley trbromley modified the milestone: v0.36 Apr 19, 2024
@lillian542 lillian542 changed the base branch from master to v0.36.0-rc0 April 30, 2024 20:07
@trbromley
Copy link
Contributor

Is this related to or replaced by #5607?

@lillian542
Copy link
Contributor Author

lillian542 commented May 1, 2024

Is this related to or replaced by #5607?

Replaced by, that one is old enough that I looked at the merge conflicts and decided it would be less work to just copy over the changes in a new PR instead and then start fixing tests

@lillian542
Copy link
Contributor Author

Out of date, replaced by #5607

@lillian542 lillian542 closed this May 1, 2024
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.

[BUG] Identity eigvals type doesn't match it's expected numeric type
2 participants