fix(examples): make Drucker-Prager triaxial 2D strain embedding vmap-safe#21
Open
kilickursat wants to merge 1 commit into
Open
Conversation
…safe Signed-off-by: Kursat Kilic <kilic_kursat@hotmail.com>
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.
Summary
Makes the 2D (plane-strain) branch of the example-local
DruckerPragerPlasticity._small_strain_3dhelper safe for batched inputs andunder
vmap.The helper previously embedded the in-plane strain into a 3x3 tensor with an
in-place slice assignment into a freshly allocated tensor:
energy()applieselement_energyper quadrature point undervmap, and thatin-place embed raises
RuntimeError: vmap: inplace arithmetic ... is not possiblewhen the 2D branch is exercised. The merged triaxial example only runsin 3D, so this path was never hit, but it blocks reusing the same constitutive
helper for a 2D problem.
Change
torch.nn.functional.pad,which is correct for both batched inputs and under
vmap._small_strain_3dwith a batched 2D gradient and undertorch.vmap.Validation
Ran locally:
pytest tests/assemble/test_drucker_prager_triaxial_example.py -vpython examples/solid/geomechanics/drucker_prager_triaxial/drucker_prager_triaxial.py --no-plot --steps 8Example + test only. No public API changes and no core TensorMesh code changes.