1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//! # RelayRL Types
//!
//! Core data types and codec utilities shared across the RelayRL stack. This is the
//! lowest-level crate: it owns the on-the-wire and in-memory representations that every
//! other crate (`relayrl_algorithms`, `relayrl_framework`) builds on, and it deliberately
//! contains no runtime, networking, or training logic.
//!
//! ## Where this crate sits
//!
//! ```text
//! relayrl_framework (client runtime, routing, sinks)
//! |
//! +-- relayrl_algorithms (PPO/IPPO/MAPPO, networks)
//! |
//! +-- relayrl_types (this crate: actions, tensors, trajectories, codecs)
//! ```
//!
//! ## System layout
//!
//! - [`data`]: the public data model.
//! - [`data::action`]: [`RelayRLAction`](data::action::RelayRLAction), the unit of
//! experience (observation, action, mask, reward, done, auxiliary data, agent id),
//! plus the [`EncodedAction`](data::action::EncodedAction) codec wrapper.
//! - [`data::tensor`]: the backend-agnostic [`TensorData`](data::tensor::TensorData)
//! container, [`DType`](data::tensor::DType) / [`DeviceType`](data::tensor::DeviceType),
//! and the [`BackendMatcher`](data::tensor::BackendMatcher) /
//! [`SupportedTensorBackend`](data::tensor::SupportedTensorBackend) machinery that maps
//! RelayRL types onto concrete Burn backends.
//! - [`data::trajectory`]: [`RelayRLTrajectory`](data::trajectory::RelayRLTrajectory), an
//! ordered buffer of actions with provenance metadata (agent/env ids, episode, policy
//! version).
//! - `data::records`: Arrow and CSV adapters for persisting trajectories to disk.
//! - `data::utilities`: the codec pipeline (compression, encryption, integrity, metadata,
//! quantization, chunking) used by transport-backed workflows.
//! - [`model`]: hot-reloadable inference model wrappers
//! ([`ModelModule`](model::ModelModule), [`HotReloadableModel`](model::HotReloadableModel)),
//! compiled only when an inference model feature and a tensor backend are both enabled.
//! - [`prelude`]: grouped re-exports (`action`, `tensor`, `trajectory`, `records`, `model`,
//! `codec`) intended as the primary import surface for downstream crates.
//! - [`HyperparameterArgs`]: shared hyperparameter input shape (map or `key=value` list).
//!
//! ## Design notes
//!
//! - **Backend-agnostic by construction.** [`TensorData`](data::tensor::TensorData) stores
//! raw bytes plus a [`DType`](data::tensor::DType) and a target backend, and is only
//! materialized into a concrete Burn `Tensor` on demand via the `to_*_tensor` helpers.
//! This keeps the data model serializable and independent of any one tensor library.
//! - **Exactly one numeric backend at a time.** `ndarray-backend` (CPU) and `tch-backend`
//! (LibTorch/GPU) are mutually exclusive in practice; most public items are gated behind
//! `any(feature = "ndarray-backend", feature = "tch-backend")`.
//! - **Codec is opt-in and layered.** Each codec stage is its own feature so a build only
//! pays for what it uses; the `codec-basic`/`codec-secure`/`codec-full` bundles compose them.
//!
//! ## Feature flags
//!
//! - `ndarray-backend` (default): CPU tensors via `burn-ndarray`.
//! - `tch-backend`: LibTorch tensors via `burn-tch`.
//! - `onnx-model` (default) / `tch-model` / `inference-models`: inference model support.
//! - `compression`, `encryption`, `integrity`, `metadata`, `quantization`, `zerocopy`:
//! individual codec stages.
//! - `codec-basic`, `codec-secure`, `codec-full`: convenience bundles of the above.
//!
//! ## Quick start
//!
//! Build actions and collect them into a trajectory (works with the default
//! `ndarray-backend` feature):
//!
//! ```no_run
//! use relayrl_types::prelude::action::RelayRLAction;
//! use relayrl_types::prelude::trajectory::RelayRLTrajectory;
//! use uuid::Uuid;
//!
//! // A trajectory is an ordered, capacity-bounded buffer of actions.
//! let mut trajectory = RelayRLTrajectory::with_agent_id(1_000, Uuid::new_v4());
//!
//! // `minimal` records only reward + done; `add_action` returns `true` when the
//! // trajectory should be flushed (capacity reached or `done == true`).
//! trajectory.add_action(RelayRLAction::minimal(1.0, false));
//! let should_flush = trajectory.add_action(RelayRLAction::minimal(2.0, true));
//!
//! assert!(should_flush);
//! assert_eq!(trajectory.len(), 2);
//! assert_eq!(trajectory.total_reward(), 3.0);
//! ```
//!
//! For tensor-backed actions, convert a Burn tensor into
//! [`TensorData`](data::tensor::TensorData) and pass it to
//! [`RelayRLAction::new`](data::action::RelayRLAction::new); see the crate README for a full
//! tensor round-trip example.
use HashMap;
/// Hyperparameter inputs for algorithms — either a key-value map or a flat `key=value` argument list.