Skip to content

Commit

Permalink
[gym/common] Improve support of dynamic computation graph.
Browse files Browse the repository at this point in the history
  • Loading branch information
duburcqa committed Apr 3, 2024
1 parent 4e46bbd commit 894d739
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
22 changes: 13 additions & 9 deletions python/gym_jiminy/common/gym_jiminy/common/bases/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,27 @@ def cache(self, cache: SharedCache[ValueT]) -> None:
self._cache = cache
self._has_cache = True

@property
def is_active(self) -> bool:
def is_active(self, any: bool = False) -> bool:

Check warning on line 217 in python/gym_jiminy/common/gym_jiminy/common/bases/quantity.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

python/gym_jiminy/common/gym_jiminy/common/bases/quantity.py#L217

Redefining built-in 'any'
"""Whether this quantity is considered active, namely `initialize` has
been called at least once since previous tracking reset, either by this
exact instance or any identical quantity if shared cache is available.
been called at least once since previous tracking reset.
:param any: False to check only if this exact instance is active, True
if any of the identical quantities (sharing the same cache)
is considered sufficient.
Optional: False by default.
"""
if self._cache is None:
if not any or self._cache is None:
return self._is_active
return any(owner._is_active for owner in self._cache.owners)
return __builtins__.any(
owner._is_active for owner in self._cache.owners)

def get(self) -> ValueT:
"""Get cached value of requested quantity if available, otherwise
evaluate it and store it in cache.
This quantity is considered active as soon as this method has been
called at least once since previous tracking reset. The corresponding
property `is_active` will be true even before calling `initialize`.
called at least once since previous tracking reset. The method
`is_active` will be return true even before calling `initialize`.
.. warning::
This method is not meant to be overloaded.
Expand Down Expand Up @@ -289,7 +293,7 @@ def reset(self, reset_tracking: bool = False) -> None:

# Reset all requirements first
for quantity in self.requirements.values():
quantity.reset()
quantity.reset(reset_tracking)

# More work has to be done if shared cache is available and has value
if self._has_cache:
Expand Down
13 changes: 9 additions & 4 deletions python/gym_jiminy/common/gym_jiminy/common/quantities/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,15 @@ def initialize(self) -> None:
self.frame_names = {self.parent.frame_name}
if self.cache:
for owner in self.cache.owners:
parent = owner.parent
assert isinstance(parent, EulerAnglesFrame)
if parent.is_active:
self.frame_names.add(parent.frame_name)
# We only consider active instances of `_BatchEulerAnglesFrame`
# instead of their corresponding parent `EulerAnglesFrame`.
# This is necessary because a derived quantity may feature
# `_BatchEulerAnglesFrame` as a requirement without actually
# relying on it depending on whether it is part of the optimal
# computation path at the time being or not.
if owner.is_active(any=False):
assert isinstance(owner.parent, EulerAnglesFrame)
self.frame_names.add(owner.parent.frame_name)

# Re-allocate memory as the number of frames is not known in advance.
# Note that Fortran memory layout (column-major) is used for speed up
Expand Down
2 changes: 1 addition & 1 deletion python/jiminy_py/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def finalize_options(self) -> None:
# Panda3d is NOT supported by PyPy even if built from source.
# - 1.10.12 fixes numerous bugs
# - 1.10.13 crashes when generating wheels on MacOS
"panda3d>=1.10.14",
"panda3d>=1.10.13",
# Photo-realistic shader for Panda3d to improve rendering of meshes.
# - 0.11.X is not backward compatible.
"panda3d-simplepbr==0.11.2",
Expand Down

0 comments on commit 894d739

Please sign in to comment.