-
Notifications
You must be signed in to change notification settings - Fork 35
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
qml.Hamiltonian
inside of a pure_callback
doesn't work
#1093
Comments
Your traceback seems to indicate the error occurs outside of the callback |
@dime10 I told @isaacdevlugt to create an issue so that I can narrow it down for him. This is not urgent. |
Thanks @dime10! Yes there's a bit of context missing 😅 |
Note that the following does work (assuming you know in advance how many terms the Hamiltonian has): data, shape = jax.tree_util.tree_flatten(H)
def get_hamiltonian(coordinates):
molecule = qml.qchem.Molecule(["H", "H"], coordinates)
H, qubits = qml.qchem.molecular_hamiltonian(molecule)
return H
@qml.qjit
def f(coordinates):
return catalyst.pure_callback(get_hamiltonian, result_type=[jax.ShapeDtypeStruct([], dtype=float)] * 15)(coordinates) >>> f(coordinates)
[Array(9.7983828, dtype=float64),
Array(0.3060033, dtype=float64),
Array(0.3060033, dtype=float64),
Array(0.19345955, dtype=float64),
Array(-0.74817268, dtype=float64),
Array(0.15271652, dtype=float64),
Array(0.19164807, dtype=float64),
Array(0.03893155, dtype=float64),
Array(-0.03893155, dtype=float64),
Array(-0.03893155, dtype=float64),
Array(0.03893155, dtype=float64),
Array(-0.74817268, dtype=float64),
Array(0.19164807, dtype=float64),
Array(0.15271652, dtype=float64),
Array(0.20376722, dtype=float64)] However, attempting to include the pytree struct of the Hamiltonian in the @isaacdevlugt something to note here: the underlying solution is that we should ensure that |
cc @soranjh |
@josh146 agreed that |
Issue description
Trying to use
qml.qchem.molecular_hamiltonian
inside of a callback and it's not working.Expected behavior: I expect that generating a
Hamiltonian
in a callback should be possible since aHamiltonian
is a pytree.Actual behavior: It doesn't work.
Reproduces how often: 100%
System information:
Source code and tracebacks
Additional information
Any additional information, configuration or data that might be necessary
to reproduce the issue.
The text was updated successfully, but these errors were encountered: