-
Notifications
You must be signed in to change notification settings - Fork 616
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
[BUG] Split non commuting fails with autograd requires_grad=False
coefficients
#5924
Comments
Note that the issue is not particularily with the qulacs device, but with Sticking
|
This may also be related to #5824 |
Thanks @albi3ro! I suspected it was something to do with the Hamiltonian, but didn't realize it was because Is the bug present with just |
It has less to do with the qulacs simulator, and more about a device that doesn't natively support hamiltonians. Why |
oops, typo in my message, have updated it! |
Never mind. This has nothing to do with The issue can also be replicated with:
|
requires_grad=False
coefficients
Thanks, that's great! Much more minimal now |
Sorry for re-opening this issue. The original code block (w/ minor changes) still raises a
Error:
|
Update: After some investigation with the help of @soranjh, it appears that the error is raised if the given Hamiltonian has an identity term with a non-zero coefficient. E.g.
A proposed solution is in #6022 |
**Context:** Described in #5924, but to summarize, `split_non_commuting` does not handle Identity terms with non-trainable coefficients well, leading to an unexpected `NonDifferentiableError`. Although the coefficients of Identity terms (also known as `offset`) is assumed to be a float given the type-hinting of `_sum_terms()`, it seems that this is not the case. It is also not the case for `coeffs` which is assumed to be a list of floats but can actually be a list of tensors. **Description of the Change:** Fixes #5924 by setting `requires_grad` to `True` for offsets when autograd is in use. **Benefits:** Fixes #5924 **Possible Drawbacks:** May have unintended side effects, or perhaps we would like to coerce `offset` and `coeffs` to be the types in the type hint. **Related GitHub Issues:** [sc-67508] --------- Co-authored-by: Christina Lee <[email protected]> Co-authored-by: Astral Cai <[email protected]>
**Context:** Described in #5924, but to summarize, `split_non_commuting` does not handle Identity terms with non-trainable coefficients well, leading to an unexpected `NonDifferentiableError`. Although the coefficients of Identity terms (also known as `offset`) is assumed to be a float given the type-hinting of `_sum_terms()`, it seems that this is not the case. It is also not the case for `coeffs` which is assumed to be a list of floats but can actually be a list of tensors. **Description of the Change:** Fixes #5924 by setting `requires_grad` to `True` for offsets when autograd is in use. **Benefits:** Fixes #5924 **Possible Drawbacks:** May have unintended side effects, or perhaps we would like to coerce `offset` and `coeffs` to be the types in the type hint. **Related GitHub Issues:** [sc-67508] --------- Co-authored-by: Christina Lee <[email protected]> Co-authored-by: Astral Cai <[email protected]>
The following code, which uses the
append_gate
transformation present withinqml.optimize.AdaptiveOptimizer
, works fine withdefault.qubit
:However, change the device to
qulacs.simulator
(which uses the old device API), and an error is raised:This means that
qml.AdapativeOptimizer
cannot be used with devices likequlacs.simulator
.Note that this error appears to be peculiar to the following situation:
H = qml.qchem.molecular_hamiltonian(...)
qml.expval(H)
.If the Hamiltonian is generated manually, the above code works correctly on both devices.
The text was updated successfully, but these errors were encountered: