Result artifacts¶
trade_study.artifacts
¶
Validated result-bundle schemas and primitive JSON input preservation.
ResultsBundle
¶
Bases: NamedTuple
Scored data plus separately preserved scientific interpretation.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
ResultsTable
|
Reconstructed parallel score/config/annotation table. |
observables |
tuple[Observable, ...]
|
Ordered directions and weights; empty for legacy exports. |
provenance |
Mapping[str, object]
|
Caller identities and recorded runtime versions. This does not reconstruct executable simulators/scorers or certify replay. |
schema_version |
int
|
One for primitive JSON bundles, zero for legacy export. |
generation |
str | None
|
Captured published generation identifier, or None for a directly loaded bundle/legacy export. |
load_result_bundle(path)
¶
Load a published generation, direct version-1 bundle or legacy export.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Published root or direct directory with committed result files. |
required |
Returns:
| Type | Description |
|---|---|
ResultsBundle
|
Scored table and available scientific metadata. Legacy schema version |
ResultsBundle
|
zero has no preserved observable definitions or replayability claim. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If schema, array digests, parallel rows or metadata disagree. |
Source code in src/trade_study/artifacts.py
save_result_bundle(results, path, *, observables, provenance=None)
¶
Write a version-1 primitive JSON bundle into a new destination only.
Validate all values before creating the destination. Reserve a new directory, write array snapshots, and atomically publish metadata last. An interrupted write has no committed metadata and cannot read as a complete bundle. This initial schema writer does not overwrite or update existing directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ResultsTable
|
Parallel scored data; arrays may contain non-finite score values. |
required |
path
|
str | Path
|
New destination directory, on a filesystem supporting atomic replace. |
required |
observables
|
Sequence[Observable]
|
Ordered scientific directions/weights matching score columns. |
required |
provenance
|
dict[str, object] | None
|
Primitive JSON identities for model/scorer/transforms, external inputs, replication and random streams. Runtime versions are added. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If data or interpretation is inconsistent or values unsupported. |
FileExistsError
|
If the destination already exists, including incomplete data. |
Source code in src/trade_study/artifacts.py
publish_result_bundle(results, path, *, observables, provenance=None)
¶
Publish an immutable generation with one atomic current-pointer replacement.
Existing generations and direct/legacy files stay intact. A failed update leaves the previous pointer unchanged unless the new complete generation has already been committed. Readers capture one pointer and check all files in that selected generation. Concurrent writers use distinct destinations; the last successful pointer replacement determines the current generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ResultsTable
|
Scored data to snapshot into a new version-1 generation. |
required |
path
|
str | Path
|
Publication root on a filesystem supporting atomic file replacement. |
required |
observables
|
Sequence[Observable]
|
Ordered directions/weights matching the score columns. |
required |
provenance
|
dict[str, object] | None
|
Primitive JSON caller identities, separate from runtime versions. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Retained generation directory, usable for an explicit snapshot read. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If current publication metadata or new inputs are inconsistent. |