How pyrddlgym-project/pyrddlgym works
Based on our analysis of the file structure and README, the pyRDDLGym project is a Python toolkit that automatically generates OpenAI Gym environments from RDDL description files. It serves as both a parser/compiler for RDDL and as a simulator/visualization framework for dynamic stochastic environments. The architecture is modular, with clearly separated components for parsing, compiling, simulation, visualization, and debugging, and it also provides integration points for various planners and external optimizers (like JaxPlan, GurobiPlan, PROST, and RL toolkits).
Main Components
• Environment Loader / Maker: The entry point (via pyRDDLGym.make()) that instantiates an environment from either preloaded domains (via rddlrepository) or custom RDDL files.
• RDDL Parser: Found inside the pyRDDLGym/core/parser directory. This component is responsible for reading RDDL domain and instance files and converting them into internal representations.
• Compiler: Under pyRDDLGym/core/compiler. It takes the parsed RDDL data and builds models (including extracting DBNs and XADDs) which describe transition dynamics.
• Simulation Engine: Located in modules such as pyRDDLGym/core/simulator and pyRDDLGym/core/env.py. This part is responsible for environment interactions (e.g., implementing reset, step, and simulation of episodes).
• Visualizer & Debug Tools: In pyRDDLGym/core/visualizer and pyRDDLGym/core/debug. Responsible for rendering environments (both live and movie recording via MovieGenerator) and logging internal states.
• Policy Handling: Found in pyRDDLGym/core/policy. Provides built-in agents (e.g., RandomAgent) to demonstrate and test environment interactions.
• Server Component (optional): Found in pyRDDLGym/core/server.py, which is used for communication over TCP when running environments in a networked or distributed setup.
• Examples: The example scripts bundled (in pyRDDLGym/examples) show various use cases (for instance, running environments with both automated and explicit interaction).
Representing the Relationships and Data Flow
• Optionally, include a branch that integrates with external planning modules (JaxPlan, GurobiPlan, PROST, and RL frameworks) to emphasize the pluggable nature.
• If applicable, include a Server module handling TCP communications (if running as a networked environment).
Architectural Patterns and Design Principles
• The system follows a modular design where each core functionality (parsing, compiling, simulation, visualization) is separated into its specialty module.
• Encourage clear separation of concerns, for instance by distinguishing between data processing (parser/compiler) and runtime execution (simulation/visualization).
• The use of subclassing is highlighted in custom visualizer creation (via pyRDDLGym.core.visualizer.viz.BaseViz), suggesting a strategy design pattern for extensibility.
• Dependency injection is used in some components (for example, passing a custom MovieGenerator to the visualizer).