tensor-optix 2.0.7__tar.gz → 2.0.9__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.7 → tensor_optix-2.0.9}/PKG-INFO +8 -5
  2. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/README.md +7 -4
  3. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/pyproject.toml +1 -1
  4. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/tf_dqn.py +6 -3
  5. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/tf_sac.py +6 -3
  6. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/tf_td3.py +6 -3
  7. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/torch_dqn.py +6 -3
  8. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/torch_rainbow_dqn.py +6 -3
  9. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/torch_sac.py +6 -3
  10. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/torch_td3.py +6 -3
  11. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/normalizers.py +9 -1
  12. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/replay_buffer.py +69 -4
  13. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/distributed/vtrace.py +3 -0
  14. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/factory.py +1 -1
  15. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/multi_agent/multi_agent_runtime.py +671 -671
  16. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/multi_agent/self_play.py +292 -292
  17. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/agent/graph_agent.py +174 -156
  18. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/brain_network.py +4 -1
  19. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/controller/topology_controller.py +122 -63
  20. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/graph/neuron.py +13 -15
  21. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/graph/neuron_graph.py +472 -52
  22. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/graph/topology_ops.py +7 -8
  23. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/hebbian.py +104 -39
  24. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/optimizer/topology_aware_adam.py +62 -1
  25. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix.egg-info/PKG-INFO +8 -5
  26. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/setup.cfg +0 -0
  27. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/__init__.py +0 -0
  28. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/adapters/__init__.py +0 -0
  29. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/adapters/jax/__init__.py +0 -0
  30. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/adapters/jax/flax_agent.py +0 -0
  31. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/adapters/jax/flax_evaluator.py +0 -0
  32. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/adapters/pytorch/__init__.py +0 -0
  33. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/adapters/pytorch/torch_agent.py +0 -0
  34. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/adapters/pytorch/torch_evaluator.py +0 -0
  35. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/adapters/tensorflow/__init__.py +0 -0
  36. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/adapters/tensorflow/tf_agent.py +0 -0
  37. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/adapters/tensorflow/tf_evaluator.py +0 -0
  38. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/__init__.py +0 -0
  39. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/flax_ppo.py +0 -0
  40. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/tf_ppo.py +0 -0
  41. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/tf_ppo_continuous.py +0 -0
  42. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/torch_ppo.py +0 -0
  43. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/torch_ppo_continuous.py +0 -0
  44. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/algorithms/torch_recurrent_ppo.py +0 -0
  45. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/callbacks/__init__.py +0 -0
  46. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/callbacks/rich_dashboard.py +0 -0
  47. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/callbacks/tensorboard_callback.py +0 -0
  48. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/callbacks/wandb_callback.py +0 -0
  49. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/cli.py +0 -0
  50. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/config.py +0 -0
  51. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/__init__.py +0 -0
  52. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/async_callback.py +0 -0
  53. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/backoff_scheduler.py +0 -0
  54. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/base_agent.py +0 -0
  55. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/base_evaluator.py +0 -0
  56. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/base_optimizer.py +0 -0
  57. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/base_pipeline.py +0 -0
  58. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/checkpoint_confirmation.py +0 -0
  59. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/checkpoint_registry.py +0 -0
  60. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/device.py +0 -0
  61. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/diagnostic_controller.py +0 -0
  62. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/ensemble_agent.py +0 -0
  63. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/her_buffer.py +0 -0
  64. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/loop_controller.py +0 -0
  65. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/meta_controller.py +0 -0
  66. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/noisy_linear.py +0 -0
  67. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/obs_utils.py +0 -0
  68. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/policy_manager.py +0 -0
  69. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/regime_detector.py +0 -0
  70. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/resume_state.py +0 -0
  71. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/reward_shape.py +0 -0
  72. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/trajectory_buffer.py +0 -0
  73. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/core/types.py +0 -0
  74. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/distributed/__init__.py +0 -0
  75. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/distributed/async_learner.py +0 -0
  76. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/encoders/__init__.py +0 -0
  77. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/encoders/obs_encoder.py +0 -0
  78. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/encoders/obs_encoder_tf.py +0 -0
  79. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/exploration/__init__.py +0 -0
  80. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/exploration/rnd.py +0 -0
  81. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ledger/__init__.py +0 -0
  82. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ledger/callback.py +0 -0
  83. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ledger/provenance.py +0 -0
  84. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ledger/records.py +0 -0
  85. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ledger/schema.py +0 -0
  86. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ledger/store.py +0 -0
  87. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml/__init__.py +0 -0
  88. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml/dataset_pipeline.py +0 -0
  89. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml/loss_registry.py +0 -0
  90. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml/ml_agent.py +0 -0
  91. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/__init__.py +0 -0
  92. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/adapters/__init__.py +0 -0
  93. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/adapters/flax_model.py +0 -0
  94. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/adapters/tf_model.py +0 -0
  95. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/adapters/torch_model.py +0 -0
  96. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/base_model.py +0 -0
  97. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/lr_schedules.py +0 -0
  98. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/metrics.py +0 -0
  99. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/metrics_impl/__init__.py +0 -0
  100. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/metrics_impl/classification.py +0 -0
  101. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/metrics_impl/regression.py +0 -0
  102. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/trainer.py +0 -0
  103. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/ml_core/transfer.py +0 -0
  104. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/multi_agent/__init__.py +0 -0
  105. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/multi_agent/aec_pipeline.py +0 -0
  106. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/multi_agent/multi_agent_episode.py +0 -0
  107. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/multi_agent/parallel_pipeline.py +0 -0
  108. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/multi_agent/seat_env.py +0 -0
  109. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/nanonets/__init__.py +0 -0
  110. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/nanonets/abstention.py +0 -0
  111. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/nanonets/features.py +0 -0
  112. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/nanonets/pooling.py +0 -0
  113. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/nanonets/selector.py +0 -0
  114. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/nanonets/smalln.py +0 -0
  115. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/__init__.py +0 -0
  116. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/agent/__init__.py +0 -0
  117. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/controller/__init__.py +0 -0
  118. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/controller/topology_callback.py +0 -0
  119. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/graph/__init__.py +0 -0
  120. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/neuromodulator.py +0 -0
  121. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/neuroevo/optimizer/__init__.py +0 -0
  122. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/optimizer.py +0 -0
  123. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/optimizers/__init__.py +0 -0
  124. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/optimizers/adaptive_optimizer.py +0 -0
  125. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/optimizers/backoff_optimizer.py +0 -0
  126. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/optimizers/momentum_optimizer.py +0 -0
  127. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/optimizers/pbt_optimizer.py +0 -0
  128. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/optimizers/spsa_optimizer.py +0 -0
  129. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/orchestrator.py +0 -0
  130. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/pipeline/__init__.py +0 -0
  131. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/pipeline/batch_pipeline.py +0 -0
  132. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/pipeline/live_pipeline.py +0 -0
  133. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/pipeline/vector_pipeline.py +0 -0
  134. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/runtime/__init__.py +0 -0
  135. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/runtime/baseline.py +0 -0
  136. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/runtime/experiment_stage.py +0 -0
  137. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/runtime/live_runtime.py +0 -0
  138. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/runtime/observer.py +0 -0
  139. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/runtime/promote.py +0 -0
  140. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/scheduler/__init__.py +0 -0
  141. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/scheduler/_mp_common.py +0 -0
  142. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/scheduler/budget.py +0 -0
  143. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/scheduler/dedup.py +0 -0
  144. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/scheduler/isolation.py +0 -0
  145. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/scheduler/pool.py +0 -0
  146. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/scheduler/retry.py +0 -0
  147. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/scheduler/worker.py +0 -0
  148. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/selection/__init__.py +0 -0
  149. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/selection/backfill.py +0 -0
  150. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/selection/selector.py +0 -0
  151. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/selection/uncertainty.py +0 -0
  152. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/simple.py +0 -0
  153. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/strategy/__init__.py +0 -0
  154. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/strategy/candidate.py +0 -0
  155. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/strategy/comparator.py +0 -0
  156. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/strategy/grammar.py +0 -0
  157. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/strategy/promotion.py +0 -0
  158. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/strategy/runner.py +0 -0
  159. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/strategy/worker.py +0 -0
  160. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/utils/__init__.py +0 -0
  161. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/utils/console.py +0 -0
  162. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix/utils/window_size.py +0 -0
  163. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix.egg-info/SOURCES.txt +0 -0
  164. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix.egg-info/dependency_links.txt +0 -0
  165. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix.egg-info/entry_points.txt +0 -0
  166. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix.egg-info/requires.txt +0 -0
  167. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/tensor_optix.egg-info/top_level.txt +0 -0
  168. {tensor_optix-2.0.7 → tensor_optix-2.0.9}/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.7
3
+ Version: 2.0.9
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
@@ -518,7 +518,7 @@ All types implement the same protocol: `step()`, `importance()`, `can_merge_with
518
518
 
519
519
  ### Trainable recurrent neurons
520
520
 
521
- `TrainableGRUNeuron` and `TrainableLSTMNeuron` set `is_recurrent = True`. `RecurrentGraphAgent` detects this flag and switches from shuffled-minibatch PPO to sequential chunk training with truncated BPTT.
521
+ `TrainableGRUNeuron` and `TrainableLSTMNeuron` let gradients flow back through their hidden state. Use them with `RecurrentGraphAgent`, which keeps the graph's state across `act()` calls (reset at episode start via `reset_hidden()`) and trains with sequential chunks and truncated BPTT, replaying exactly what `act()` computed.
522
522
 
523
523
  ```python
524
524
  from tensor_optix.neuroevo import TrainableGRUNeuron, TrainableLSTMNeuron, RecurrentGraphAgent
@@ -532,7 +532,8 @@ agent = RecurrentGraphAgent(
532
532
  graph, obs_dim=4, n_actions=2,
533
533
  hyperparams=HyperparamSet(params={"chunk_len": 64}),
534
534
  )
535
- # Falls back to standard shuffled-minibatch PPO if no recurrent neurons are present
535
+ # Falls back to standard shuffled-minibatch PPO if the graph holds no state
536
+ # (no GRU/LSTM neurons, no delayed edges)
536
537
  ```
537
538
 
538
539
  ### Topology controller
@@ -660,15 +661,17 @@ w = graph.effective_weight(edge_id) # reads post-softplus value
660
661
 
661
662
  ### TopologyAwareAdam
662
663
 
663
- Drop-in Adam replacement that resets (m, v) momentum state for parameters touched by a grow, prune, or merge operation. Stale momentum estimates from before a structural change would otherwise corrupt the first update on modified parameters.
664
+ Drop-in Adam replacement for graphs whose parameters get replaced by topology changes. `GraphAgent` uses it and carries Adam's (m, v) moments across every grow, prune or merge by edge id, so surviving edges keep their momentum and new edges start from zero. You can also reset the state of specific parameters yourself:
664
665
 
665
666
  ```python
