rlightning.engine.base_engine

Base engine module for reinforcement learning training loops.

This module defines the abstract base class for all RL engines, providing the common interface for training, rollout, and weight updates.

class rlightning.engine.base_engine.BaseEngine(config: MainConfig, env_group: EnvGroup | None = None, policy_group: PolicyGroup | None = None, buffer: DataBuffer | None = None)[source]

Bases: ABC

Abstract base class for reinforcement learning engines.

This class defines the common interface for all RL engines, including methods for warm-up, training, rollout, weight updates, and timing.

buffer: DataBuffer
abstractmethod evaluate(*args: Any, **kwargs: Any) None[source]

User defined evaluation to collect experience.

Parameters:
  • *args – Variable positional arguments.

  • **kwargs – Variable keyword arguments.

iter_epochs(num_epochs: int) iter[source]

An iterator that yields epoch numbers up to num_epochs.

Parameters:

num_epochs (int) – The number of epochs to iterate through.

Returns:

An iterator over epoch numbers.

Return type:

iter

print_timing_summary(reset: bool = False) None[source]

Print timing summary for profiling.

Parameters:

reset – If True, reset timing statistics after printing.

abstractmethod rollout(*args: Any, **kwargs: Any) None[source]

User defined rollout to collect experience.

Parameters:
  • *args – Variable positional arguments.

  • **kwargs – Variable keyword arguments.

abstractmethod run() None[source]

Run the RL training flow.

This method should execute the complete RL training flow, coordinating rollout, training, and weight updates.

sync_weights() None[source]

sync weights from train policy to eval policy.

Parameters:

policy_group – Policy group containing train and eval policies.

timing_raw: dict[str, dict[str, Any]]
abstractmethod train() None[source]

User defined training on collected experience.

Parameters:
  • *args – Variable positional arguments.

  • **kwargs – Variable keyword arguments.

abstractmethod update_dataset() None[source]

User defined dataset update from buffer to train policy.

abstractmethod warm_up() None[source]

Initialize and perform dummy run for constructing RL dataflow.

This method should initialize all components (environment, policy, buffer) and perform a dummy training iteration to ensure the dataflow is properly constructed.