xrtm-train 0.1.1__py3-none-any.whl → 0.2.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.
@@ -0,0 +1,24 @@
1
+ # coding=utf-8
2
+ # Copyright 2026 XRTM Team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ r"""
17
+ Researcher Kit for xrtm-train.
18
+
19
+ This module provides high-level, composable utilities for training.
20
+ Includes memory management, optimization strategies, and utilities
21
+ built on top of the core interfaces.
22
+ """
23
+
24
+ __all__: list[str] = []
@@ -8,6 +8,7 @@ from xrtm.forecast.kit.memory.unified import Memory as UnifiedMemory
8
8
 
9
9
  logger = logging.getLogger(__name__)
10
10
 
11
+
11
12
  class EpisodicLearner:
12
13
  def __init__(self, memory: UnifiedMemory):
13
14
  self.memory = memory
@@ -18,12 +19,15 @@ class EpisodicLearner:
18
19
  experiences = self.memory.retrieve_similar(query, n_results=n_results)
19
20
  if not experiences:
20
21
  return "No relevant past experiences found."
21
- formatted_lessons = "\n--- PAST LESSONS LEARNED ---\n"
22
+ formatted_lessons = ["\n--- PAST LESSONS LEARNED ---\n"]
22
23
  for i, doc in enumerate(experiences, 1):
23
- formatted_lessons += f"Experience {i}:\n{doc.strip()}\n"
24
- return formatted_lessons
24
+ formatted_lessons.append(f"Experience {i}:\n")
25
+ formatted_lessons.append(doc.strip())
26
+ formatted_lessons.append("\n")
27
+ return "".join(formatted_lessons)
25
28
  except Exception as e:
26
29
  logger.error(f"[LEARNER] Failed to retrieve lessons: {e}")
27
30
  return "Error retrieving past lessons."
28
31
 
32
+
29
33
  __all__ = ["EpisodicLearner"]
@@ -9,6 +9,7 @@ from xrtm.forecast.kit.agents.prompting import CompiledAgent, PromptTemplate
9
9
 
10
10
  logger = logging.getLogger(__name__)
11
11
 
12
+
12
13
  class BrierOptimizer:
13
14
  def __init__(self, optimizer_model: Any):
14
15
  self.optimizer_model = optimizer_model
@@ -29,4 +30,5 @@ class BrierOptimizer:
29
30
  instruction=new_instruction.strip(), examples=agent.template.examples, version=agent.template.version + 1
30
31
  )
31
32
 
33
+
32
34
  __all__ = ["BrierOptimizer"]
@@ -0,0 +1,24 @@
1
+ # coding=utf-8
2
+ # Copyright 2026 XRTM Team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ r"""
17
+ External providers for xrtm-train.
18
+
19
+ This module provides adapters for external training services.
20
+ Currently empty - will be populated with remote training APIs,
21
+ distributed training backends, etc.
22
+ """
23
+
24
+ __all__: list[str] = []
@@ -13,6 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ import asyncio
16
17
  import logging
17
18
  from typing import List, Tuple
18
19
 
@@ -20,7 +21,7 @@ from typing import List, Tuple
20
21
  from xrtm.data.schemas.forecast import ForecastQuestion
21
22
 
22
23
  # From xrtm-eval
23
- from xrtm.eval.core.eval.definitions import EvaluationReport, EvaluationResult, Evaluator
24
+ from xrtm.eval.core.eval.definitions import EvaluationReport, Evaluator
24
25
  from xrtm.eval.schemas.forecast import ForecastResolution
25
26
 
26
27
  # From xrtm-forecast (Internal)
@@ -37,23 +38,25 @@ class Backtester:
37
38
  self.evaluator = evaluator
38
39
 
39
40
  async def run(self, dataset: List[Tuple[ForecastQuestion, ForecastResolution]]) -> EvaluationReport:
40
- results: List[EvaluationResult] = []
41
- total_score = 0.0
42
-
43
- for question, resolution in dataset:
41
+ async def process_question(question, resolution):
44
42
  try:
45
43
  logger.info(f"Backtesting question: {question.id}")
46
44
  prediction = await self.agent.run(question)
47
45
  conf = getattr(prediction, "confidence", prediction)
48
- eval_res = self.evaluator.evaluate(
49
- prediction=conf, ground_truth=resolution.outcome, subject_id=question.id
50
- )
51
- results.append(eval_res)
52
- total_score += eval_res.score
46
+ return self.evaluator.evaluate(prediction=conf, ground_truth=resolution.outcome, subject_id=question.id)
53
47
  except Exception as e:
54
48
  logger.error(f"Failed to evaluate question {question.id}: {e}")
49
+ return None
50
+
51
+ # Execute all questions concurrently
52
+ tasks = [process_question(q, r) for q, r in dataset]
53
+ processed_results = await asyncio.gather(*tasks)
54
+
55
+ # Filter out failed evaluations
56
+ results = [res for res in processed_results if res is not None]
55
57
 
56
58
  count = len(results)
59
+ total_score = sum(res.score for res in results)
57
60
  mean_score = total_score / count if count > 0 else 0.0
58
61
 
59
62
  return EvaluationReport(
@@ -35,6 +35,9 @@ from xrtm.forecast.core.schemas.graph import BaseGraphState, TemporalContext
35
35
 
36
36
  logger = logging.getLogger(__name__)
37
37
 
38
+ TRUE_VALUES = {"true", "yes", "1", "pass"}
39
+ FALSE_VALUES = {"false", "no", "0", "fail"}
40
+
38
41
 
39
42
  class BacktestInstance(BaseModel):
40
43
  """Represents a single instance in a backtest dataset."""
@@ -101,7 +104,7 @@ class BacktestRunner:
101
104
  tags: Optional[List[str]] = None,
102
105
  ) -> EvaluationResult:
103
106
  prediction_val = 0.5
104
- for report in reversed(list(state.node_reports.values())):
107
+ for _, report in reversed(state.node_reports.items()):
105
108
  if isinstance(report, ForecastOutput):
106
109
  prediction_val = report.confidence
107
110
  break
@@ -114,9 +117,10 @@ class BacktestRunner:
114
117
 
115
118
  outcome_raw = resolution.outcome
116
119
  if isinstance(outcome_raw, str):
117
- if outcome_raw.lower() in ["true", "yes", "1", "pass"]:
120
+ lowered = outcome_raw.lower()
121
+ if lowered in TRUE_VALUES:
118
122
  gt_val = 1.0
119
- elif outcome_raw.lower() in ["false", "no", "0", "fail"]:
123
+ elif lowered in FALSE_VALUES:
120
124
  gt_val = 0.0
121
125
  else:
122
126
  try:
xrtm/train/version.py ADDED
@@ -0,0 +1,28 @@
1
+ # coding=utf-8
2
+ # Copyright 2026 XRTM Team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ r"""
17
+ Version information for xrtm-train.
18
+
19
+ This module provides the single source of truth for the package version.
20
+ """
21
+
22
+ __all__ = ["__version__", "__author__", "__contact__", "__license__", "__copyright__"]
23
+
24
+ __version__ = "0.2.0"
25
+ __author__ = "XRTM Team"
26
+ __contact__ = "moy@xrtm.org"
27
+ __license__ = "Apache-2.0"
28
+ __copyright__ = "Copyright 2026 XRTM Team"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xrtm-train
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: The Learning/Optimization layer for XRTM.
5
5
  Author-email: XRTM Team <moy@xrtm.org>
6
6
  License: Apache-2.0
@@ -11,7 +11,7 @@ Requires-Dist: pydantic>=2.0.0
11
11
  Requires-Dist: numpy>=1.24.0
12
12
  Requires-Dist: scikit-learn>=1.3.0
13
13
  Requires-Dist: xrtm-data
14
- Requires-Dist: xrtm-eval
14
+ Requires-Dist: xrtm-eval>=0.1.2
15
15
  Requires-Dist: xrtm-forecast
16
16
  Provides-Extra: dev
17
17
  Requires-Dist: pytest>=7.0.0; extra == "dev"
@@ -25,17 +25,31 @@ Dynamic: license-file
25
25
 
26
26
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
27
27
  [![Python](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
28
+ [![PyPI](https://img.shields.io/pypi/v/xrtm-train.svg)](https://pypi.org/project/xrtm-train/)
28
29
 
29
30
  **The Optimization Layer for XRTM.**
30
31
 
31
32
  `xrtm-train` is the engine that closes the loop. It simulates history by replaying agents against past "Ground Truth" snapshots stored in `xrtm-data`, scoring them with `xrtm-eval`, and optimizing their reasoning parameters.
32
33
 
34
+ ## Part of the XRTM Ecosystem
35
+
36
+ ```
37
+ Layer 4: xrtm-train → (imports all) ← YOU ARE HERE
38
+ Layer 3: xrtm-forecast → (imports eval, data)
39
+ Layer 2: xrtm-eval → (imports data)
40
+ Layer 1: xrtm-data → (zero dependencies)
41
+ ```
42
+
43
+ `xrtm-train` sits at the top of the stack and can import from ALL other packages. **Installing `xrtm-train` gives you the full XRTM stack.**
44
+
33
45
  ## Installation
34
46
 
35
47
  ```bash
36
- uv pip install xrtm-train
48
+ pip install xrtm-train
37
49
  ```
38
50
 
51
+ > This automatically installs `xrtm-forecast`, `xrtm-eval`, and `xrtm-data`.
52
+
39
53
  ## Core Primitives
40
54
 
41
55
  ### The Simulation Loop
@@ -52,6 +66,26 @@ results = await backtester.run(dataset=historical_questions)
52
66
  print(f"Mean Brier Score: {results.mean_score}")
53
67
  ```
54
68
 
69
+ ### Examples (v0.1.2+)
70
+ With the v0.6.0 architecture split, calibration and replay examples now live here:
71
+
72
+ * **[Calibration Demo](examples/kit/run_calibration_demo.py)**: Adjusting confidence intervals to match reality.
73
+ * **[Trace Replay](examples/kit/run_trace_replay.py)**: Re-running a saved execution for debugging.
74
+ * **[Evaluation Harness](examples/kit/run_evaluation_harness.py)**: End-to-end backtest with metrics.
75
+
76
+ ## Project Structure
77
+
78
+ ```
79
+ src/xrtm/train/
80
+ ├── core/ # Interfaces & Schemas
81
+ │ └── eval/ # Calibration (PlattScaler, BetaScaler)
82
+ ├── kit/ # Training utilities
83
+ │ ├── memory/ # Replay buffers
84
+ │ └── optimization/ # Training strategies
85
+ ├── simulation/ # Backtester, TraceReplayer
86
+ └── providers/ # Remote training backends (future)
87
+ ```
88
+
55
89
  ## Development
56
90
 
57
91
  Prerequisites:
@@ -0,0 +1,19 @@
1
+ xrtm/train/__init__.py,sha256=6R9rOJmQAuucbrYhnWjRwcZ16DVqG2dkxiIY1YVTrl8,778
2
+ xrtm/train/version.py,sha256=8tPsPN88u3iN46elJHRfqdsPQT_2Jss5Arl-EAnRZ_0,965
3
+ xrtm/train/core/__init__.py,sha256=ItMY4rUopNAuCMQ9vROhNTCGxGa5WSynqsqlSCOXlZo,160
4
+ xrtm/train/core/eval/__init__.py,sha256=8PpRyGk71RvZu-vdOq-s6B78b3hauWZ3Vf83cff6FtY,90
5
+ xrtm/train/core/eval/calibration.py,sha256=UxL8M3V_MAcHey1mGryffRcIut18RXtYPzmhHUPSFFY,2941
6
+ xrtm/train/kit/__init__.py,sha256=AOm9Jgj-nKVQIER73uMbev0TwAtVstz67AgSwTBo7iM,849
7
+ xrtm/train/kit/memory/__init__.py,sha256=oSBRWgSUEKliy0P1M5UHuunVbQnIQQYl-5E4AVslMco,68
8
+ xrtm/train/kit/memory/learner.py,sha256=04crGs89UvHwAaTw_Mpv56bKr_urzTWa11Ogq_M3bZk,1170
9
+ xrtm/train/kit/optimization/__init__.py,sha256=t2iS562XLDuDHr2yqjFHnZKENdDvUhn6rkVKFO_AtYI,67
10
+ xrtm/train/kit/optimization/compiler.py,sha256=SYDRnuIllCHQW6N18ur5CQol9uPdTk-x0Fe20NZaa8c,1370
11
+ xrtm/train/providers/__init__.py,sha256=60CIsjAuT9USAY4UnYiKoabAqU59GlBrVLjNP16Pnq0,842
12
+ xrtm/train/simulation/backtester.py,sha256=6ahUB5PuEw4FTkzgcKvNxbABnVuzN4zTDItOcJQF00s,2481
13
+ xrtm/train/simulation/replayer.py,sha256=XobezkdWpRzzdeWqJmJfvFVP1yD1z8bYwO5AmFfC2LY,3007
14
+ xrtm/train/simulation/runner.py,sha256=n82s0lbDZqNHIrh4-NidrW90-mxrFhzKcfONiDcA3IY,6047
15
+ xrtm_train-0.2.0.dist-info/licenses/LICENSE,sha256=BexUTTsX5WlzyJ0Tqajo1h_LFYfCtfFgWdRaGltpm5I,11328
16
+ xrtm_train-0.2.0.dist-info/METADATA,sha256=-jytQM7g-ZQytObmpfuGwYGN2knJLSqLjuOEO-2tpUo,3263
17
+ xrtm_train-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
18
+ xrtm_train-0.2.0.dist-info/top_level.txt,sha256=Jz-i0a9P8GVrIR9KJTT-9wT95E1brww6U5o2QViAt20,5
19
+ xrtm_train-0.2.0.dist-info/RECORD,,
@@ -1,16 +0,0 @@
1
- xrtm/train/__init__.py,sha256=6R9rOJmQAuucbrYhnWjRwcZ16DVqG2dkxiIY1YVTrl8,778
2
- xrtm/train/core/__init__.py,sha256=ItMY4rUopNAuCMQ9vROhNTCGxGa5WSynqsqlSCOXlZo,160
3
- xrtm/train/core/eval/__init__.py,sha256=8PpRyGk71RvZu-vdOq-s6B78b3hauWZ3Vf83cff6FtY,90
4
- xrtm/train/core/eval/calibration.py,sha256=UxL8M3V_MAcHey1mGryffRcIut18RXtYPzmhHUPSFFY,2941
5
- xrtm/train/kit/memory/__init__.py,sha256=oSBRWgSUEKliy0P1M5UHuunVbQnIQQYl-5E4AVslMco,68
6
- xrtm/train/kit/memory/learner.py,sha256=LxhQFyZKeXCSkzl-bQAo9Q0yK1cvV1ZIohoT7o4GiNA,1066
7
- xrtm/train/kit/optimization/__init__.py,sha256=t2iS562XLDuDHr2yqjFHnZKENdDvUhn6rkVKFO_AtYI,67
8
- xrtm/train/kit/optimization/compiler.py,sha256=NHMG4181Y7z9g54BplGZrNRso94L_Y2PqKlErGydVr8,1368
9
- xrtm/train/simulation/backtester.py,sha256=_GJrYBrLjMGxeFXxFix4YdbyLBiBg-8uFo_lnzTAsK8,2311
10
- xrtm/train/simulation/replayer.py,sha256=XobezkdWpRzzdeWqJmJfvFVP1yD1z8bYwO5AmFfC2LY,3007
11
- xrtm/train/simulation/runner.py,sha256=nqnIjqqTKL-7MDUso8Zis1ifQe-HazV_Ntmb8YV4Zyk,5978
12
- xrtm_train-0.1.1.dist-info/licenses/LICENSE,sha256=BexUTTsX5WlzyJ0Tqajo1h_LFYfCtfFgWdRaGltpm5I,11328
13
- xrtm_train-0.1.1.dist-info/METADATA,sha256=1F0tPpNBK15-ywV76N0Y8XrEYEWLpIoYYdq8jUDJilY,1840
14
- xrtm_train-0.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
15
- xrtm_train-0.1.1.dist-info/top_level.txt,sha256=Jz-i0a9P8GVrIR9KJTT-9wT95E1brww6U5o2QViAt20,5
16
- xrtm_train-0.1.1.dist-info/RECORD,,