sequence-base 0.3.0__py3-none-any.whl

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 (84) hide show
  1. sequence_base/__init__.py +134 -0
  2. sequence_base/auth.py +35 -0
  3. sequence_base/codec/__init__.py +25 -0
  4. sequence_base/codec/image.py +136 -0
  5. sequence_base/codec/resize.py +147 -0
  6. sequence_base/constants/__init__.py +0 -0
  7. sequence_base/constants/env.py +14 -0
  8. sequence_base/constants/headers.py +5 -0
  9. sequence_base/constants/version.py +9 -0
  10. sequence_base/contract/__init__.py +111 -0
  11. sequence_base/contract/accounts.py +93 -0
  12. sequence_base/contract/act.py +89 -0
  13. sequence_base/contract/benchmarks.py +130 -0
  14. sequence_base/contract/connect.py +53 -0
  15. sequence_base/contract/deployments.py +197 -0
  16. sequence_base/contract/errors.py +45 -0
  17. sequence_base/contract/eval.py +201 -0
  18. sequence_base/contract/flags.py +92 -0
  19. sequence_base/contract/policy.py +172 -0
  20. sequence_base/errors/__init__.py +0 -0
  21. sequence_base/errors/transport.py +36 -0
  22. sequence_base/obs/__init__.py +0 -0
  23. sequence_base/obs/log.py +57 -0
  24. sequence_base/obs/rid.py +31 -0
  25. sequence_base/schema_export.py +238 -0
  26. sequence_base/schemas/ActionChunk.json +102 -0
  27. sequence_base/schemas/ActionContract.json +43 -0
  28. sequence_base/schemas/ActionStep.json +23 -0
  29. sequence_base/schemas/AdapterTransform.json +42 -0
  30. sequence_base/schemas/Autoscaler.json +43 -0
  31. sequence_base/schemas/BenchmarkRegisterRequest.json +302 -0
  32. sequence_base/schemas/BenchmarkSpec.json +401 -0
  33. sequence_base/schemas/BootstrapResponse.json +76 -0
  34. sequence_base/schemas/ClampInfo.json +27 -0
  35. sequence_base/schemas/CodeBundle.json +27 -0
  36. sequence_base/schemas/Concurrency.json +21 -0
  37. sequence_base/schemas/Conditions.json +59 -0
  38. sequence_base/schemas/ConnectRequest.json +16 -0
  39. sequence_base/schemas/ConnectResponse.json +81 -0
  40. sequence_base/schemas/DeploymentAccepted.json +22 -0
  41. sequence_base/schemas/DeploymentPolicy.json +101 -0
  42. sequence_base/schemas/DeploymentRequest.json +467 -0
  43. sequence_base/schemas/DeploymentStatusResponse.json +45 -0
  44. sequence_base/schemas/ErrorBody.json +32 -0
  45. sequence_base/schemas/Estimate.json +25 -0
  46. sequence_base/schemas/EvalDryRunResponse.json +41 -0
  47. sequence_base/schemas/EvalReport.json +179 -0
  48. sequence_base/schemas/EvalRequest.json +111 -0
  49. sequence_base/schemas/EvalResponse.json +88 -0
  50. sequence_base/schemas/ImageFrame.json +36 -0
  51. sequence_base/schemas/ImageSpec.json +123 -0
  52. sequence_base/schemas/ImageStepApt.json +18 -0
  53. sequence_base/schemas/ImageStepEnv.json +18 -0
  54. sequence_base/schemas/ImageStepRun.json +18 -0
  55. sequence_base/schemas/ImageStepUvPip.json +18 -0
  56. sequence_base/schemas/Lease.json +28 -0
  57. sequence_base/schemas/LossyTransform.json +21 -0
  58. sequence_base/schemas/MetricAgg.json +87 -0
  59. sequence_base/schemas/Observation.json +133 -0
  60. sequence_base/schemas/PolicyRegistration.json +438 -0
  61. sequence_base/schemas/PolicySpec.json +346 -0
  62. sequence_base/schemas/Proprioception.json +67 -0
  63. sequence_base/schemas/RenderSpec.json +22 -0
  64. sequence_base/schemas/Resources.json +29 -0
  65. sequence_base/schemas/RolloutResult.json +59 -0
  66. sequence_base/schemas/SecretCreateRequest.json +25 -0
  67. sequence_base/schemas/SecretInfo.json +44 -0
  68. sequence_base/schemas/SecretRef.json +16 -0
  69. sequence_base/schemas/SeqFlags.json +33 -0
  70. sequence_base/schemas/Step.json +68 -0
  71. sequence_base/schemas/SuiteAgg.json +26 -0
  72. sequence_base/schemas/TaskAgg.json +26 -0
  73. sequence_base/schemas/Timeouts.json +20 -0
  74. sequence_base/schemas/UsageReport.json +38 -0
  75. sequence_base/schemas/Variant.json +24 -0
  76. sequence_base/schemas/VolumeAttach.json +26 -0
  77. sequence_base/schemas/VolumeMount.json +21 -0
  78. sequence_base/schemas/VolumeRef.json +28 -0
  79. sequence_base/schemas/WarmingError.json +50 -0
  80. sequence_base/telemetry/__init__.py +13 -0
  81. sequence_base/telemetry/events.py +101 -0
  82. sequence_base-0.3.0.dist-info/METADATA +12 -0
  83. sequence_base-0.3.0.dist-info/RECORD +84 -0
  84. sequence_base-0.3.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,238 @@