666
667
  from tensor_optix.neuroevo import TopologyAwareAdam
667
668
 
668
669
  optimizer = TopologyAwareAdam(graph.parameters(), lr=3e-4)
669
- optimizer.notify_topology_change(new_params) # call after any topology mutation
670
+ optimizer.notify_topology_change(new_params) # reset (m, v) for these Parameters
670
671
  ```
671
672
 
673
+ After a rebuild, `new_optimizer.carry_over(old_optimizer, old_packed=..., old_ids=..., new_packed=..., new_ids=...)` moves the state across. See the [reference](https://sup3rus3r.github.io/tensor-optix/reference/neuroevo/topology-aware-adam/).
674
+
672
675
  ### Compiled forward
673
676
 
674
677
  `NeuronGraph` runs in **eager mode by default**. Because `_raw_forward` mutates Python-side neuron state (`neuron._current`, `push_history`), `torch.compile` cannot safely trace it without replaying those side effects. The default eager path is safe for training, recurrent neurons, and dynamic topologies.
@@ -447,7 +447,7 @@ All types implement the same protocol: `step()`, `importance()`, `can_merge_with
447
447
 
448
448
  ### Trainable recurrent neurons
449
449
 
450
- `TrainableGRUNeuron` and `TrainableLSTMNeuron` set `is_recurrent = True`. `RecurrentGraphAgent` detects this flag and switches from shuffled-minibatch PPO to sequential chunk training with truncated BPTT.
450
+ `TrainableGRUNeuron` and `TrainableLSTMNeuron` let gradients flow back through their hidden state. Use them with `RecurrentGraphAgent`, which keeps the graph's state across `act()` calls (reset at episode start via `reset_hidden()`) and trains with sequential chunks and truncated BPTT, replaying exactly what `act()` computed.
451
451
 
