tensor-optix 2.0.3__tar.gz → 2.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/PKG-INFO +50 -5
  2. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/README.md +49 -4
  3. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/pyproject.toml +1 -1
  4. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/pytorch/torch_evaluator.py +9 -9
  5. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/tensorflow/tf_evaluator.py +9 -9
  6. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/tf_dqn.py +11 -7
  7. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/tf_sac.py +14 -10
  8. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/tf_td3.py +19 -9
  9. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_dqn.py +9 -5
  10. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_rainbow_dqn.py +9 -5
  11. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_recurrent_ppo.py +19 -1
  12. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_sac.py +9 -5
  13. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_td3.py +17 -7
  14. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/callbacks/tensorboard_callback.py +7 -0
  15. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/callbacks/wandb_callback.py +7 -0
  16. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/cli.py +8 -0
  17. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/config.py +50 -8
  18. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/backoff_scheduler.py +9 -3
  19. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/base_evaluator.py +4 -1
  20. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/checkpoint_registry.py +6 -1
  21. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/diagnostic_controller.py +2 -1
  22. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/ensemble_agent.py +12 -0
  23. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/loop_controller.py +56 -47
  24. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/obs_utils.py +120 -120
  25. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/policy_manager.py +32 -2
  26. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/replay_buffer.py +29 -1
  27. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/reward_shape.py +16 -10
  28. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/distributed/async_learner.py +9 -0
  29. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/encoders/__init__.py +15 -15
  30. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/encoders/obs_encoder.py +229 -229
  31. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/encoders/obs_encoder_tf.py +80 -80
  32. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/factory.py +64 -10
  33. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/callback.py +19 -0
  34. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/provenance.py +19 -7
  35. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml/loss_registry.py +2 -1
  36. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/__init__.py +53 -53
  37. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/adapters/flax_model.py +230 -230
  38. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/adapters/tf_model.py +208 -208
  39. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/adapters/torch_model.py +241 -241
  40. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/base_model.py +150 -150
  41. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/lr_schedules.py +67 -67
  42. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/metrics.py +201 -188
  43. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/metrics_impl/classification.py +101 -101
  44. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/metrics_impl/regression.py +46 -46
  45. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/trainer.py +240 -207
  46. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/transfer.py +152 -152
  47. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/__init__.py +34 -34
  48. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/aec_pipeline.py +191 -173
  49. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/multi_agent_episode.py +18 -18
  50. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/multi_agent_runtime.py +53 -53
  51. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/parallel_pipeline.py +145 -145
  52. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/multi_agent/seat_env.py +81 -81
  53. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/selector.py +9 -3
  54. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/agent/graph_agent.py +74 -15
  55. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/controller/topology_controller.py +16 -4
  56. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/graph/neuron_graph.py +58 -2
  57. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/graph/topology_ops.py +51 -16
  58. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/hebbian.py +45 -4
  59. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/neuromodulator.py +12 -0
  60. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizer.py +17 -10
  61. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/backoff_optimizer.py +13 -4
  62. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/spsa_optimizer.py +18 -3
  63. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/pipeline/batch_pipeline.py +5 -0
  64. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/pipeline/live_pipeline.py +30 -6
  65. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/pipeline/vector_pipeline.py +19 -2
  66. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/baseline.py +8 -0
  67. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/live_runtime.py +12 -4
  68. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/pool.py +36 -1
  69. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/worker.py +7 -0
  70. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/selection/selector.py +17 -1
  71. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/simple.py +11 -1
  72. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/grammar.py +8 -0
  73. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/worker.py +14 -0
  74. tensor_optix-2.0.4/tensor_optix/utils/console.py +28 -0
  75. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/PKG-INFO +50 -5
  76. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/SOURCES.txt +1 -0
  77. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/setup.cfg +0 -0
  78. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/__init__.py +0 -0
  79. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/__init__.py +0 -0
  80. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/jax/__init__.py +0 -0
  81. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/jax/flax_agent.py +0 -0
  82. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/jax/flax_evaluator.py +0 -0
  83. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/pytorch/__init__.py +0 -0
  84. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/pytorch/torch_agent.py +0 -0
  85. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/tensorflow/__init__.py +0 -0
  86. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/adapters/tensorflow/tf_agent.py +0 -0
  87. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/__init__.py +0 -0
  88. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/flax_ppo.py +0 -0
  89. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/tf_ppo.py +0 -0
  90. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/tf_ppo_continuous.py +0 -0
  91. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_ppo.py +0 -0
  92. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/algorithms/torch_ppo_continuous.py +0 -0
  93. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/callbacks/__init__.py +0 -0
  94. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/callbacks/rich_dashboard.py +0 -0
  95. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/__init__.py +0 -0
  96. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/async_callback.py +0 -0
  97. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/base_agent.py +0 -0
  98. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/base_optimizer.py +0 -0
  99. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/base_pipeline.py +0 -0
  100. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/checkpoint_confirmation.py +0 -0
  101. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/device.py +0 -0
  102. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/her_buffer.py +0 -0
  103. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/meta_controller.py +0 -0
  104. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/noisy_linear.py +0 -0
  105. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/normalizers.py +0 -0
  106. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/regime_detector.py +0 -0
  107. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/resume_state.py +0 -0
  108. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/trajectory_buffer.py +0 -0
  109. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/core/types.py +0 -0
  110. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/distributed/__init__.py +0 -0
  111. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/distributed/vtrace.py +0 -0
  112. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/exploration/__init__.py +0 -0
  113. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/exploration/rnd.py +0 -0
  114. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/__init__.py +0 -0
  115. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/records.py +0 -0
  116. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/schema.py +0 -0
  117. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ledger/store.py +0 -0
  118. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml/__init__.py +0 -0
  119. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml/dataset_pipeline.py +0 -0
  120. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml/ml_agent.py +0 -0
  121. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/adapters/__init__.py +0 -0
  122. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/ml_core/metrics_impl/__init__.py +0 -0
  123. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/__init__.py +0 -0
  124. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/abstention.py +0 -0
  125. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/features.py +0 -0
  126. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/pooling.py +0 -0
  127. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/nanonets/smalln.py +0 -0
  128. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/__init__.py +0 -0
  129. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/agent/__init__.py +0 -0
  130. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/brain_network.py +0 -0
  131. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/controller/__init__.py +0 -0
  132. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/controller/topology_callback.py +0 -0
  133. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/graph/__init__.py +0 -0
  134. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/graph/neuron.py +0 -0
  135. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/optimizer/__init__.py +0 -0
  136. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/neuroevo/optimizer/topology_aware_adam.py +0 -0
  137. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/__init__.py +0 -0
  138. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/adaptive_optimizer.py +0 -0
  139. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/momentum_optimizer.py +0 -0
  140. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/optimizers/pbt_optimizer.py +0 -0
  141. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/orchestrator.py +0 -0
  142. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/pipeline/__init__.py +0 -0
  143. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/__init__.py +0 -0
  144. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/experiment_stage.py +0 -0
  145. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/observer.py +0 -0
  146. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/runtime/promote.py +0 -0
  147. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/__init__.py +0 -0
  148. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/_mp_common.py +0 -0
  149. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/budget.py +0 -0
  150. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/dedup.py +0 -0
  151. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/isolation.py +0 -0
  152. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/scheduler/retry.py +0 -0
  153. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/selection/__init__.py +0 -0
  154. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/selection/backfill.py +0 -0
  155. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/selection/uncertainty.py +0 -0
  156. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/__init__.py +0 -0
  157. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/candidate.py +0 -0
  158. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/comparator.py +0 -0
  159. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/promotion.py +0 -0
  160. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/strategy/runner.py +0 -0
  161. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/utils/__init__.py +0 -0
  162. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix/utils/window_size.py +0 -0
  163. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/dependency_links.txt +0 -0
  164. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/entry_points.txt +0 -0
  165. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/requires.txt +0 -0
  166. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tensor_optix.egg-info/top_level.txt +0 -0
  167. {tensor_optix-2.0.3 → tensor_optix-2.0.4}/tests/test_ml.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tensor-optix
