-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidated LDP imports into
ldp_shims
module (#772)
- Loading branch information
1 parent
d22eda1
commit a4db19a
Showing
5 changed files
with
68 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Centralized place for lazy LDP imports.""" | ||
|
||
__all__ = [ | ||
"HAS_LDP_INSTALLED", | ||
"Agent", | ||
"Callback", | ||
"ComputeTrajectoryMetricsMixin", | ||
"HTTPAgentClient", | ||
"Memory", | ||
"MemoryAgent", | ||
"ReActAgent", | ||
"RolloutManager", | ||
"SimpleAgent", | ||
"SimpleAgentState", | ||
"UIndexMemoryModel", | ||
"_Memories", | ||
"discounted_returns", | ||
"set_training_mode", | ||
] | ||
|
||
from pydantic import TypeAdapter | ||
|
||
try: | ||
from ldp.agent import ( | ||
Agent, | ||
HTTPAgentClient, | ||
MemoryAgent, | ||
ReActAgent, | ||
SimpleAgent, | ||
SimpleAgentState, | ||
) | ||
from ldp.alg import Callback, ComputeTrajectoryMetricsMixin, RolloutManager | ||
from ldp.graph.memory import Memory, UIndexMemoryModel | ||
from ldp.graph.op_utils import set_training_mode | ||
from ldp.utils import discounted_returns | ||
|
||
_Memories = TypeAdapter(dict[int, Memory] | list[Memory]) # type: ignore[var-annotated] | ||
|
||
HAS_LDP_INSTALLED = True | ||
except ImportError: | ||
HAS_LDP_INSTALLED = False | ||
|
||
class ComputeTrajectoryMetricsMixin: # type: ignore[no-redef] | ||
"""Placeholder parent class for when ldp isn't installed.""" | ||
|
||
class Callback: # type: ignore[no-redef] | ||
"""Placeholder parent class for when ldp isn't installed.""" | ||
|
||
RolloutManager = None # type: ignore[assignment,misc] | ||
discounted_returns = None # type: ignore[assignment] |
This file contains 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
This file contains 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
This file contains 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
This file contains 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