tensor-optix 2.0.3__tar.gz → 2.0.5__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 (168) hide show
  1. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/PKG-INFO +52 -5
  2. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/README.md +51 -4
  3. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/pyproject.toml +1 -1
  4. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/pytorch/torch_evaluator.py +9 -9
  5. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/tensorflow/tf_evaluator.py +9 -9
  6. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_dqn.py +11 -7
  7. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_sac.py +14 -10
  8. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_td3.py +19 -9
  9. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_dqn.py +9 -5
  10. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_rainbow_dqn.py +9 -5
  11. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_recurrent_ppo.py +19 -1
  12. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_sac.py +9 -5
  13. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_td3.py +17 -7
  14. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/callbacks/tensorboard_callback.py +7 -0
  15. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/callbacks/wandb_callback.py +7 -0
  16. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/cli.py +8 -0
  17. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/config.py +50 -8
  18. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/backoff_scheduler.py +23 -7
  19. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/base_evaluator.py +4 -1
  20. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/checkpoint_registry.py +6 -1
  21. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/diagnostic_controller.py +2 -1
  22. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/ensemble_agent.py +12 -0
  23. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/loop_controller.py +56 -47
  24. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/obs_utils.py +120 -120
  25. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/policy_manager.py +32 -2
  26. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/replay_buffer.py +29 -1
  27. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/reward_shape.py +16 -10
  28. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/distributed/async_learner.py +9 -0
  29. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/encoders/__init__.py +15 -15
  30. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/encoders/obs_encoder.py +229 -229
  31. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/encoders/obs_encoder_tf.py +80 -80
  32. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/factory.py +64 -10
  33. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/callback.py +19 -0
  34. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/provenance.py +19 -7
  35. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml/loss_registry.py +2 -1
  36. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/__init__.py +53 -53
  37. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/flax_model.py +230 -230
  38. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/tf_model.py +208 -208
  39. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/torch_model.py +241 -241
  40. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/base_model.py +150 -150
  41. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/lr_schedules.py +67 -67
  42. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics.py +201 -188
  43. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics_impl/classification.py +101 -101
  44. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics_impl/regression.py +46 -46
  45. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/trainer.py +240 -207
  46. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/transfer.py +152 -152
  47. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/multi_agent/__init__.py +41 -34
  48. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/multi_agent/aec_pipeline.py +191 -173
  49. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/multi_agent/multi_agent_episode.py +18 -18
  50. tensor_optix-2.0.5/tensor_optix/multi_agent/multi_agent_runtime.py +359 -0
  51. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/multi_agent/parallel_pipeline.py +145 -145
  52. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/multi_agent/seat_env.py +81 -81
  53. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/selector.py +9 -3
  54. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/agent/graph_agent.py +74 -15
  55. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/controller/topology_controller.py +16 -4
  56. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/neuron_graph.py +58 -2
  57. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/topology_ops.py +51 -16
  58. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/hebbian.py +45 -4
  59. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/neuromodulator.py +12 -0
  60. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizer.py +17 -10
  61. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/backoff_optimizer.py +13 -4
  62. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/spsa_optimizer.py +18 -3
  63. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/pipeline/batch_pipeline.py +5 -0
  64. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/pipeline/live_pipeline.py +30 -6
  65. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/pipeline/vector_pipeline.py +19 -2
  66. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/baseline.py +8 -0
  67. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/live_runtime.py +12 -4
  68. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/pool.py +36 -1
  69. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/worker.py +7 -0
  70. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/selection/selector.py +17 -1
  71. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/simple.py +11 -1
  72. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/grammar.py +8 -0
  73. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/worker.py +14 -0
  74. tensor_optix-2.0.5/tensor_optix/utils/console.py +28 -0
  75. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/PKG-INFO +52 -5
  76. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/SOURCES.txt +1 -0
  77. tensor_optix-2.0.3/tensor_optix/multi_agent/multi_agent_runtime.py +0 -53
  78. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/setup.cfg +0 -0
  79. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/__init__.py +0 -0
  80. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/__init__.py +0 -0
  81. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/jax/__init__.py +0 -0
  82. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/jax/flax_agent.py +0 -0
  83. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/jax/flax_evaluator.py +0 -0
  84. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/pytorch/__init__.py +0 -0
  85. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/pytorch/torch_agent.py +0 -0
  86. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/tensorflow/__init__.py +0 -0
  87. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/adapters/tensorflow/tf_agent.py +0 -0
  88. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/__init__.py +0 -0
  89. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/flax_ppo.py +0 -0
  90. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_ppo.py +0 -0
  91. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/tf_ppo_continuous.py +0 -0
  92. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_ppo.py +0 -0
  93. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/algorithms/torch_ppo_continuous.py +0 -0
  94. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/callbacks/__init__.py +0 -0
  95. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/callbacks/rich_dashboard.py +0 -0
  96. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/__init__.py +0 -0
  97. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/async_callback.py +0 -0
  98. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/base_agent.py +0 -0
  99. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/base_optimizer.py +0 -0
  100. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/base_pipeline.py +0 -0
  101. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/checkpoint_confirmation.py +0 -0
  102. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/device.py +0 -0
  103. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/her_buffer.py +0 -0
  104. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/meta_controller.py +0 -0
  105. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/noisy_linear.py +0 -0
  106. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/normalizers.py +0 -0
  107. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/regime_detector.py +0 -0
  108. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/resume_state.py +0 -0
  109. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/trajectory_buffer.py +0 -0
  110. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/core/types.py +0 -0
  111. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/distributed/__init__.py +0 -0
  112. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/distributed/vtrace.py +0 -0
  113. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/exploration/__init__.py +0 -0
  114. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/exploration/rnd.py +0 -0
  115. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/__init__.py +0 -0
  116. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/records.py +0 -0
  117. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/schema.py +0 -0
  118. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ledger/store.py +0 -0
  119. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml/__init__.py +0 -0
  120. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml/dataset_pipeline.py +0 -0
  121. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml/ml_agent.py +0 -0
  122. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/adapters/__init__.py +0 -0
  123. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/ml_core/metrics_impl/__init__.py +0 -0
  124. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/__init__.py +0 -0
  125. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/abstention.py +0 -0
  126. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/features.py +0 -0
  127. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/pooling.py +0 -0
  128. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/nanonets/smalln.py +0 -0
  129. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/__init__.py +0 -0
  130. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/agent/__init__.py +0 -0
  131. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/brain_network.py +0 -0
  132. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/controller/__init__.py +0 -0
  133. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/controller/topology_callback.py +0 -0
  134. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/__init__.py +0 -0
  135. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/graph/neuron.py +0 -0
  136. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/optimizer/__init__.py +0 -0
  137. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/neuroevo/optimizer/topology_aware_adam.py +0 -0
  138. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/__init__.py +0 -0
  139. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/adaptive_optimizer.py +0 -0
  140. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/momentum_optimizer.py +0 -0
  141. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/optimizers/pbt_optimizer.py +0 -0
  142. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/orchestrator.py +0 -0
  143. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/pipeline/__init__.py +0 -0
  144. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/__init__.py +0 -0
  145. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/experiment_stage.py +0 -0
  146. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/observer.py +0 -0
  147. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/runtime/promote.py +0 -0
  148. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/__init__.py +0 -0
  149. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/_mp_common.py +0 -0
  150. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/budget.py +0 -0
  151. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/dedup.py +0 -0
  152. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/isolation.py +0 -0
  153. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/scheduler/retry.py +0 -0
  154. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/selection/__init__.py +0 -0
  155. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/selection/backfill.py +0 -0
  156. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/selection/uncertainty.py +0 -0
  157. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/__init__.py +0 -0
  158. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/candidate.py +0 -0
  159. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/comparator.py +0 -0
  160. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/promotion.py +0 -0
  161. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/strategy/runner.py +0 -0
  162. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/utils/__init__.py +0 -0
  163. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix/utils/window_size.py +0 -0
  164. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/dependency_links.txt +0 -0
  165. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/entry_points.txt +0 -0
  166. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/requires.txt +0 -0
  167. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/tensor_optix.egg-info/top_level.txt +0 -0
  168. {tensor_optix-2.0.3 → tensor_optix-2.0.5}/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.5
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
@@ -71,6 +71,8 @@ Requires-Dist: torch>=2.11.0; extra == "dev"
71
71
 
