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

equistore operation dot does not support gradients #100

Open
agoscinski opened this issue Jan 20, 2023 · 6 comments
Open

equistore operation dot does not support gradients #100

agoscinski opened this issue Jan 20, 2023 · 6 comments
Labels
documentation Improvements or additions to documentation Operations Related to metatensor-operations in Python

Comments

@agoscinski
Copy link
Contributor

Is there a reason why it is not supported? Because the error message specifically talks about the second tensor map
https://github.com/lab-cosmo/equistore/blob/e65cd07d2f0d5aefa41a7b2beade835b9b1dc03b/python/src/equistore/operations/dot.py#L49
and then the values and gradients are dotted together
https://github.com/lab-cosmo/equistore/blob/e65cd07d2f0d5aefa41a7b2beade835b9b1dc03b/python/src/equistore/operations/dot.py#L63
I cannot make sense out of it

@agoscinski agoscinski added documentation Improvements or additions to documentation Python-API Related to the Python bindings to "core" labels Jan 20, 2023
@Luthaf
Copy link
Contributor

Luthaf commented Jan 20, 2023

The second tensor map is the "weights" in x = dot(A, w), so there are no gradients associated with them for now. We could add support for gradients on both sides of a dot, but that might require adding support for double gradients in equistore (to store dot(grad A, grad w))

@agoscinski
Copy link
Contributor Author

agoscinski commented Jan 23, 2023

Ah I see, I feel like this operation alone is too limiting, but I need to think about this more. Seems to be far from trivial to extend it in an understandable way.

But regarding this issue, could we just add a bit of documentation for this? like this one

    Computes the dot product of two :py:class:`TensorMap` using the values of B
    for the matrix product with A and its gradients

    .. math::
       C = A @ B
       ∇C = ∇A @ B

@Luthaf
Copy link
Contributor

Luthaf commented Jan 23, 2023

Adding more documentation works for me!

@agoscinski
Copy link
Contributor Author

Should I do a separate PR for this? Seems it could be also added to #91

@Luthaf
Copy link
Contributor

Luthaf commented Jan 23, 2023

This is more about API documentation than user tutorials/explanation, so I would do it in a quick separate PR.

@ceriottm
Copy link
Contributor

Imo adding support for gradients shouldn't be too hard. If B does not have gradients, then grad(A.B) is grad(A).B, if B also has gradients then it's grad(A).B + A.grad(B).

@agoscinski agoscinski changed the title equistore operatons dot does not support gradients equistore operations dot does not support gradients Jan 27, 2023
@agoscinski agoscinski changed the title equistore operations dot does not support gradients equistore operation dot does not support gradients Jan 27, 2023
@Luthaf Luthaf added Operations Related to metatensor-operations in Python and removed Python-API Related to the Python bindings to "core" labels Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation Operations Related to metatensor-operations in Python
Projects
None yet
Development

No branches or pull requests

4 participants