452
452
  ```python
453
453
  from tensor_optix.neuroevo import TrainableGRUNeuron, TrainableLSTMNeuron, RecurrentGraphAgent
@@ -461,7 +461,8 @@ agent = RecurrentGraphAgent(
461
461
  graph, obs_dim=4, n_actions=2,
462
462
  hyperparams=HyperparamSet(params={"chunk_len": 64}),
463
463
  )
464
- # Falls back to standard shuffled-minibatch PPO if no recurrent neurons are present
464
+ # Falls back to standard shuffled-minibatch PPO if the graph holds no state
465
+ # (no GRU/LSTM neurons, no delayed edges)
465
466
  ```
466
467
 
467
468
  ### Topology controller
@@ -589,15 +590,17 @@ w = graph.effective_weight(edge_id) # reads post-softplus value
589
590
 
590
591
  ### TopologyAwareAdam
591
592
 
592
- Drop-in Adam replacement that resets (m, v) momentum state for parameters touched by a grow, prune, or merge operation. Stale momentum estimates from before a structural change would otherwise corrupt the first update on modified parameters.
593
+ Drop-in Adam replacement for graphs whose parameters get replaced by topology changes. `GraphAgent` uses it and carries Adam's (m, v) moments across every grow, prune or merge by edge id, so surviving edges keep their momentum and new edges start from zero. You can also reset the state of specific parameters yourself:
593
594
 
594
595
  ```python
595
596
  from tensor_optix.neuroevo import TopologyAwareAdam
596
597
 
597
598
  optimizer = TopologyAwareAdam(graph.parameters(), lr=3e-4)
598
- optimizer.notify_topology_change(new_params) # call after any topology mutation
599
+ optimizer.notify_topology_change(new_params) # reset (m, v) for these Parameters
599
600
  ```
600
601
 