3
- Version: 2.0.3
3
+ Version: 2.0.4
4
4
  Summary: Autonomous training loop for any sequential learning model — PPO, DQN, SAC, TD3, Rainbow DQN, Recurrent PPO for TensorFlow, PyTorch, and JAX/Flax; distributed async actor-learner (IMPALA + V-trace)
5
5
  Author: sup3rus3r
6
6
  License-Expression: MIT
@@ -162,7 +162,7 @@ pip install tensor-optix[torch]
162
162
  pip install tensor-optix[all]
163
163
  ```
164
164
 
165
- Environment extras: `[box2d]`, `[atari]`, `[mujoco]`
165
+ Environment extras: `[box2d]`, `[atari]`, `[mujoco]`, `[pettingzoo]` (multi-agent)
166
166
  Logging extras: `[wandb]`, `[tensorboard]`
167
167
  Export: `[onnx]`
168
168
 
@@ -194,7 +194,7 @@ All agents implement `BaseAgent` and are interchangeable with `RLOptimizer`.
194
194
 
195
195
  ### Auto-selection
196
196
 
197
- `make_agent` inspects the environment action space and returns a fully constructed agent. Pass an algorithm name as the first argument, or let it be inferred.
197
+ `make_agent` inspects the environment action space and returns a fully constructed agent. Pass an algorithm name as the first argument, or let it be inferred. Observations may be a flat `Box`, an image `Box` `(H, W, C)` (CNN encoder), or a `Dict` of those (see [Encoders](https://sup3rus3r.github.io/tensor-optix/reference/encoders/)).
198
198
 
199
199
  ```python
200
200
  from tensor_optix import make_agent
@@ -280,6 +280,32 @@ pipeline = VectorBatchPipeline(
280
280
  )