1
+ """
2
+ JSON Schema export for every W0.1 wire type — the deliverable is "wire types + JSON schema".
3
+
4
+ Each pydantic model is exported via `model_json_schema()`; `SeqFlags` (an IntFlag, for which
5
+ `model_json_schema()` does not apply) is exported as an integer with a named-member enum. Every schema
6
+ carries `x-contract-version` (constants.version.CONTRACT_VERSION) as a schema-level version stamp.
7
+
8
+ Determinism is the contract: `render(...)` serializes with sorted keys + fixed indent, so the bytes are a
9
+ pure function of the Python definitions. `export_all()` writes them under `sequence_base/schemas/`; a test
10
+ regenerates in memory and asserts byte-for-byte equality with what is on disk (no drift), and that every
11
+ instance serialized round-trips through its own exported schema.
12
+
13
+ Regenerate after any shape change: `python -m sequence_base.schema_export`
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ from pathlib import Path
19
+
20
+ from pydantic import BaseModel
21
+
22
+ from sequence_base.constants.version import CONTRACT_VERSION
23
+ from sequence_base.contract.accounts import (
24
+ BootstrapResponse,
25
+ SecretCreateRequest,
26
+ SecretInfo,
27
+ SecretRef,
28
+ UsageReport,
29
+ )
30
+ from sequence_base.contract.act import (
31
+ ActionChunk,
32
+ ActionStep,
33
+ ImageFrame,
34
+ Observation,
35
+ Proprioception,
36
+ )
37
+ from sequence_base.contract.benchmarks import (
38
+ BenchmarkRegisterRequest,
39
+ BenchmarkSpec,
40
+ Conditions,
41
+ RenderSpec,
42
+ Step,
43
+ Variant,
44
+ )
45
+ from sequence_base.contract.connect import ConnectRequest, ConnectResponse, Lease
46
+ from sequence_base.contract.deployments import (
47
+ Autoscaler,
48
+ CodeBundle,
49
+ DeploymentAccepted,
50
+ DeploymentPolicy,
51
+ DeploymentRequest,
52
+ DeploymentStatusResponse,
53
+ Resources,
54
+ Timeouts,
55
+ VolumeAttach,
56
+ )
57
+ from sequence_base.contract.errors import ErrorBody, WarmingError
58
+ from sequence_base.contract.eval import (
59
+ AdapterTransform,
60
+ ClampInfo,
61
+ Estimate,
62
+ EvalDryRunResponse,
63
+ EvalReport,
64
+ EvalRequest,
65
+ EvalResponse,
66
+ LossyTransform,
67
+ MetricAgg,
68
+ RolloutResult,
69
+ SuiteAgg,
70
+ TaskAgg,
71
+ )
72
+ from sequence_base.contract.flags import seqflags_json_schema
73
+ from sequence_base.contract.policy import (
74
+ ActionContract,
75
+ Concurrency,
76
+ ImageSpec,
77
+ ImageStepApt,
78
+ ImageStepEnv,
79
+ ImageStepRun,
80
+ ImageStepUvPip,
81
+ PolicyRegistration,
82
+ PolicySpec,
83
+ VolumeMount,
84
+ VolumeRef,
85
+ )
86
+
87
+ SCHEMA_DIR = Path(__file__).parent / "schemas"
88
+
89
+ # Every pydantic wire model, by the filename stem its schema is written under. One entry per shared
90
+ # shape — this list IS the export manifest.
91
+ WIRE_MODELS: dict[str, type[BaseModel]] = {
92
+ # contract 4 — /act data plane
93
+ "ImageFrame": ImageFrame,
94
+ "Proprioception": Proprioception,
95
+ "Observation": Observation,
96
+ "ActionStep": ActionStep,
97
+ "ActionChunk": ActionChunk,
98
+ # contract 1 — policy registry
99
+ "ImageStepUvPip": ImageStepUvPip,
100
+ "ImageStepApt": ImageStepApt,
101
+ "ImageStepEnv": ImageStepEnv,
102
+ "ImageStepRun": ImageStepRun,
103
+ "ImageSpec": ImageSpec,
104
+ "VolumeMount": VolumeMount,
105
+ "VolumeRef": VolumeRef,
106
+ "Concurrency": Concurrency,
107
+ "ActionContract": ActionContract,
108
+ "PolicySpec": PolicySpec,
109
+ "PolicyRegistration": PolicyRegistration,
110
+ # contract 2 — deployments
111
+ "Resources": Resources,
112
+ "Autoscaler": Autoscaler,
113
+ "Timeouts": Timeouts,
114
+ "VolumeAttach": VolumeAttach,
115
+ "CodeBundle": CodeBundle,
116
+ "DeploymentPolicy": DeploymentPolicy,
117
+ "DeploymentRequest": DeploymentRequest,
118
+ "DeploymentAccepted": DeploymentAccepted,
119
+ "DeploymentStatusResponse": DeploymentStatusResponse,
120
+ # contract 3 — connect / lease
121
+ "Lease": Lease,
122
+ "ConnectRequest": ConnectRequest,
123
+ "ConnectResponse": ConnectResponse,
124
+ # contract 5 — benchmark registration
125
+ "Variant": Variant,
126
+ "Conditions": Conditions,
127
+ "RenderSpec": RenderSpec,
128
+ "Step": Step,
129
+ "BenchmarkSpec": BenchmarkSpec,
130
+ "BenchmarkRegisterRequest": BenchmarkRegisterRequest,
131
+ # contract 5 — eval run / report / adapter
132
+ "EvalRequest": EvalRequest,
133
+ "ClampInfo": ClampInfo,
134
+ "Estimate": Estimate,
135
+ "EvalResponse": EvalResponse,
136
+ "EvalDryRunResponse": EvalDryRunResponse,
137
+ "RolloutResult": RolloutResult,
138
+ "SuiteAgg": SuiteAgg,
139
+ "TaskAgg": TaskAgg,
140
+ "MetricAgg": MetricAgg,
141
+ "LossyTransform": LossyTransform,
142
+ "EvalReport": EvalReport,
143
+ "AdapterTransform": AdapterTransform,
144
+ # contract 6 — accounts / secret / billing
145
+ "SecretRef": SecretRef,
146
+ "SecretCreateRequest": SecretCreateRequest,
147
+ "SecretInfo": SecretInfo,
148
+ "BootstrapResponse": BootstrapResponse,
149
+ "UsageReport": UsageReport,
150
+ # shared error bodies
151
+ "ErrorBody": ErrorBody,
152
+ "WarmingError": WarmingError,
153
+ }
154
+
155
+
156
+ def _stringify_int_property_names(schema: dict) -> None:
157
+ """JSON object keys are always strings, but pydantic renders an int-keyed dict (e.g.
158
+ dict[SeqFlags, str]) with integer `propertyNames` — inline or `$ref`-ed to an integer `$defs` enum —
159
+ which no serialized instance can satisfy (its keys are the strings "2", "16", …). Walk the schema and
160
+ rewrite any such `propertyNames` to the string form, so the exported schema accurately describes the
161
+ wire JSON. The referenced `$def` (the SeqFlags value form) is left untouched; only the key constraint
162
+ is inlined and string-encoded."""
163
+ defs = schema.get("$defs", {})
164
+
165
+ def resolve(pn: dict) -> dict | None:
166
+ if "$ref" in pn:
167
+ return defs.get(pn["$ref"].split("/")[-1])
168
+ return pn
169
+
170
+ def walk(node: object) -> None:
171
+ if isinstance(node, dict):
172
+ pn = node.get("propertyNames")
173
+ if isinstance(pn, dict):
174
+ target = resolve(pn)
175
+ if isinstance(target, dict) and target.get("type") == "integer":
176
+ fixed: dict = {"type": "string"}
177
+ if isinstance(target.get("enum"), list):
178
+ fixed["enum"] = [str(v) for v in target["enum"]]
179
+ node["propertyNames"] = fixed
180
+ for v in node.values():
181
+ walk(v)
182
+ elif isinstance(node, list):
183
+ for v in node:
184
+ walk(v)
185
+
186
+ walk(schema)
187
+
188
+
189
+ def _reconcile_embedded_seqflags(schema: dict) -> None:
190
+ """`SeqFlags` is an IntFlag whose every member is its own distinct bit. pydantic's default
191
+ `model_json_schema()` emits an embedded `$defs.SeqFlags` (present whenever a model has a
192
+ dict[SeqFlags, ...] field, e.g. PolicyRegistration.bindings / BenchmarkSpec.bindings) as a plain
193
+ integer enum with NO `x-flag-names` — which diverges from the canonical standalone
194
+ `seqflags_json_schema()` (same values, plus the name→value map).
195
+
196
+ Route the embedded def through the single source: overwrite `$defs.SeqFlags` with the canonical
197
+ schema so it is byte-identical to standalone SeqFlags.json. This runs BEFORE
198
+ `_stringify_int_property_names`, so any `propertyNames: {$ref: #/$defs/SeqFlags}` that resolves against
199
+ this def also inherits the canonical value list — the key constraint stays in lockstep."""
200
+ defs = schema.get("$defs")
201
+ if isinstance(defs, dict) and "SeqFlags" in defs:
202
+ defs["SeqFlags"] = seqflags_json_schema(CONTRACT_VERSION)
203
+
204
+
205
+ def build_schema(model: type[BaseModel]) -> dict:
206
+ """A model's JSON Schema, with the contract version stamped in."""
207
+ schema = model.model_json_schema()
208
+ _reconcile_embedded_seqflags(schema)
209
+ _stringify_int_property_names(schema)
210
+ schema["x-contract-version"] = CONTRACT_VERSION
211
+ return schema
212
+
213
+
214
+ def all_schemas() -> dict[str, dict]:
215
+ """Every exported schema, by filename stem — pydantic models plus the SeqFlags IntFlag."""
216
+ out: dict[str, dict] = {name: build_schema(m) for name, m in WIRE_MODELS.items()}
217
+ out["SeqFlags"] = seqflags_json_schema(CONTRACT_VERSION)
218
+ return out
219
+
220
+
221
+ def render(schema: dict) -> str:
222
+ """Deterministic bytes: sorted keys, fixed indent, trailing newline. A pure function of the schema."""
223
+ return json.dumps(schema, indent=2, sort_keys=True, ensure_ascii=False) + "\n"
224
+
225
+
226
+ def export_all(out_dir: Path = SCHEMA_DIR) -> list[Path]:
227
+ out_dir.mkdir(parents=True, exist_ok=True)
228
+ written: list[Path] = []
229
+ for name, schema in all_schemas().items():
230
+ path = out_dir / f"{name}.json"
231
+ path.write_text(render(schema), encoding="utf-8")
232
+ written.append(path)
233
+ return written
234
+
235
+
236
+ if __name__ == "__main__":
237
+ paths = export_all()
238
+ print(f"wrote {len(paths)} schemas to {SCHEMA_DIR} (contract_version={CONTRACT_VERSION})")
@@ -0,0 +1,102 @@
1
+ {
2
+ "$defs": {
3
+ "ActionSpace": {
4
+ "description": "Must be explicit: the same floats mean opposite things across spaces — executing an absolute\njoint position as a delta flings the arm into its limit stops. {schema.py:124}",
5
+ "enum": [
6
+ "joint_absolute",
7
+ "joint_delta",
8
+ "ee_absolute",
9
+ "ee_delta"
10
+ ],
11
+ "title": "ActionSpace",
12
+ "type": "string"
13
+ },
14
+ "ActionStep": {
15
+ "additionalProperties": false,
16
+ "properties": {
17
+ "index": {
18
+ "title": "Index",
19
+ "type": "integer"
20
+ },
21
+ "values": {
22
+ "items": {
23
+ "type": "number"
24
+ },
25
+ "title": "Values",
26
+ "type": "array"
27
+ }
28
+ },
29
+ "required": [
30
+ "index",
31
+ "values"
32
+ ],
33
+ "title": "ActionStep",
34
+ "type": "object"
35
+ }
36
+ },
37
+ "additionalProperties": false,
38
+ "description": "A chunk of actions. `covers_seconds` is what the robot schedules the next request against —\nit must ask again before this much motion finishes playing out.",
39
+ "properties": {
40
+ "action_dim": {
41
+ "title": "Action Dim",
42
+ "type": "integer"
43
+ },
44
+ "action_space": {
45
+ "$ref": "#/$defs/ActionSpace"
46
+ },
47
+ "control_frequency_hz": {
48
+ "title": "Control Frequency Hz",
49
+ "type": "number"
50
+ },
51
+ "covers_seconds": {
52
+ "title": "Covers Seconds",
53
+ "type": "number"
54
+ },
55
+ "open_loop_horizon": {
56
+ "anyOf": [
57
+ {
58
+ "type": "integer"
59
+ },
60
+ {
61
+ "type": "null"
62
+ }
63
+ ],
64
+ "default": null,
65
+ "title": "Open Loop Horizon"
66
+ },
67
+ "robot": {
68
+ "title": "Robot",
69
+ "type": "string"
70
+ },
71
+ "steps": {
72
+ "items": {
73
+ "$ref": "#/$defs/ActionStep"
74
+ },
75
+ "title": "Steps",
76
+ "type": "array"
77
+ },
78
+ "sustains_seconds": {
79
+ "anyOf": [
80
+ {
81
+ "type": "number"
82
+ },
83
+ {
84
+ "type": "null"
85
+ }
86
+ ],
87
+ "default": null,
88
+ "title": "Sustains Seconds"
89
+ }
90
+ },
91
+ "required": [
92
+ "steps",
93
+ "robot",
94
+ "action_space",
95
+ "action_dim",
96
+ "control_frequency_hz",
97
+ "covers_seconds"
98
+ ],
99
+ "title": "ActionChunk",
100
+ "type": "object",
101
+ "x-contract-version": "0.4.1"
102
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "$defs": {
3
+ "ActionSpace": {
4
+ "description": "Must be explicit: the same floats mean opposite things across spaces — executing an absolute\njoint position as a delta flings the arm into its limit stops. {schema.py:124}",
5
+ "enum": [
6
+ "joint_absolute",
7
+ "joint_delta",
8
+ "ee_absolute",
9
+ "ee_delta"
10
+ ],
11
+ "title": "ActionSpace",
12
+ "type": "string"
13
+ }
14
+ },
15
+ "additionalProperties": false,
16
+ "description": "The fixed obs→ActionChunk contract a policy promises. Every field required; `action_space` reuses\ncontract 4's enum (not a free string). Each ActionChunk echoes exactly these invariants back.",
17
+ "properties": {
18
+ "action_dim": {
19
+ "title": "Action Dim",
20
+ "type": "integer"
21
+ },
22
+ "action_space": {
23
+ "$ref": "#/$defs/ActionSpace"
24
+ },
25
+ "control_frequency_hz": {
26
+ "title": "Control Frequency Hz",
27
+ "type": "number"
28
+ },
29
+ "robot": {
30
+ "title": "Robot",
31
+ "type": "string"
32
+ }
33
+ },
34
+ "required": [
35
+ "robot",
36
+ "action_space",
37
+ "action_dim",
38
+ "control_frequency_hz"
39
+ ],
40
+ "title": "ActionContract",
41
+ "type": "object",
42
+ "x-contract-version": "0.4.1"
43
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "additionalProperties": false,
3
+ "properties": {
4
+ "index": {
5
+ "title": "Index",
6
+ "type": "integer"
7
+ },
8
+ "values": {
9
+ "items": {
10
+ "type": "number"
11
+ },
12
+ "title": "Values",
13
+ "type": "array"
14
+ }
15
+ },
16
+ "required": [
17
+ "index",
18
+ "values"
19
+ ],
20
+ "title": "ActionStep",
21
+ "type": "object",
22
+ "x-contract-version": "0.4.1"
23
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "$defs": {
3
+ "AdapterKind": {
4
+ "enum": [
5
+ "lossless",
6
+ "lossy"
7
+ ],
8
+ "title": "AdapterKind",
9
+ "type": "string"
10
+ }
11
+ },
12
+ "additionalProperties": false,
13
+ "description": "One adapter transform, classified. A lossy transform must carry a non-empty reason; a lossless one\nneeds none. The lossy element's shape ({transform, reason}) aligns with EvalReport.adapter_lossy.",
14
+ "properties": {
15
+ "kind": {
16
+ "$ref": "#/$defs/AdapterKind"
17
+ },
18
+ "reason": {
19
+ "anyOf": [
20
+ {
21
+ "type": "string"
22
+ },
23
+ {
24
+ "type": "null"
25
+ }
26
+ ],
27
+ "default": null,
28
+ "title": "Reason"
29
+ },
30
+ "transform": {
31
+ "title": "Transform",
32
+ "type": "string"
33
+ }
34
+ },
35
+ "required": [
36
+ "kind",
37
+ "transform"
38
+ ],
39
+ "title": "AdapterTransform",
40
+ "type": "object",
41
+ "x-contract-version": "0.4.1"
42
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "additionalProperties": false,
3
+ "description": "= Modal AutoscalerSettings. Defaults mirror PolicySpec so an omitted block scale-to-zeroes.",
4
+ "properties": {
5
+ "buffer_containers": {
6
+ "anyOf": [
7
+ {
8
+ "type": "integer"
9
+ },
10
+ {
11
+ "type": "null"
12
+ }
13
+ ],
14
+ "default": null,
15
+ "title": "Buffer Containers"
16
+ },
17
+ "max_containers": {
18
+ "anyOf": [
19
+ {
20
+ "type": "integer"
21
+ },
22
+ {
23
+ "type": "null"
24
+ }
25
+ ],
26
+ "default": null,
27
+ "title": "Max Containers"
28
+ },
29
+ "min_containers": {
30
+ "default": 0,
31
+ "title": "Min Containers",
32
+ "type": "integer"
33
+ },
34
+ "scaledown_window": {
35
+ "default": 600,
36
+ "title": "Scaledown Window",
37
+ "type": "integer"
38
+ }
39
+ },
40
+ "title": "Autoscaler",
41
+ "type": "object",
42
+ "x-contract-version": "0.4.1"
43
+ }