Results¶
The results module provides interfaces for querying and analyzing experiment outcomes. Use these classes to access run records, metrics, and artifacts after execution completes.
metalab.Results ¶
Collection of experiment runs with querying and access capabilities.
Results wraps a Store and provides convenient access to: - Individual Run objects via indexing - Tabular view of results - Filtering by status, tags, or parameters
Example:
result = metalab.run(experiment) # stores in ./runs/{name} by default
# Access individual runs
run = result[0]
print(run.metrics)
artifact = run.artifact("summary")
# Get tabular view
df = result.table(as_dataframe=True)
# Filter results
successful = result.successful
filtered = result.filter(gene="KLF1")
# Export
result.to_csv("./output/results.csv")
# Display summary
result.display()
Initialize the Results collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
Store
|
The store containing artifacts. |
required |
records
|
list[RunRecord]
|
List of RunRecords from the experiment. |
required |
__getitem__ ¶
compute_derived ¶
compute_derived(metrics: 'list[DerivedMetricFn]', *, overwrite: bool = False, progress: bool = False) -> None
Compute derived metrics for all runs and persist to store.
This method computes derived metrics from run artifacts/params/metrics and stores them in /derived/{run_id}.json for each run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
'list[DerivedMetricFn]'
|
List of derived metric functions. Each function receives a Run object and returns dict[str, Metric]. |
required |
overwrite
|
bool
|
If True, recompute even if derived metrics exist. |
False
|
progress
|
bool
|
Show progress bar (requires rich). |
False
|
Example
def final_loss(run: Run) -> dict[str, Metric]: loss_history = run.artifact("loss_history") return {"final_loss": float(loss_history[-1])}
results.compute_derived([final_loss])
display ¶
Display results summary to console.
Uses rich if available, falls back to plain text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_by
|
list[str] | None
|
Optional metric keys to group results by. |
None
|
show_summary
|
bool
|
Show overall summary statistics. |
True
|
Example
result.display() result.display(group_by=["gene", "perturbation_value"])
filter ¶
Filter results by criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str | Status | None
|
Filter by status ("success", "failed", "cancelled"). |
None
|
tags
|
list[str] | None
|
Filter by tags (all must be present). |
None
|
**params
|
Any
|
Filter by metric values. |
{}
|
Returns:
| Type | Description |
|---|---|
Results
|
A new Results with filtered runs. |
from_store
classmethod
¶
Load results from a store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
Store
|
The store to load from. |
required |
experiment_id
|
str | None
|
Optional filter by experiment ID. |
None
|
Returns:
| Type | Description |
|---|---|
Results
|
Results containing the loaded runs. |
Example
from metalab.store import FileStore
store = FileStore("./runs/my_experiment") results = Results.from_store(store)
load ¶
Load an artifact from a run by run_id.
Prefer using run.artifact(name) for cleaner access:
result[0].artifact("summary")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
The run identifier. |
required |
artifact_name
|
str
|
The name of the artifact. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The deserialized artifact. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the artifact doesn't exist. |
summary ¶
Get a summary of the results.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with counts and basic statistics. |
table ¶
Get results as a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
as_dataframe
|
bool
|
If True, return a pandas DataFrame (requires pandas). |
False
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | Any
|
List of dicts by default, or DataFrame if as_dataframe=True. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If as_dataframe=True but pandas is not installed. |
to_csv ¶
Export results to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Output path. If a directory, generates a timestamped filename. |
required |
include_fingerprints
|
bool
|
Include fingerprint columns (default: False). |
False
|
timestamp
|
bool
|
Add timestamp to filename if path is a file (default: False). |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written CSV file. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If pandas is not installed. |
to_dataframe ¶
to_dataframe(*, include_params: bool = True, include_metrics: bool = True, include_record: bool = True, include_derived: bool = False, derived_metrics: 'list[DerivedMetricFn] | None' = None, artifact_reducers: dict[str, ArtifactReducer | ContextAwareReducer] | None = None, progress: bool = False) -> Any
Export results to a pandas DataFrame with optional artifact reduction.
This method provides flexible DataFrame export with: - Resolved parameters (prefixed with 'param_') - Captured metrics - Record metadata (run_id, status, duration, etc.) - Persisted derived metrics (from /derived/{run_id}.json) - On-the-fly derived metrics via reducer functions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_params
|
bool
|
Include params_resolved columns (prefixed with 'param_'). |
True
|
include_metrics
|
bool
|
Include metrics columns. |
True
|
include_record
|
bool
|
Include record fields (run_id, status, duration, etc.). |
True
|
include_derived
|
bool
|
Include persisted derived metrics from /derived/. |
False
|
derived_metrics
|
'list[DerivedMetricFn] | None'
|
List of derived metric functions for on-the-fly computation (not persisted). Each function receives a Run object and returns dict[str, Metric]. |
None
|
artifact_reducers
|
dict[str, ArtifactReducer | ContextAwareReducer] | None
|
(Deprecated, use derived_metrics) Dict mapping artifact name to reducer function. |
None
|
progress
|
bool
|
Show progress bar when loading artifacts (requires rich). |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
pandas DataFrame with the requested columns. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If pandas is not installed. |
Example (include persisted derived metrics): df = results.to_dataframe(include_derived=True)
Example (on-the-fly derived metric): def final_loss(run): return {"final_loss": run.artifact("loss_history")[-1]}
df = results.to_dataframe(derived_metrics=[final_loss])
Example (artifact reducer - legacy): def reduce_history(arr): return {"final": arr[:, -1].mean(), "best": arr.min()}
df = results.to_dataframe(
artifact_reducers={"history": reduce_history}
)
metalab.Run ¶
A single experiment run with access to its metrics and artifacts.
The Run object wraps a RunRecord and provides convenient access to:
- Run metadata (run_id, status, timestamps)
- Metrics captured during the run
- Artifacts stored for the run
- Experiment-level metadata via the experiment property
Example:
result = metalab.run(experiment)
run = result[0] # Get first run
# Access metrics
print(run.metrics)
print(run.status)
# Access experiment metadata
print(run.experiment.metadata)
# Load artifacts
summary = run.artifact("summary")
for desc in run.artifacts():
print(f" {desc.name}: {desc.kind}")
Initialize the Run wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
RunRecord
|
The underlying RunRecord. |
required |
store
|
Store
|
The store containing artifacts. |
required |
derived
property
¶
Derived metrics computed post-hoc.
These are stored separately from the run record in /derived/{run_id}.json. Returns an empty dict if no derived metrics exist.
experiment
property
¶
Experiment-level information including metadata.
Lazily loads from the experiment manifest on first access. If the manifest is not found, returns minimal info extracted from the experiment_id.
Returns:
| Type | Description |
|---|---|
ExperimentInfo
|
ExperimentInfo with experiment metadata. |
Example:
artifact ¶
Load an artifact by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The artifact name. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The deserialized artifact. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the artifact doesn't exist. |
artifacts ¶
List available artifacts for this run.
Returns:
| Type | Description |
|---|---|
list[ArtifactDescriptor]
|
List of artifact descriptors. |
data ¶
Load structured result data by name.
Structured data is stored via capture.data() and is optimized for fast access by derived metric functions. With PostgresStore, data is stored inline in the database (as JSON). With FileStore, data is stored in JSON files at results/{run_id}/{name}.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The data name. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The data object. Arrays are returned as numpy arrays if |
Any
|
shape/dtype metadata is available. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the data doesn't exist. |
Example:
list_data ¶
List available structured data names for this run.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of data names. |
metalab.ExperimentInfo
dataclass
¶
ExperimentInfo(experiment_id: str, name: str = '', version: str = '', description: str = '', metadata: dict[str, Any] = dict(), tags: list[str] = list())
Experiment-level information accessible from a Run.
This provides access to experiment metadata without needing to load the full experiment manifest repeatedly.
Attributes:
| Name | Type | Description |
|---|---|---|
experiment_id |
str
|
The experiment identifier (name:version). |
name |
str
|
The experiment name. |
version |
str
|
The experiment version. |
description |
str
|
Human-readable description. |
metadata |
dict[str, Any]
|
User-defined metadata dict. |
tags |
list[str]
|
List of tags for categorization. |
from_experiment_id
classmethod
¶
Create minimal ExperimentInfo from just an experiment_id.
Used as a fallback when the manifest is not available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
The experiment identifier (name:version). |
required |
Returns:
| Type | Description |
|---|---|
ExperimentInfo
|
ExperimentInfo with minimal data extracted from the ID. |
from_manifest
classmethod
¶
Create ExperimentInfo from an experiment manifest dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
dict[str, Any]
|
The experiment manifest dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ExperimentInfo
|
ExperimentInfo populated from the manifest. |