72
72
  # tensor-optix
73
73
 
74
+ [See Documentation](https://sup3rus3r.github.io/tensor-optix/)
75
+
74
76
  tensor-optix is a training framework for reinforcement learning and for supervised/unsupervised machine learning. Both have statistical convergence control, online hyperparameter optimisation, and real checkpointing.
75
77
 
76
78
  It has two parallel cores:
@@ -162,7 +164,7 @@ pip install tensor-optix[torch]
162
164
  pip install tensor-optix[all]
163
165
  ```
164
166
 
165
- Environment extras: `[box2d]`, `[atari]`, `[mujoco]`
167
+ Environment extras: `[box2d]`, `[atari]`, `[mujoco]`, `[pettingzoo]` (multi-agent)
166
168
  Logging extras: `[wandb]`, `[tensorboard]`
167
169
  Export: `[onnx]`
168
170
 
@@ -194,7 +196,7 @@ All agents implement `BaseAgent` and are interchangeable with `RLOptimizer`.
194
196
 
195
197
  ### Auto-selection
196
198
 
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.
199
+ `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
200
 
199
201
  ```python
200
202
  from tensor_optix import make_agent
@@ -280,6 +282,32 @@ pipeline = VectorBatchPipeline(
280
282
  )
281
283
  ```
282
284
 
285
+ Notes:
286
+
287
+ - `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.
288
+ - `BatchPipeline` resets a recurrent agent's hidden state (`reset_hidden()`) at every episode boundary.
289
+ - `LivePipeline` applies backpressure: when the consumer is slower than the source, the producer waits instead of dropping samples or restarting the stream.
290
+
291
+ ### Multi-agent (PettingZoo)
292
+
293
+ `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.
294
+
295
+ ```python
296
+ from pettingzoo.classic import rps_v2
297
+ from tensor_optix import make_agent
298
+ from tensor_optix.multi_agent import SeatEnvView, AECMultiAgentPipeline, MultiAgentRunner
299
+
300
+ env = rps_v2.env()
301
+ env.reset(seed=0)
302
+ views = {aid: SeatEnvView(env, aid) for aid in env.possible_agents}
303
+ agents = {aid: make_agent(views[aid]) for aid in env.possible_agents}
304
+
305
+ pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
306
+ MultiAgentRunner(pipeline, agents).run(max_windows=500)
307
+ ```
308
+
309
+ In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner` scores every seat each window, checkpoints each seat's best weights (`checkpoint_dir=`), detects per-seat convergence with the same trend test as the single-agent loop, and stops once every seat has converged (`stop_when="any"` for the first), restoring best weights. See [Multi-agent training](https://sup3rus3r.github.io/tensor-optix/guides/multi-agent/).
310
+
283
311
  ---
284
312
 
285
313
  ## The loop
@@ -309,7 +337,20 @@ opt.best_snapshot # -> PolicySnapshot: best weights + EvalMetrics + Hyperparam
309
337
 
310
338
  Loop state transitions: `ACTIVE` -> `COOLING` -> `DORMANT` -> watchdog shutdown or policy spawn.
311
339
 
312
- On shutdown the loop restores best-known weights, not the final checkpoint.
340
+ - 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.
341
+ - At `DORMANT` the loop stops by default. A `PolicyManagerCallback` with spawn budget remaining spawns a variant instead and training continues.
342
+ - `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.
343
+ - On shutdown the loop restores best-known weights, not the final checkpoint.
344
+ - `verbose=True` prints a per-eval diagnostic block; it is safe on consoles that cannot render the box-drawing glyphs (they degrade to `?`).
345
+
346
+ ### YAML / CLI
347
+
348
+ ```bash
349
+ tensor-optix validate config.yaml
350
+ tensor-optix train config.yaml agent.learning_rate=1e-3 optimizer.max_episodes=200
351
+ ```
352
+
353
+ 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
354
 
314
355
  ---
315
356
 
@@ -372,12 +413,14 @@ best_config = orch.run()
372
413
  from tensor_optix import PolicyManager
373
414
 
374
415
  pm = PolicyManager(registry, max_spawns=4)
375
- cb = pm.as_callback(agent, agent_factory=make_agent)
416
+ cb = pm.as_callback(agent, agent_factory=lambda: make_agent(env)) # zero-argument factory
376
417
  cb.set_stop_fn(opt.stop)
377
418
  opt.add_callback(cb)
378
419
  opt.run()
379
420
  ```
380
421
 
422
+ 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`.
423
+
381
424
  ---
382
425
 
383
426
  ## Callbacks
@@ -788,6 +831,8 @@ store.finalize_experiment(record.experiment_id, state=ExperimentState.COMPLETED)
788
831
 
789
832
  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
833
 
834
+ 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`.
835
+
791
836
  ### Concurrent trial scheduler
792
837
 
793
838
  `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 +849,8 @@ scheduler = ConcurrentTrialScheduler(
804
849
  best_params, best_score = scheduler.run()
805
850
  ```
806
851
 
852
+ 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.
853
+
807
854
  ### Cross-task transfer (Nanonets)
808
855
 
809
856
  `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.
@@ -1,5 +1,7 @@
1
1
  # tensor-optix
2
2
 
3
+ [See Documentation](https://sup3rus3r.github.io/tensor-optix/)
4
+
3
5
  tensor-optix is a training framework for reinforcement learning and for supervised/unsupervised machine learning. Both have statistical convergence control, online hyperparameter optimisation, and real checkpointing.
4
6
 
5
7
  It has two parallel cores:
@@ -91,7 +93,7 @@ pip install tensor-optix[torch]
91
93
  pip install tensor-optix[all]
92
94
  ```
93
95
 
94
- Environment extras: `[box2d]`, `[atari]`, `[mujoco]`
96
+ Environment extras: `[box2d]`, `[atari]`, `[mujoco]`, `[pettingzoo]` (multi-agent)
95
97
  Logging extras: `[wandb]`, `[tensorboard]`
96
98
  Export: `[onnx]`
97
99
 
@@ -123,7 +125,7 @@ All agents implement `BaseAgent` and are interchangeable with `RLOptimizer`.
123
125
 
124
126
  ### Auto-selection
125
127
 
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.
128
+ `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
129
 
128
130
  ```python
129
131
  from tensor_optix import make_agent
@@ -209,6 +211,32 @@ pipeline = VectorBatchPipeline(
209
211
  )
210
212
  ```
211
213
 
214
+ Notes:
215
+
216
+ - `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.
217
+ - `BatchPipeline` resets a recurrent agent's hidden state (`reset_hidden()`) at every episode boundary.
218
+ - `LivePipeline` applies backpressure: when the consumer is slower than the source, the producer waits instead of dropping samples or restarting the stream.
219
+
220
+ ### Multi-agent (PettingZoo)
221
+
222
+ `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.
223
+
224
+ ```python
225
+ from pettingzoo.classic import rps_v2
226
+ from tensor_optix import make_agent
227
+ from tensor_optix.multi_agent import SeatEnvView, AECMultiAgentPipeline, MultiAgentRunner
228
+
229
+ env = rps_v2.env()
230
+ env.reset(seed=0)
231
+ views = {aid: SeatEnvView(env, aid) for aid in env.possible_agents}
232
+ agents = {aid: make_agent(views[aid]) for aid in env.possible_agents}
233
+
234
+ pipeline = AECMultiAgentPipeline(env, agents, window_size=400, views=views)
235
+ MultiAgentRunner(pipeline, agents).run(max_windows=500)
236
+ ```
237
+
238
+ In turn-based games each reward (including the terminal win/loss) is credited to the action that earned it. `MultiAgentRunner` scores every seat each window, checkpoints each seat's best weights (`checkpoint_dir=`), detects per-seat convergence with the same trend test as the single-agent loop, and stops once every seat has converged (`stop_when="any"` for the first), restoring best weights. See [Multi-agent training](https://sup3rus3r.github.io/tensor-optix/guides/multi-agent/).
239
+
212
240
  ---
213
241
 
214
242
  ## The loop
@@ -238,7 +266,20 @@ opt.best_snapshot # -> PolicySnapshot: best weights + EvalMetrics + Hyperparam
238
266
 
239
267
  Loop state transitions: `ACTIVE` -> `COOLING` -> `DORMANT` -> watchdog shutdown or policy spawn.
240
268
 
241
- On shutdown the loop restores best-known weights, not the final checkpoint.
269
+ - 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.
270
+ - At `DORMANT` the loop stops by default. A `PolicyManagerCallback` with spawn budget remaining spawns a variant instead and training continues.
271
+ - `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.
272
+ - On shutdown the loop restores best-known weights, not the final checkpoint.
273
+ - `verbose=True` prints a per-eval diagnostic block; it is safe on consoles that cannot render the box-drawing glyphs (they degrade to `?`).
274
+
275
+ ### YAML / CLI
276
+
277
+ ```bash
278
+ tensor-optix validate config.yaml
279
+ tensor-optix train config.yaml agent.learning_rate=1e-3 optimizer.max_episodes=200
280
+ ```
281
+
282
+ 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
283
 
243
284
  ---
244
285
 
@@ -301,12 +342,14 @@ best_config = orch.run()
301
342
  from tensor_optix import PolicyManager
302
343
 
303
344
  pm = PolicyManager(registry, max_spawns=4)
304
- cb = pm.as_callback(agent, agent_factory=make_agent)
345
+ cb = pm.as_callback(agent, agent_factory=lambda: make_agent(env)) # zero-argument factory
305
346
  cb.set_stop_fn(opt.stop)
306
347
  opt.add_callback(cb)
307
348
  opt.run()
308
349
  ```
309
350
 
351
+ 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`.
352
+
310
353
  ---
311
354
 
312
355
  ## Callbacks
@@ -717,6 +760,8 @@ store.finalize_experiment(record.experiment_id, state=ExperimentState.COMPLETED)
717
760
 
718
761
  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
762
 
763
+ 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`.
764
+
720
765
  ### Concurrent trial scheduler
721
766
 
722
767
  `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 +778,8 @@ scheduler = ConcurrentTrialScheduler(
733
778
  best_params, best_score = scheduler.run()
734
779
  ```
735
780
 
781
+ 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.
782
+
736
783
  ### Cross-task transfer (Nanonets)
737
784
 
738
785
  `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.5"
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 {