Add unit-aware gradients and corresponding documentation#66
Merged
chaoming0625 merged 4 commits intomainfrom Nov 25, 2024
Merged
Add unit-aware gradients and corresponding documentation#66chaoming0625 merged 4 commits intomainfrom
chaoming0625 merged 4 commits intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces the
autogradmodule to thebrainunitpackage, which includes functionality for automatic differentiation. The key changes involve adding new files for theautogradmodule, updating the__init__.pyfile to include the new module, and modifying existing methods for better compatibility.New
autogradmodule:brainunit/autograd/__init__.py: Added theautogradmodule with functions for automatic differentiation, such asvalue_and_grad,grad,vector_grad,jacobian,jacrev,jacfwd, andhessian.brainunit/autograd/_hessian.py: Implemented thehessianfunction, which computes the Hessian of a function with physical unit awareness.brainunit/autograd/_jacobian.py: Implementedjacrev,jacfwd, andjacobianfunctions for computing Jacobians with physical unit awareness.Updates to existing files:
brainunit/__init__.py: Imported the newautogradmodule and updated the__all__list to includeautograd. [1] [2]brainunit/_base.py: Modified thereshapemethod signature to accept a singleshapeargument instead of variadic arguments.New tests:
brainunit/autograd/_hessian_test.py: Added unit tests for thehessianfunction to verify its correctness with scalar, vector, and dictionary functions.brainunit/autograd/_jacobian_test.py: Added unit tests forjacrevandjacfwdfunctions to ensure they handle various cases correctly, including auxiliary outputs and multiple arguments.