281
281
  ```
282
282
 
283
+ Notes:
284
+
285
+ - `VectorBatchPipeline` works with every built-in agent except `TorchRecurrentPPOAgent`: PPO agents compute GAE per env, and the off-policy agents (DQN, Rainbow, SAC, TD3) build replay transitions per env. Envs are created with Gymnasium's `SAME_STEP` autoreset so no action-ignored "reset" transitions enter the training data.
286
+ - `BatchPipeline` resets a recurrent agent's hidden state (`reset_hidden()`) at every episode boundary.
287
+ - `LivePipeline` applies backpressure: when the consumer is slower than the source, the producer waits instead of dropping samples or restarting the stream.
288
+
289
+ ### Multi-agent (PettingZoo)
290
+
291
+ `pip install tensor-optix[torch,pettingzoo]` adds pipelines for PettingZoo's Parallel and AEC (turn-based) APIs. Each seat is an ordinary agent; a window yields one `EpisodeData` per seat.
292
+
293
+ ```python
294
+ from pettingzoo.classic import rps_v2
295
+ from tensor_optix import make_agent
296
+ from tensor_optix.multi_agent import SeatEnvView, AECMultiAgentPipeline, MultiAgentRunner
297
+
298
+ env = rps_v2.env()
299
+ env.reset(seed=0)
300
+ views = {aid: SeatEnvView(env, aid) for aid in env.possible_agents}
301
+ agents = {aid: make_agent(views[aid]) for aid in env.possible_agents}
302
+
303
+ pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
304
+ MultiAgentRunner(pipeline, agents).run(max_windows=500)
305
+ ```
306
+
307
+ In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner` is a minimal collect/learn driver - it does not run the convergence/checkpoint state machine. See [Multi-agent training](https://sup3rus3r.github.io/tensor-optix/guides/multi-agent/).
308
+
283
309
  ---
284
310
 
285
311
  ## The loop
@@ -309,7 +335,20 @@ opt.best_snapshot # -> PolicySnapshot: best weights + EvalMetrics + Hyperparam
309
335
 
310
336
  Loop state transitions: `ACTIVE` -> `COOLING` -> `DORMANT` -> watchdog shutdown or policy spawn.
311
337
 
312
- On shutdown the loop restores best-known weights, not the final checkpoint.
338
+ - Every non-improving eval counts toward `COOLING`/`DORMANT`, for on-policy and off-policy agents alike. While the score is flat the eval interval backs off (`backoff_factor`, default 2.0); set `backoff_factor=1.0` to evaluate every window.
339
+ - At `DORMANT` the loop stops by default. A `PolicyManagerCallback` with spawn budget remaining spawns a variant instead and training continues.
340
+ - `rollback_on_degradation=True` restores the best checkpoint when a degradation is confirmed (`min_consecutive_degradations` consecutive evals below `degradation_threshold x best`), for on-policy agents only - off-policy agents keep their weights because their replay buffer would immediately pull a restored policy back.
341
+ - On shutdown the loop restores best-known weights, not the final checkpoint.
342
+ - `verbose=True` prints a per-eval diagnostic block; it is safe on consoles that cannot render the box-drawing glyphs (they degrade to `?`).
343
+
344
+ ### YAML / CLI
345
+
346
+ ```bash
347
+ tensor-optix validate config.yaml
348
+ tensor-optix train config.yaml agent.learning_rate=1e-3 optimizer.max_episodes=200
349
+ ```
350
+
351
+ The `algorithm` key selects the agent class and must be buildable for the env (e.g. `TorchDQNAgent` needs a discrete action space; a mismatch is a build error, not a silent substitution). See [Configure via YAML / CLI](https://sup3rus3r.github.io/tensor-optix/guides/cli-config/).
313
352
 
314
353
  ---
315
354
 
@@ -372,12 +411,14 @@ best_config = orch.run()
372
411
  from tensor_optix import PolicyManager
373
412
 
374
413
  pm = PolicyManager(registry, max_spawns=4)
375
- cb = pm.as_callback(agent, agent_factory=make_agent)
414
+ cb = pm.as_callback(agent, agent_factory=lambda: make_agent(env)) # zero-argument factory
376
415
  cb.set_stop_fn(opt.stop)
377
416
  opt.add_callback(cb)
378
417
  opt.run()
379
418
  ```
380
419
 
420
+ Each `DORMANT` event with budget remaining spawns a variant and training continues; once the budget is exhausted the callback stops the loop with the best weights restored. A multi-member `EnsembleAgent` combines policies at inference time - for discrete PPO members `act()` returns the averaged probability vector, which you sample or `argmax`.
421
+
381
422
  ---
382
423
 
383
424
  ## Callbacks
@@ -788,6 +829,8 @@ store.finalize_experiment(record.experiment_id, state=ExperimentState.COMPLETED)
788
829
 
789
830
  Writes are idempotent on `experiment_id`, and every method opens a short, single-statement transaction — nothing here ever holds a lock for the duration of training.
790
831
 
832
+ To record an ordinary training run, attach `ExperimentLedgerCallback(store, task_env=..., algorithm=..., checkpoint_dir=...)` (from `tensor_optix.ledger.callback`) to `RLOptimizer`. A run that raises is finalized `FAILED` automatically; an interrupted one `CANCELLED`.
833
+
791
834
  ### Concurrent trial scheduler
792
835
 
793
836
  `ConcurrentTrialScheduler` runs multiple Optuna trials as real OS processes, with the parent process as sole owner of the Optuna study and the ledger.
@@ -804,6 +847,8 @@ scheduler = ConcurrentTrialScheduler(
804
847
  best_params, best_score = scheduler.run()
805
848
  ```
806
849
 
850
+ A worker that dies without reporting (OOM-kill, crash) is detected, retried up to `max_retries` times, and then recorded as `FAILED` - the scheduler never waits on a dead process.
851
+
807
852
  ### Cross-task transfer (Nanonets)
808
853
 
809
854
  `NanonetsSelector` pools evidence from other tasks' ledger history when deciding how to allocate a new task's trial budget — but only when a conservative abstention gate confirms a source task's data is actually comparable (median performance at or above the target's own 95th percentile, both normalized against each task's own solve threshold so differently-scaled/signed scores are never compared on raw terms). When nothing passes the gate, it falls back to the non-learned baseline rather than guess.
@@ -91,7 +91,7 @@ pip install tensor-optix[torch]
91
91
  pip install tensor-optix[all]
92
92
  ```
93
93
 
94
- Environment extras: `[box2d]`, `[atari]`, `[mujoco]`
94
+ Environment extras: `[box2d]`, `[atari]`, `[mujoco]`, `[pettingzoo]` (multi-agent)
95
95
  Logging extras: `[wandb]`, `[tensorboard]`
96
96
  Export: `[onnx]`
97
97
 
@@ -123,7 +123,7 @@ All agents implement `BaseAgent` and are interchangeable with `RLOptimizer`.
123
123
 
124
124
  ### Auto-selection
125
125
 
126
- `make_agent` inspects the environment action space and returns a fully constructed agent. Pass an algorithm name as the first argument, or let it be inferred.
126
+ `make_agent` inspects the environment action space and returns a fully constructed agent. Pass an algorithm name as the first argument, or let it be inferred. Observations may be a flat `Box`, an image `Box` `(H, W, C)` (CNN encoder), or a `Dict` of those (see [Encoders](https://sup3rus3r.github.io/tensor-optix/reference/encoders/)).
127
127
 
128
128
  ```python
129
129
  from tensor_optix import make_agent
@@ -209,6 +209,32 @@ pipeline = VectorBatchPipeline(
209
209
  )
210
210
  ```
211
211
 
212
+ Notes:
213
+
214
+ - `VectorBatchPipeline` works with every built-in agent except `TorchRecurrentPPOAgent`: PPO agents compute GAE per env, and the off-policy agents (DQN, Rainbow, SAC, TD3) build replay transitions per env. Envs are created with Gymnasium's `SAME_STEP` autoreset so no action-ignored "reset" transitions enter the training data.
215
+ - `BatchPipeline` resets a recurrent agent's hidden state (`reset_hidden()`) at every episode boundary.
216
+ - `LivePipeline` applies backpressure: when the consumer is slower than the source, the producer waits instead of dropping samples or restarting the stream.
217
+
218
+ ### Multi-agent (PettingZoo)
219
+
220
+ `pip install tensor-optix[torch,pettingzoo]` adds pipelines for PettingZoo's Parallel and AEC (turn-based) APIs. Each seat is an ordinary agent; a window yields one `EpisodeData` per seat.
221
+
222
+ ```python
223
+ from pettingzoo.classic import rps_v2
224
+ from tensor_optix import make_agent
225
+ from tensor_optix.multi_agent import SeatEnvView, AECMultiAgentPipeline, MultiAgentRunner
226
+
227
+ env = rps_v2.env()
228
+ env.reset(seed=0)
229
+ views = {aid: SeatEnvView(env, aid) for aid in env.possible_agents}
230
+ agents = {aid: make_agent(views[aid]) for aid in env.possible_agents}
231
+
232
+ pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
233
+ MultiAgentRunner(pipeline, agents).run(max_windows=500)
234
+ ```
235
+
236
+ In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner` is a minimal collect/learn driver - it does not run the convergence/checkpoint state machine. See [Multi-agent training](https://sup3rus3r.github.io/tensor-optix/guides/multi-agent/).
237
+
212
238
  ---
213
239
 
214
240
  ## The loop
@@ -238,7 +264,20 @@ opt.best_snapshot # -> PolicySnapshot: best weights + EvalMetrics + Hyperparam
238
264
 
239
265
  Loop state transitions: `ACTIVE` -> `COOLING` -> `DORMANT` -> watchdog shutdown or policy spawn.
240
266
 
241
- On shutdown the loop restores best-known weights, not the final checkpoint.
267
+ - Every non-improving eval counts toward `COOLING`/`DORMANT`, for on-policy and off-policy agents alike. While the score is flat the eval interval backs off (`backoff_factor`, default 2.0); set `backoff_factor=1.0` to evaluate every window.
268
+ - At `DORMANT` the loop stops by default. A `PolicyManagerCallback` with spawn budget remaining spawns a variant instead and training continues.
269
+ - `rollback_on_degradation=True` restores the best checkpoint when a degradation is confirmed (`min_consecutive_degradations` consecutive evals below `degradation_threshold x best`), for on-policy agents only - off-policy agents keep their weights because their replay buffer would immediately pull a restored policy back.
270
+ - On shutdown the loop restores best-known weights, not the final checkpoint.
271
+ - `verbose=True` prints a per-eval diagnostic block; it is safe on consoles that cannot render the box-drawing glyphs (they degrade to `?`).
272
+
273
+ ### YAML / CLI
274
+
275
+ ```bash
276
+ tensor-optix validate config.yaml
277
+ tensor-optix train config.yaml agent.learning_rate=1e-3 optimizer.max_episodes=200
278
+ ```
279
+
280
+ The `algorithm` key selects the agent class and must be buildable for the env (e.g. `TorchDQNAgent` needs a discrete action space; a mismatch is a build error, not a silent substitution). See [Configure via YAML / CLI](https://sup3rus3r.github.io/tensor-optix/guides/cli-config/).
242
281
 
243
282
  ---
244
283
 
@@ -301,12 +340,14 @@ best_config = orch.run()
301
340
  from tensor_optix import PolicyManager
302
341
 
303
342
  pm = PolicyManager(registry, max_spawns=4)
304
- cb = pm.as_callback(agent, agent_factory=make_agent)
343
+ cb = pm.as_callback(agent, agent_factory=lambda: make_agent(env)) # zero-argument factory
305
344
  cb.set_stop_fn(opt.stop)
306
345
  opt.add_callback(cb)
307
346
  opt.run()
308
347
  ```
309
348
 
349
+ Each `DORMANT` event with budget remaining spawns a variant and training continues; once the budget is exhausted the callback stops the loop with the best weights restored. A multi-member `EnsembleAgent` combines policies at inference time - for discrete PPO members `act()` returns the averaged probability vector, which you sample or `argmax`.
350
+
310
351
  ---
311
352
 
312
353
  ## Callbacks
@@ -717,6 +758,8 @@ store.finalize_experiment(record.experiment_id, state=ExperimentState.COMPLETED)
717
758
 
718
759
  Writes are idempotent on `experiment_id`, and every method opens a short, single-statement transaction — nothing here ever holds a lock for the duration of training.
719
760
 
761
+ To record an ordinary training run, attach `ExperimentLedgerCallback(store, task_env=..., algorithm=..., checkpoint_dir=...)` (from `tensor_optix.ledger.callback`) to `RLOptimizer`. A run that raises is finalized `FAILED` automatically; an interrupted one `CANCELLED`.
762
+
720
763
  ### Concurrent trial scheduler
721
764
 
722
765
  `ConcurrentTrialScheduler` runs multiple Optuna trials as real OS processes, with the parent process as sole owner of the Optuna study and the ledger.
@@ -733,6 +776,8 @@ scheduler = ConcurrentTrialScheduler(
733
776
  best_params, best_score = scheduler.run()
734
777
  ```
735
778
 
779
+ A worker that dies without reporting (OOM-kill, crash) is detected, retried up to `max_retries` times, and then recorded as `FAILED` - the scheduler never waits on a dead process.
780
+
736
781
  ### Cross-task transfer (Nanonets)
737
782
 
738
783
  `NanonetsSelector` pools evidence from other tasks' ledger history when deciding how to allocate a new task's trial budget — but only when a conservative abstention gate confirms a source task's data is actually comparable (median performance at or above the target's own 95th percentile, both normalized against each task's own solve threshold so differently-scaled/signed scores are never compared on raw terms). When nothing passes the gate, it falls back to the non-learned baseline rather than guess.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tensor-optix"
7
- version = "2.0.3"
7
+ version = "2.0.4"
8
8
  description = "Autonomous training loop for any sequential learning model — PPO, DQN, SAC, TD3, Rainbow DQN, Recurrent PPO for TensorFlow, PyTorch, and JAX/Flax; distributed async actor-learner (IMPALA + V-trace)"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,6 +1,7 @@
1
1
  import numpy as np
2
2
  from typing import Callable, Optional
3
3
  from tensor_optix.core.base_evaluator import BaseEvaluator
4
+ from tensor_optix.core.reward_shape import split_episode_returns
4
5
  from tensor_optix.core.types import EpisodeData, EvalMetrics
5
6
 
6
7
 
@@ -39,7 +40,8 @@ class TorchEvaluator(BaseEvaluator):
39
40
  if self._primary_score_fn is not None:
40
41
  primary = float(self._primary_score_fn(episode_data, train_diagnostics))
41
42
  else:
42
- primary = self._mean_episode_return(rewards, dones)
43
+ n_envs = int((episode_data.metadata or {}).get("n_envs", 1))
44
+ primary = self._mean_episode_return(rewards, dones, n_envs)
43
45
 
44
46
  metrics = {
45
47
  "primary_score": primary,
@@ -54,20 +56,18 @@ class TorchEvaluator(BaseEvaluator):
54
56
  episode_id=episode_data.episode_id)
55
57
 
56
58
  @staticmethod
57
- def _mean_episode_return(rewards: np.ndarray, dones: list) -> float:
59
+ def _mean_episode_return(rewards: np.ndarray, dones: list, n_envs: int = 1) -> float:
58
60
  """
59
61
  Compute mean return of episodes that completed in this window.
60
62
  dones should be terminated OR truncated — both signal an episode
61
63
  boundary. Falls back to mean per-step reward only if the window
62
64
  contains a single incomplete episode (very long envs, early training).
63
65
  """
64
- episode_returns = []
65
- current = 0.0
66
- for r, done in zip(rewards, dones):
67
- current += float(r)
68
- if done:
69
- episode_returns.append(current)
70
- current = 0.0
66
+ # Per-env accumulation: a VectorBatchPipeline window interleaves
67
+ # n_envs envs, and each episode's return must only sum its own env.
68
+ episode_returns = [
69
+ float(np.sum(seg)) for seg in split_episode_returns(rewards, dones, n_envs)
70
+ ]
71
71
  if episode_returns:
72
72
  return float(np.mean(episode_returns))
73
73
  return float(rewards.mean())
@@ -1,5 +1,6 @@
1
1
  import numpy as np
2
2
  from tensor_optix.core.base_evaluator import BaseEvaluator
3
+ from tensor_optix.core.reward_shape import split_episode_returns
3
4
  from tensor_optix.core.types import EpisodeData, EvalMetrics
4
5
 
5
6
 
@@ -36,7 +37,8 @@ class TFEvaluator(BaseEvaluator):
36
37
  if self._primary_score_fn is not None:
37
38
  primary = float(self._primary_score_fn(episode_data, train_diagnostics))
38
39
  else:
39
- primary = self._mean_episode_return(rewards, dones)
40
+ n_envs = int((episode_data.metadata or {}).get("n_envs", 1))
41
+ primary = self._mean_episode_return(rewards, dones, n_envs)
40
42
 
41
43
  metrics = {
42
44
  "primary_score": primary,
@@ -51,20 +53,18 @@ class TFEvaluator(BaseEvaluator):
51
53
  episode_id=episode_data.episode_id)
52
54
 
53
55
  @staticmethod
54
- def _mean_episode_return(rewards: np.ndarray, dones: list) -> float:
56
+ def _mean_episode_return(rewards: np.ndarray, dones: list, n_envs: int = 1) -> float:
55
57
  """
56
58
  Compute mean return of episodes that completed in this window.
57
59
  dones should be terminated OR truncated — both signal an episode
58
60
  boundary. Falls back to mean per-step reward only if the window
59
61
  contains a single incomplete episode (very long envs, early training).
60
62
  """
61
- episode_returns = []
62
- current = 0.0
63
- for r, done in zip(rewards, dones):
64
- current += float(r)
65
- if done:
66
- episode_returns.append(current)
67
- current = 0.0
63
+ # Per-env accumulation: a VectorBatchPipeline window interleaves
64
+ # n_envs envs, and each episode's return must only sum its own env.
65
+ episode_returns = [
66
+ float(np.sum(seg)) for seg in split_episode_returns(rewards, dones, n_envs)
67
+ ]
68
68
  if episode_returns:
69
69
  return float(np.mean(episode_returns))
70
70
  return float(rewards.mean())
@@ -6,7 +6,7 @@ import tensorflow as tf
6
6
 
7
7
  from tensor_optix.core.base_agent import BaseAgent
8
8
  from tensor_optix.core.types import EpisodeData, HyperparamSet
9
- from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
9
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
10
10
  from tensor_optix.core.obs_utils import to_batch_numpy, to_tf_batch, already_batched_to_tf, batch_index
11
11
 
12
12
 
@@ -119,12 +119,16 @@ class TFDQNAgent(BaseAgent):
119
119
  done_arr = episode_data.dones
120
120
 
121
121
  T = len(rew_arr)
122
- for t in range(T - 1):
123
- self._buffer.push(
124
- batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
125
- batch_index(obs_arr, t + 1), bool(done_arr[t]),
126
- )
127
- self._buffer.flush_episode()
122
+ # Pair each step with the NEXT step of the same environment. With a
123
+ # VectorBatchPipeline window the flat arrays interleave n_envs envs
124
+ # ([t * n_envs + i]), so index t + 1 belongs to a different env.
125
+ for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
126
+ for t, t_next in env_pairs:
127
+ self._buffer.push(
128
+ batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
129
+ batch_index(obs_arr, t_next), bool(done_arr[t]),
130
+ )
131
+ self._buffer.flush_episode()
128
132
 
129
133
  self._learn_calls += 1
130
134
  new_eps = max(epsilon_min, float(hp.get("epsilon", 1.0)) * epsilon_decay)
@@ -6,7 +6,7 @@ import tensorflow as tf
6
6
 
7
7
  from tensor_optix.core.base_agent import BaseAgent
8
8
  from tensor_optix.core.types import EpisodeData, HyperparamSet
9
- from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
9
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
10
10
  from tensor_optix.core.obs_utils import to_batch_numpy, to_tf_batch, already_batched_to_tf
11
11
 
12
12
 
@@ -175,15 +175,19 @@ class TFSACAgent(BaseAgent):
175
175
  done_arr = episode_data.dones
176
176
  T = len(rew_arr)
177
177
 
178
- for t in range(T - 1):
179
- self._buffer.push(
180
- obs_arr[t],
181
- act_arr[t],
182
- float(rew_arr[t]),
183
- obs_arr[t + 1],
184
- float(done_arr[t]),
185
- )
186
- self._buffer.flush_episode()
178
+ # Pair each step with the NEXT step of the same environment. With a
179
+ # VectorBatchPipeline window the flat arrays interleave n_envs envs
180
+ # ([t * n_envs + i]), so index t + 1 belongs to a different env.
181
+ for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
182
+ for t, t_next in env_pairs:
183
+ self._buffer.push(
184
+ obs_arr[t],
185
+ act_arr[t],
186
+ float(rew_arr[t]),
187
+ obs_arr[t_next],
188
+ float(done_arr[t]),
189
+ )
190
+ self._buffer.flush_episode()
187
191
 
188
192
  if len(self._buffer) < batch_size:
189
193
  return {
@@ -61,7 +61,7 @@ import tensorflow as tf
61
61
 
62
62
  from tensor_optix.core.base_agent import BaseAgent
63
63
  from tensor_optix.core.types import EpisodeData, HyperparamSet
64
- from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
64
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
65
65
  from tensor_optix.core.obs_utils import to_tf_batch, already_batched_to_tf
66
66
 
67
67
 
@@ -146,8 +146,14 @@ class TFTDDAgent(BaseAgent):
146
146
  def act(self, observation) -> np.ndarray:
147
147
  """Deterministic action: a = π_θ(s) = tanh(actor(s))."""
148
148
  obs = to_tf_batch(observation)
149
- action = self._actor(obs, training=False)
150
- return action.numpy()[0]
149
+ action = self._actor(obs, training=False).numpy()[0]
150
+ # Optional Gaussian exploration noise (Fujimoto et al. 2018, σ=0.1).
151
+ # Off by default: act() stays deterministic unless the
152
+ # "exploration_noise" hyperparameter is set > 0.
153
+ sigma = float(self._hyperparams.params.get("exploration_noise", 0.0))
154
+ if sigma > 0.0:
155
+ action = np.clip(action + sigma * np.random.randn(*action.shape), -1.0, 1.0).astype(action.dtype)
156
+ return action
151
157
 
152
158
  def learn(self, episode_data: EpisodeData) -> dict:
153
159
  hp = self._hyperparams.params
@@ -164,12 +170,16 @@ class TFTDDAgent(BaseAgent):
164
170
  done_arr = episode_data.dones
165
171
  T = len(rew_arr)
166
172
 
167
- for t in range(T - 1):
168
- self._buffer.push(
169
- obs_arr[t], act_arr[t], float(rew_arr[t]),
170
- obs_arr[t + 1], float(done_arr[t]),
171
- )
172
- self._buffer.flush_episode()
173
+ # Pair each step with the NEXT step of the same environment. With a
174
+ # VectorBatchPipeline window the flat arrays interleave n_envs envs
175
+ # ([t * n_envs + i]), so index t + 1 belongs to a different env.
176
+ for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
177
+ for t, t_next in env_pairs:
178
+ self._buffer.push(
179
+ obs_arr[t], act_arr[t], float(rew_arr[t]),
180
+ obs_arr[t_next], float(done_arr[t]),
181
+ )
182
+ self._buffer.flush_episode()
173
183
 
174
184
  if len(self._buffer) < batch_size:
175
185
  return {
@@ -5,7 +5,7 @@ import numpy as np
5
5
 
6
6
  from tensor_optix.core.base_agent import BaseAgent
7
7
  from tensor_optix.core.types import EpisodeData, HyperparamSet
8
- from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
8
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
9
9
  from tensor_optix.core.obs_utils import to_batch_numpy, to_torch_batch, batch_index, already_batched_to_torch
10
10
 
11
11
 
@@ -130,10 +130,14 @@ class TorchDQNAgent(BaseAgent):
130
130
  done_arr = episode_data.dones
131
131
  T = len(rew_arr)
132
132
 
133
- for t in range(T - 1):
134
- self._buffer.push(batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
135
- batch_index(obs_arr, t + 1), bool(done_arr[t]))
136
- self._buffer.flush_episode()
133
+ # Pair each step with the NEXT step of the same environment. With a
134
+ # VectorBatchPipeline window the flat arrays interleave n_envs envs
135
+ # ([t * n_envs + i]), so index t + 1 belongs to a different env.
136
+ for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
137
+ for t, t_next in env_pairs:
138
+ self._buffer.push(batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
139
+ batch_index(obs_arr, t_next), bool(done_arr[t]))
140
+ self._buffer.flush_episode()
137
141
 
138
142
  self._learn_calls += 1
139
143
  new_eps = max(epsilon_min, float(hp.get("epsilon", 1.0)) * epsilon_decay)
@@ -76,7 +76,7 @@ import numpy as np
76
76
 
77
77
  from tensor_optix.core.base_agent import BaseAgent
78
78
  from tensor_optix.core.types import EpisodeData, HyperparamSet
79
- from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
79
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
80
80
  from tensor_optix.core.noisy_linear import NoisyLinear
81
81
  from tensor_optix.core.obs_utils import to_batch_numpy, to_torch_batch, batch_index, already_batched_to_torch
82
82
 
@@ -269,10 +269,14 @@ class TorchRainbowDQNAgent(BaseAgent):
269
269
  done_arr = episode_data.dones
270
270
  T = len(rew_arr)
271
271
 
272
- for t in range(T - 1):
273
- self._buffer.push(batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
274
- batch_index(obs_arr, t + 1), bool(done_arr[t]))
275
- self._buffer.flush_episode()
272
+ # Pair each step with the NEXT step of the same environment. With a
273
+ # VectorBatchPipeline window the flat arrays interleave n_envs envs
274
+ # ([t * n_envs + i]), so index t + 1 belongs to a different env.
275
+ for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
276
+ for t, t_next in env_pairs:
277
+ self._buffer.push(batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
278
+ batch_index(obs_arr, t_next), bool(done_arr[t]))
279
+ self._buffer.flush_episode()
276
280
 
277
281
  self._learn_calls += 1
278
282
 
@@ -219,10 +219,28 @@ class TorchRecurrentPPOAgent(BaseAgent):
219
219
  self._cache_lp = self._cache_lp[T:]
220
220
  self._cache_values = self._cache_values[T:]
221
221
  self._cache_hidden = self._cache_hidden[T:]
222
+
223
+ # Bootstrap V(s_T) when the window ended mid-episode (BatchPipeline
224
+ # yields fixed-size windows, not whole episodes). self._h is the
225
+ # hidden state after the window's last step — exactly the context the
226
+ # critic needs for the post-window observation. Zero when terminal.
227
+ last_value = 0.0
228
+ final_obs = getattr(episode_data, "final_obs", None)
229
+ if (
230
+ T > 0 and not dones[-1] and self._h is not None
231
+ and final_obs is not None and not isinstance(final_obs, (list, tuple))
232
+ ):
233
+ with torch.no_grad():
234
+ fo = torch.as_tensor(
235
+ np.atleast_2d(final_obs), dtype=torch.float32
236
+ ).unsqueeze(0).to(self._device)
237
+ out, _ = self._rnn(fo, self._h)
238
+ last_value = float(self._critic_head(out.squeeze(0)).squeeze().item())
239
+
222
240
  self._h = None # reset for next episode
223
241
 
224
242
  # GAE advantage estimation
225
- advantages, returns = compute_gae(rewards, val_arr, dones, gamma, gae_lambda, 0.0)
243
+ advantages, returns = compute_gae(rewards, val_arr, dones, gamma, gae_lambda, last_value)
226
244
  if T > 1:
227
245
  advantages = (advantages - advantages.mean()) / (advantages.std() + 1e-8)
228
246
 
@@ -6,7 +6,7 @@ import numpy as np
6
6
  from tensor_optix.core.base_agent import BaseAgent
7
7
  from tensor_optix.core.resume_state import save_torch_resume_state, load_torch_resume_state
8
8
  from tensor_optix.core.types import EpisodeData, HyperparamSet
9
- from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
9
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
10
10
  from tensor_optix.core.obs_utils import to_torch_batch, already_batched_to_torch
11
11
 
12
12
 
@@ -169,10 +169,14 @@ class TorchSACAgent(BaseAgent):
169
169
  done_arr = episode_data.dones
170
170
  T = len(rew_arr)
171
171
 
172
- for t in range(T - 1):
173
- self._buffer.push(obs_arr[t], act_arr[t], float(rew_arr[t]),
174
- obs_arr[t + 1], float(done_arr[t]))
175
- self._buffer.flush_episode()
172
+ # Pair each step with the NEXT step of the same environment. With a
173
+ # VectorBatchPipeline window the flat arrays interleave n_envs envs
174
+ # ([t * n_envs + i]), so index t + 1 belongs to a different env.
175
+ for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
176
+ for t, t_next in env_pairs:
177
+ self._buffer.push(obs_arr[t], act_arr[t], float(rew_arr[t]),
178
+ obs_arr[t_next], float(done_arr[t]))
179
+ self._buffer.flush_episode()
176
180
 
177
181
  if len(self._buffer) < batch_size:
178
182
  return {
@@ -86,7 +86,7 @@ import numpy as np
86
86
 
87
87
  from tensor_optix.core.base_agent import BaseAgent
88
88
  from tensor_optix.core.types import EpisodeData, HyperparamSet
89
- from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer
89
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, episode_n_envs, window_transition_pairs
90
90
  from tensor_optix.core.obs_utils import to_torch_batch, already_batched_to_torch
91
91
 
92
92
 
@@ -179,6 +179,12 @@ class TorchTD3Agent(BaseAgent):
179
179
  obs = to_torch_batch(observation, self._device)
180
180
  with torch.no_grad():
181
181
  action = self._actor(obs)
182
+ # Optional Gaussian exploration noise (Fujimoto et al. 2018, σ=0.1).
183
+ # Off by default: act() stays deterministic unless the
184
+ # "exploration_noise" hyperparameter is set > 0.
185
+ sigma = float(self._hyperparams.params.get("exploration_noise", 0.0))
186
+ if sigma > 0.0:
187
+ action = (action + sigma * torch.randn_like(action)).clamp(-1.0, 1.0)
182
188
  return action.cpu().numpy()[0]
183
189
 
184
190
  def learn(self, episode_data: EpisodeData) -> dict:
@@ -196,12 +202,16 @@ class TorchTD3Agent(BaseAgent):
196
202
  done_arr = episode_data.dones
197
203
  T = len(rew_arr)
198
204
 
199
- for t in range(T - 1):
200
- self._buffer.push(
201
- obs_arr[t], act_arr[t], float(rew_arr[t]),
202
- obs_arr[t + 1], float(done_arr[t]),
203
- )
204
- self._buffer.flush_episode()
205
+ # Pair each step with the NEXT step of the same environment. With a
206
+ # VectorBatchPipeline window the flat arrays interleave n_envs envs
207
+ # ([t * n_envs + i]), so index t + 1 belongs to a different env.
208
+ for env_pairs in window_transition_pairs(T, episode_n_envs(episode_data)):
209
+ for t, t_next in env_pairs:
210
+ self._buffer.push(
211
+ obs_arr[t], act_arr[t], float(rew_arr[t]),
212
+ obs_arr[t_next], float(done_arr[t]),
213
+ )
214
+ self._buffer.flush_episode()
205
215
 
206
216
  if len(self._buffer) < batch_size:
207
217
  return {
@@ -123,6 +123,10 @@ class TensorBoardCallback(LoopCallback):
123
123
  self._writer.add_scalar(f"metrics/{k}", float(v), episode_id)
124
124
 
125
125
  def on_improvement(self, snapshot: PolicySnapshot) -> None:
126
+ # These hooks fire before on_episode_end for the same episode;
127
+ # advance the step so a following on_hyperparam_update is not
128
+ # logged at an older step (W&B drops non-monotonic steps).
129
+ self._last_episode_id = max(self._last_episode_id, snapshot.episode_id)
126
130
  if self._writer is None:
127
131
  return
128
132
 
@@ -135,16 +139,19 @@ class TensorBoardCallback(LoopCallback):
135
139
  self._writer.add_scalar(f"hyperparams/{k}", float(v), ep)
136
140
 
137
141
  def on_plateau(self, episode_id: int, state) -> None:
142
+ self._last_episode_id = max(self._last_episode_id, episode_id)
138
143
  if self._writer is None:
139
144
  return
140
145
  self._writer.add_scalar("events/plateau", 1, episode_id)
141
146
 
142
147
  def on_dormant(self, episode_id: int) -> None:
148
+ self._last_episode_id = max(self._last_episode_id, episode_id)
143
149
  if self._writer is None:
144
150
  return
145
151
  self._writer.add_scalar("events/convergence", 1, episode_id)
146
152
 
147
153
  def on_degradation(self, episode_id: int, eval_metrics: Optional[EvalMetrics]) -> None:
154
+ self._last_episode_id = max(self._last_episode_id, episode_id)
148
155
  if self._writer is None:
149
156
  return
150
157
  self._writer.add_scalar("events/degradation", 1, episode_id)