ssapling 0.1.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.
- ssapling/__init__.py +12 -0
- ssapling/core/__init__.py +53 -0
- ssapling/core/_declarations.py +139 -0
- ssapling/core/_execution.py +155 -0
- ssapling/core/_plain.py +37 -0
- ssapling/core/_text.py +42 -0
- ssapling/core/errors.py +175 -0
- ssapling/core/loading.py +205 -0
- ssapling/core/registry.py +345 -0
- ssapling/core/settings.py +698 -0
- ssapling/core/spec.py +98 -0
- ssapling/data/__init__.py +89 -0
- ssapling/data/_matching.py +22 -0
- ssapling/data/batching.py +166 -0
- ssapling/data/collections.py +335 -0
- ssapling/data/encoding.py +107 -0
- ssapling/data/errors.py +104 -0
- ssapling/data/provenance.py +94 -0
- ssapling/data/records.py +546 -0
- ssapling/data/sampling.py +339 -0
- ssapling/data/storage.py +569 -0
- ssapling/environments/__init__.py +43 -0
- ssapling/environments/contracts.py +168 -0
- ssapling/environments/errors.py +53 -0
- ssapling/environments/runner.py +153 -0
- ssapling/environments/types.py +173 -0
- ssapling/evaluate/__init__.py +40 -0
- ssapling/evaluate/aggregation.py +173 -0
- ssapling/evaluate/assessment.py +429 -0
- ssapling/evaluate/measurement.py +165 -0
- ssapling/interaction/__init__.py +24 -0
- ssapling/interaction/episode.py +713 -0
- ssapling/interaction/errors.py +21 -0
- ssapling/interaction/hosting.py +287 -0
- ssapling/models/__init__.py +44 -0
- ssapling/models/buffering.py +189 -0
- ssapling/models/contracts.py +181 -0
- ssapling/models/errors.py +27 -0
- ssapling/models/types.py +75 -0
- ssapling/py.typed +0 -0
- ssapling/registries.py +37 -0
- ssapling/tasks/__init__.py +49 -0
- ssapling/tasks/contracts.py +137 -0
- ssapling/tasks/errors.py +37 -0
- ssapling/tasks/types.py +172 -0
- ssapling/teachers/__init__.py +34 -0
- ssapling/teachers/contracts.py +145 -0
- ssapling/teachers/errors.py +80 -0
- ssapling/teachers/runner.py +142 -0
- ssapling/teachers/types.py +178 -0
- ssapling/train/__init__.py +43 -0
- ssapling/train/components.py +194 -0
- ssapling/train/context.py +169 -0
- ssapling/train/errors.py +24 -0
- ssapling/train/procedure.py +316 -0
- ssapling/train/runner.py +398 -0
- ssapling/train/stages.py +463 -0
- ssapling-0.1.0.dist-info/METADATA +113 -0
- ssapling-0.1.0.dist-info/RECORD +61 -0
- ssapling-0.1.0.dist-info/WHEEL +4 -0
- ssapling-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Measurements: one value per instance, taken from its attempt, with a status.
|
|
2
|
+
|
|
3
|
+
A **measurement** is a function that takes a ``Trial`` (the instance, its
|
|
4
|
+
record, the outcome, and the task) and returns a value. It is registered by
|
|
5
|
+
name in ``measurements``:
|
|
6
|
+
|
|
7
|
+
def steps(trial):
|
|
8
|
+
return len(trial.record.steps)
|
|
9
|
+
|
|
10
|
+
measurements.register("steps", steps)
|
|
11
|
+
|
|
12
|
+
Every value carries a status, so a missing value is never mistaken for
|
|
13
|
+
zero: see ``MeasuredValue``.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from collections.abc import Callable, Mapping
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
from typing import Any, Literal
|
|
19
|
+
|
|
20
|
+
from ..core import Registry
|
|
21
|
+
from ..data import Record, RecordStatus
|
|
22
|
+
from ..tasks import Instance, Score
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"InstanceResult",
|
|
26
|
+
"MeasuredValue",
|
|
27
|
+
"Trial",
|
|
28
|
+
"ValueStatus",
|
|
29
|
+
"measurements",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
ValueStatus = Literal["available", "external", "unavailable", "failed"]
|
|
33
|
+
"""Where a measured value came from, or why there is none.
|
|
34
|
+
|
|
35
|
+
``available``: computed here. ``external``: reported by a service, such as
|
|
36
|
+
an ARC-AGI-3 scorecard, and kept as reported. ``unavailable``: it cannot be
|
|
37
|
+
computed, for example because no reference is accessible. ``failed``: the
|
|
38
|
+
measurement raised an error, or the attempt could not be completed.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
43
|
+
class MeasuredValue:
|
|
44
|
+
"""One measurement of one instance, or the reason there is none.
|
|
45
|
+
|
|
46
|
+
Attributes:
|
|
47
|
+
status: See ``ValueStatus``.
|
|
48
|
+
value: The value. ``None`` exactly when unavailable or failed.
|
|
49
|
+
detail: Optional. More about the value, or why there is none, such
|
|
50
|
+
as the error.
|
|
51
|
+
|
|
52
|
+
Build one with ``MeasuredValue.available(value)``, ``.external(value)``,
|
|
53
|
+
``.unavailable(reason)``, or ``.failed(reason)``.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
status: ValueStatus
|
|
57
|
+
value: Any = None
|
|
58
|
+
detail: Any = None
|
|
59
|
+
|
|
60
|
+
def __post_init__(self) -> None:
|
|
61
|
+
if self.status not in ("available", "external", "unavailable", "failed"):
|
|
62
|
+
raise ValueError(
|
|
63
|
+
"status must be 'available', 'external', 'unavailable', or 'failed', "
|
|
64
|
+
f"got {self.status!r}"
|
|
65
|
+
)
|
|
66
|
+
if (self.value is None) != (self.status in ("unavailable", "failed")):
|
|
67
|
+
raise ValueError(
|
|
68
|
+
f"a value is required when {self.status!r} and not allowed otherwise; "
|
|
69
|
+
"put a reason in detail"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
@classmethod
|
|
73
|
+
def available(cls, value: Any, detail: Any = None) -> "MeasuredValue":
|
|
74
|
+
"""A value computed here."""
|
|
75
|
+
return cls(status="available", value=value, detail=detail)
|
|
76
|
+
|
|
77
|
+
@classmethod
|
|
78
|
+
def external(cls, value: Any, detail: Any = None) -> "MeasuredValue":
|
|
79
|
+
"""A value reported by an external service, kept as reported."""
|
|
80
|
+
return cls(status="external", value=value, detail=detail)
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def unavailable(cls, reason: Any = None) -> "MeasuredValue":
|
|
84
|
+
"""No value can be computed; ``reason`` says why."""
|
|
85
|
+
return cls(status="unavailable", detail=reason)
|
|
86
|
+
|
|
87
|
+
@classmethod
|
|
88
|
+
def failed(cls, reason: Any = None) -> "MeasuredValue":
|
|
89
|
+
"""The measurement, or the attempt, failed; ``reason`` says how."""
|
|
90
|
+
return cls(status="failed", detail=reason)
|
|
91
|
+
|
|
92
|
+
@classmethod
|
|
93
|
+
def of(cls, value: Any) -> "MeasuredValue":
|
|
94
|
+
"""What a measurement returned, as a measured value.
|
|
95
|
+
|
|
96
|
+
A ``MeasuredValue`` is kept. A task's ``Score`` keeps its status:
|
|
97
|
+
local becomes available. ``None`` is unavailable. Anything else is
|
|
98
|
+
available.
|
|
99
|
+
"""
|
|
100
|
+
if isinstance(value, MeasuredValue):
|
|
101
|
+
return value
|
|
102
|
+
if isinstance(value, Score):
|
|
103
|
+
if value.status == "unavailable":
|
|
104
|
+
return cls.unavailable(value.detail)
|
|
105
|
+
if value.status == "external":
|
|
106
|
+
return cls.external(value.value, value.detail)
|
|
107
|
+
return cls.available(value.value, value.detail)
|
|
108
|
+
if value is None:
|
|
109
|
+
return cls.unavailable("the measurement gave no value")
|
|
110
|
+
return cls.available(value)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@dataclass(frozen=True, slots=True)
|
|
114
|
+
class Trial:
|
|
115
|
+
"""One instance's attempt, as a measurement sees it.
|
|
116
|
+
|
|
117
|
+
Attributes:
|
|
118
|
+
instance: The instance attempted, reference included.
|
|
119
|
+
record: The attempt's record: every step, with its observations,
|
|
120
|
+
actions, teacher responses, timing and model diagnostics.
|
|
121
|
+
outcome: What the task scores: by default the last prediction, or
|
|
122
|
+
the final observation (see ``StandardAssessment``).
|
|
123
|
+
task: The task, for its ``score`` and ``check_partial``.
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
instance: Instance
|
|
127
|
+
record: Record
|
|
128
|
+
outcome: Any
|
|
129
|
+
task: Any
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
133
|
+
class InstanceResult:
|
|
134
|
+
"""What an assessment found for one instance.
|
|
135
|
+
|
|
136
|
+
Attributes:
|
|
137
|
+
instance_id: The instance's id.
|
|
138
|
+
collection: The collection it was drawn from.
|
|
139
|
+
descriptors: The instance's descriptors, for grouping.
|
|
140
|
+
record_id: Its record's id, to read the record back from the store.
|
|
141
|
+
status: How its attempt ended: ``"terminated"``, ``"truncated"``,
|
|
142
|
+
or ``"failed"``.
|
|
143
|
+
values: Its measured values, keyed by measurement name.
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
instance_id: str
|
|
147
|
+
collection: str
|
|
148
|
+
descriptors: Mapping[str, Any]
|
|
149
|
+
record_id: str
|
|
150
|
+
status: RecordStatus
|
|
151
|
+
values: Mapping[str, MeasuredValue]
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def score(trial: Trial) -> Any:
|
|
155
|
+
"""The task's score of the outcome: ``task.score(instance, outcome)``."""
|
|
156
|
+
return trial.task.score(trial.instance, trial.outcome)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
measurements: Registry[Callable[[Trial], Any]] = Registry("measurement")
|
|
160
|
+
"""Registered measurements. Also available as ``ssapling.registries.measurements``.
|
|
161
|
+
|
|
162
|
+
A measurement is registered as the function itself, and looked up by name
|
|
163
|
+
with ``measurements.get(name)``. ``"score"`` is built in.
|
|
164
|
+
"""
|
|
165
|
+
measurements.register("score", score)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""SSAPling interaction.
|
|
2
|
+
|
|
3
|
+
Responsibility: The loop that runs episodes: driving environments, models, and
|
|
4
|
+
teachers under the chosen timing and execution, static solving, and writing
|
|
5
|
+
records.
|
|
6
|
+
|
|
7
|
+
Not its responsibility: Choosing instances, deciding when episodes run,
|
|
8
|
+
scoring.
|
|
9
|
+
|
|
10
|
+
May import: core, tasks, environments, teachers, models, data. Enforced by
|
|
11
|
+
tests/test_layering.py.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from .episode import EpisodeSettings, run_episode, solve
|
|
15
|
+
from .errors import ComponentProcessError
|
|
16
|
+
from .hosting import in_process
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"ComponentProcessError",
|
|
20
|
+
"EpisodeSettings",
|
|
21
|
+
"in_process",
|
|
22
|
+
"run_episode",
|
|
23
|
+
"solve",
|
|
24
|
+
]
|