602
+ After a rebuild, `new_optimizer.carry_over(old_optimizer, old_packed=..., old_ids=..., new_packed=..., new_ids=...)` moves the state across. See the [reference](https://sup3rus3r.github.io/tensor-optix/reference/neuroevo/topology-aware-adam/).
603
+
601
604
  ### Compiled forward
602
605
 
603
606
  `NeuronGraph` runs in **eager mode by default**. Because `_raw_forward` mutates Python-side neuron state (`neuron._current`, `push_history`), `torch.compile` cannot safely trace it without replaying those side effects. The default eager path is safe for training, recurrent neurons, and dynamic topologies.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tensor-optix"
7
- version = "2.0.7"
7
+ version = "2.0.9"
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"
@@ -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, episode_n_envs, window_transition_pairs
9
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, window_transitions
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
 
@@ -113,7 +113,10 @@ class TFDQNAgent(BaseAgent):
113
113
  # DQN pushes the RAW observation into the buffer (not pre-encoded)
114
114
  # -- same single-network constraint as TorchDQNAgent, see
115
115
  # torch_dqn.py's learn() comment for the full rationale.
116
- obs_arr = to_batch_numpy(list(episode_data.observations))
116
+ # Window observations plus each env's post-window observation, so the
117
+ # last step of the window is stored too (see window_transitions).
118
+ window_obs, env_pair_lists = window_transitions(episode_data)
119
+ obs_arr = to_batch_numpy(window_obs)
117
120
  act_arr = episode_data.actions
118
121
  rew_arr = episode_data.rewards
119
122
  done_arr = episode_data.dones
@@ -122,7 +125,7 @@ class TFDQNAgent(BaseAgent):
122
125
  # Pair each step with the NEXT step of the same environment. With a
123
126
  # VectorBatchPipeline window the flat arrays interleave n_envs envs
124
127
  # ([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)):
128
+ for env_pairs in env_pair_lists:
126
129
  for t, t_next in env_pairs:
127
130
  self._buffer.push(
128
131
  batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
@@ -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, episode_n_envs, window_transition_pairs
9
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, window_transitions
10
10
  from tensor_optix.core.obs_utils import to_batch_numpy, to_tf_batch, already_batched_to_tf
11
11
 
12
12
 
@@ -168,7 +168,10 @@ class TFSACAgent(BaseAgent):
168
168
  batch_size = int(hp.get("batch_size", 256))
169
169
  updates_per_step = float(hp.get("updates_per_step", 1))
170
170
 
171
- obs_batched = to_tf_batch(list(episode_data.observations))
171
+ # Window observations plus each env's post-window observation, so the
172
+ # last step of the window is stored too (see window_transitions).
173
+ window_obs, env_pair_lists = window_transitions(episode_data)
174
+ obs_batched = to_tf_batch(window_obs)
172
175
  obs_arr = self._encode(obs_batched).numpy()
173
176
  act_arr = np.array(episode_data.actions, dtype=np.float32)
174
177
  rew_arr = episode_data.rewards
@@ -178,7 +181,7 @@ class TFSACAgent(BaseAgent):
178
181
  # Pair each step with the NEXT step of the same environment. With a
179
182
  # VectorBatchPipeline window the flat arrays interleave n_envs envs
180
183
  # ([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)):
184
+ for env_pairs in env_pair_lists:
182
185
  for t, t_next in env_pairs:
183
186
  self._buffer.push(
184
187
  obs_arr[t],
@@ -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, episode_n_envs, window_transition_pairs
64
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, window_transitions
65
65
  from tensor_optix.core.obs_utils import to_tf_batch, already_batched_to_tf
66
66
 
67
67
 
@@ -163,7 +163,10 @@ class TFTDDAgent(BaseAgent):
163
163
  updates_per_step = float(hp.get("updates_per_step", 1))
164
164
  policy_delay = int(hp.get("policy_delay", 2))
165
165
 
166
- obs_batched = to_tf_batch(list(episode_data.observations))
166
+ # Window observations plus each env's post-window observation, so the
167
+ # last step of the window is stored too (see window_transitions).
168
+ window_obs, env_pair_lists = window_transitions(episode_data)
169
+ obs_batched = to_tf_batch(window_obs)
167
170
  obs_arr = self._encode(obs_batched).numpy()
168
171
  act_arr = np.array(episode_data.actions, dtype=np.float32)
169
172
  rew_arr = episode_data.rewards
@@ -173,7 +176,7 @@ class TFTDDAgent(BaseAgent):
173
176
  # Pair each step with the NEXT step of the same environment. With a
174
177
  # VectorBatchPipeline window the flat arrays interleave n_envs envs
175
178
  # ([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)):
179
+ for env_pairs in env_pair_lists:
177
180
  for t, t_next in env_pairs:
178
181
  self._buffer.push(
179
182
  obs_arr[t], act_arr[t], float(rew_arr[t]),
@@ -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, episode_n_envs, window_transition_pairs
8
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, window_transitions
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
 
@@ -124,7 +124,10 @@ class TorchDQNAgent(BaseAgent):
124
124
  # of being bypassed via a pre-encoded buffer (see
125
125
  # tensor_optix.encoders' module docstring). PrioritizedReplayBuffer
126
126
  # already supports storing dict observations for exactly this case.
127
- obs_arr = to_batch_numpy(list(episode_data.observations))
127
+ # Window observations plus each env's post-window observation, so the
128
+ # last step of the window is stored too (see window_transitions).
129
+ window_obs, env_pair_lists = window_transitions(episode_data)
130
+ obs_arr = to_batch_numpy(window_obs)
128
131
  act_arr = episode_data.actions
129
132
  rew_arr = episode_data.rewards
130
133
  done_arr = episode_data.dones
@@ -133,7 +136,7 @@ class TorchDQNAgent(BaseAgent):
133
136
  # Pair each step with the NEXT step of the same environment. With a
134
137
  # VectorBatchPipeline window the flat arrays interleave n_envs envs
135
138
  # ([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)):
139
+ for env_pairs in env_pair_lists:
137
140
  for t, t_next in env_pairs:
138
141
  self._buffer.push(batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
139
142
  batch_index(obs_arr, t_next), bool(done_arr[t]))
@@ -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, episode_n_envs, window_transition_pairs
79
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, window_transitions
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
 
@@ -263,7 +263,10 @@ class TorchRainbowDQNAgent(BaseAgent):
263
263
  # comment): q_network sees raw observations in both act() and the
264
264
  # distributional Bellman update below, so the buffer stores the raw
265
265
  # (possibly dict) observation rather than a pre-encoded vector.
266
- obs_arr = to_batch_numpy(list(episode_data.observations))
266
+ # Window observations plus each env's post-window observation, so the
267
+ # last step of the window is stored too (see window_transitions).
268
+ window_obs, env_pair_lists = window_transitions(episode_data)
269
+ obs_arr = to_batch_numpy(window_obs)
267
270
  act_arr = episode_data.actions
268
271
  rew_arr = episode_data.rewards
269
272
  done_arr = episode_data.dones
@@ -272,7 +275,7 @@ class TorchRainbowDQNAgent(BaseAgent):
272
275
  # Pair each step with the NEXT step of the same environment. With a
273
276
  # VectorBatchPipeline window the flat arrays interleave n_envs envs
274
277
  # ([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)):
278
+ for env_pairs in env_pair_lists:
276
279
  for t, t_next in env_pairs:
277
280
  self._buffer.push(batch_index(obs_arr, t), int(act_arr[t]), float(rew_arr[t]),
278
281
  batch_index(obs_arr, t_next), bool(done_arr[t]))
@@ -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, episode_n_envs, window_transition_pairs
9
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, window_transitions
10
10
  from tensor_optix.core.obs_utils import to_torch_batch, already_batched_to_torch
11
11
 
12
12
 
@@ -162,7 +162,10 @@ class TorchSACAgent(BaseAgent):
162
162
  batch_size = int(hp.get("batch_size", 256))
163
163
  updates_per_step = float(hp.get("updates_per_step", 1))
164
164
 
165
- obs_batched = to_torch_batch(list(episode_data.observations), self._device)
165
+ # Window observations plus each env's post-window observation, so the
166
+ # last step of the window is stored too (see window_transitions).
167
+ window_obs, env_pair_lists = window_transitions(episode_data)
168
+ obs_batched = to_torch_batch(window_obs, self._device)
166
169
  obs_arr = self._encode(obs_batched).cpu().numpy()
167
170
  act_arr = np.array(episode_data.actions, dtype=np.float32)
168
171
  rew_arr = episode_data.rewards
@@ -172,7 +175,7 @@ class TorchSACAgent(BaseAgent):
172
175
  # Pair each step with the NEXT step of the same environment. With a
173
176
  # VectorBatchPipeline window the flat arrays interleave n_envs envs
174
177
  # ([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)):
178
+ for env_pairs in env_pair_lists:
176
179
  for t, t_next in env_pairs:
177
180
  self._buffer.push(obs_arr[t], act_arr[t], float(rew_arr[t]),
178
181
  obs_arr[t_next], float(done_arr[t]))
@@ -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, episode_n_envs, window_transition_pairs
89
+ from tensor_optix.core.replay_buffer import PrioritizedReplayBuffer, window_transitions
90
90
  from tensor_optix.core.obs_utils import to_torch_batch, already_batched_to_torch
91
91
 
92
92
 
@@ -195,7 +195,10 @@ class TorchTD3Agent(BaseAgent):
195
195
  updates_per_step = float(hp.get("updates_per_step", 1))
196
196
  policy_delay = int(hp.get("policy_delay", 2))
197
197
 
198
- obs_batched = to_torch_batch(list(episode_data.observations), self._device)
198
+ # Window observations plus each env's post-window observation, so the
199
+ # last step of the window is stored too (see window_transitions).
200
+ window_obs, env_pair_lists = window_transitions(episode_data)
201
+ obs_batched = to_torch_batch(window_obs, self._device)
199
202
  obs_arr = self._encode(obs_batched).cpu().numpy()
200
203
  act_arr = np.array(episode_data.actions, dtype=np.float32)
201
204
  rew_arr = episode_data.rewards
@@ -205,7 +208,7 @@ class TorchTD3Agent(BaseAgent):
205
208
  # Pair each step with the NEXT step of the same environment. With a
206
209
  # VectorBatchPipeline window the flat arrays interleave n_envs envs
207
210
  # ([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)):
211
+ for env_pairs in env_pair_lists:
209
212
  for t, t_next in env_pairs:
210
213
  self._buffer.push(
211
214
  obs_arr[t], act_arr[t], float(rew_arr[t]),
@@ -16,8 +16,14 @@ class RunningMeanStd:
16
16
  self.count = epsilon
17
17
 
18
18
  def update(self, x: np.ndarray) -> None:
19
- """Update statistics with a batch of samples (shape [N, ...] or scalar)."""
19
+ """Update statistics with a batch of samples (shape [N, ...] or scalar).
20
+
21
+ An empty batch is ignored: it carries no information, and folding its
22
+ moments in (mean of nothing = NaN) would make the statistics NaN for
23
+ good, since every later update starts from them."""
20
24
  x = np.asarray(x, dtype=np.float64)
25
+ if x.size == 0:
26
+ return
21
27
  if x.ndim == len(self.mean.shape):
22
28
  # Single sample — wrap in batch dimension
23
29
  x = x[np.newaxis]
@@ -29,6 +35,8 @@ class RunningMeanStd:
29
35
  def _update_from_moments(
30
36
  self, batch_mean: np.ndarray, batch_var: np.ndarray, batch_count: int
31
37
  ) -> None:
38
+ if batch_count <= 0:
39
+ return
32
40
  delta = batch_mean - self.mean
33
41
  tot_count = self.count + batch_count
34
42
  new_mean = self.mean + delta * batch_count / tot_count
@@ -41,13 +41,57 @@ def window_transition_pairs(T: int, n_envs: int = 1):
41
41
  there would stitch env i's observation to env i+1's as its "next state".
42
42
 
43
43
  The final step of each env has no successor inside the window and is not
44
- paired (its next observation is not part of the window arrays).
44
+ paired here. Use window_transitions() to get it paired as well.
45
45
  """
46
46
  n_envs = max(1, int(n_envs))
47
47
  for env_i in range(n_envs):
48
48
  yield [(t, t + n_envs) for t in range(env_i, T - n_envs, n_envs)]
49
49
 
50
50
 
51
+ def window_transitions(episode_data):
52
+ """
53
+ Every transition of a rollout window, including each env's last step.
54
+
55
+ Returns (observations, pair_lists): `observations` is the window's
56
+ observations with each env's post-window observation appended, and
57
+ pair_lists[env] is that env's list of (t, t_next) index pairs into it.
58
+
59
+ An env's last step is paired with:
60
+ * itself, when it was terminal: the done flag masks the bootstrap, so
61
+ the next observation is never used, but the reward is kept;
62
+ * the window's final_obs for that env, when the window ended mid-episode;
63
+ * nothing, only if the window carries no final_obs to pair it with.
64
+
65
+ final_obs is a single observation for single-env pipelines and a list
66
+ with one entry per env when metadata["n_envs"] is set (VectorBatchPipeline).
67
+ """
68
+ observations = list(episode_data.observations)
69
+ T = len(episode_data.rewards)
70
+ n_envs = episode_n_envs(episode_data)
71
+ dones = episode_data.dones
72
+ final = getattr(episode_data, "final_obs", None)
73
+ per_env = "n_envs" in (getattr(episode_data, "metadata", None) or {})
74
+ if per_env and isinstance(final, (list, tuple)) and len(final) == n_envs:
75
+ finals = list(final)
76
+ elif n_envs == 1 and not per_env:
77
+ finals = [final]
78
+ else:
79
+ finals = [None] * n_envs
80
+
81
+ pair_lists = []
82
+ for env_i, pairs in enumerate(window_transition_pairs(T, n_envs)):
83
+ pairs = list(pairs)
84
+ if env_i < T:
85
+ last = env_i + n_envs * ((T - 1 - env_i) // n_envs)
86
+ if dones[last]:
87
+ pairs.append((last, last))
88
+ elif finals[env_i] is not None:
89
+ observations.append(finals[env_i])
90
+ pairs.append((last, len(observations) - 1))
91
+ pair_lists.append(pairs)
92
+ return observations, pair_lists
93
+
94
+
51
95
  def _as_obs(obs):
52
96
  """Normalize a single observation for storage: flat/image arrays become
53
97
  float32 np.ndarray exactly as before; a dict observation (Dict space)
@@ -184,11 +228,25 @@ class PrioritizedReplayBuffer:
184
228
  self._tree = _SumTree(self._capacity)
185
229
 
186
230
  def set_params(self, alpha: float = None, beta: float = None, n_step: int = None, gamma: float = None) -> None:
187
- """Update tunable params at runtime (called by agent.set_hyperparams)."""
231
+ """Update tunable params at runtime (called by agent.set_hyperparams).
232
+
233
+ Switching between uniform (alpha=0) and prioritized (alpha>0) replay
234
+ moves the stored transitions to the new storage, so nothing collected
235
+ so far is lost. Transitions entering prioritized replay this way get
236
+ the current max priority, as new transitions do."""
188
237
  if alpha is not None:
189
- self._alpha = float(alpha)
190
- if self._alpha > 0:
238
+ new_alpha = float(alpha)
239
+ was_uniform = self._alpha == 0
240
+ self._alpha = new_alpha
241
+ if was_uniform and new_alpha > 0:
191
242
  self._ensure_tree()
243
+ priority = self._tree.max_priority
244
+ for item in self._uniform_buf:
245
+ self._tree.add(priority, item)
246
+ self._uniform_buf.clear()
247
+ elif not was_uniform and new_alpha == 0 and self._tree is not None:
248
+ self._uniform_buf.extend(self._tree_items_oldest_first())
249
+ self._tree = None
192
250
  if beta is not None:
193
251
  self._beta = float(beta)
194
252
  if n_step is not None:
@@ -196,6 +254,13 @@ class PrioritizedReplayBuffer:
196
254
  if gamma is not None:
197
255
  self._gamma = float(gamma)
198
256
 
257
+ def _tree_items_oldest_first(self) -> list:
258
+ tree = self._tree
259
+ if tree.size < tree._capacity:
260
+ return list(tree._data[:tree.size])
261
+ w = tree._write
262
+ return tree._data[w:] + tree._data[:w]
263
+
199
264
  def push(self, obs, action, reward, next_obs, done) -> None:
200
265
  obs = _as_obs(obs)
201
266
  next_obs = _as_obs(next_obs)
@@ -65,6 +65,9 @@ def compute_vtrace_targets(
65
65
  advantages shape [T] IS-corrected policy-gradient advantages
66
66
  """
67
67
  T = len(rewards)
68
+ if T == 0:
69
+ # Nothing to correct: no targets, no advantages.
70
+ return np.zeros(0, dtype=np.float32), np.zeros(0, dtype=np.float32)
68
71
  not_done = 1.0 - dones.astype(np.float32)
69
72
 
70
73
  # IS ratios ρ_t = exp(log π_θ − log π_μ)
@@ -1063,7 +1063,7 @@ def _make_neuroevo_feature_extractor(
1063
1063
  def save_weights(self, path):
1064
1064
  super().save_weights(path)
1065
1065
  torch.save(
1066
- {"topology": graph.to_dict(), "graph": graph.state_dict(), "proj": _proj_cell["np"]},
1066
+ {"topology": graph.to_dict(include_weights=False), "graph": graph.state_dict(), "proj": _proj_cell["np"]},
1067
1067
  os.path.join(path, "neuro_graph.pt"),
1068
1068
  )
1069
1069