Result
module crystallize.experiments.result
Section titled “module crystallize.experiments.result”class Result
Section titled “class Result”Outputs of an experiment run including metrics and provenance.
method Result.__init__
Section titled “method Result.__init__”__init__( metrics: 'ExperimentMetrics', artifacts: 'Optional[Dict[str, Any]]' = None, errors: 'Optional[Dict[str, Exception]]' = None, provenance: 'Optional[Dict[str, Any]]' = None) → Nonemethod Result.get_artifact
Section titled “method Result.get_artifact”get_artifact(name: 'str') → AnyReturn an artifact by name if it was recorded.
method Result.get_hypothesis
Section titled “method Result.get_hypothesis”get_hypothesis(name: 'str') → Optional[HypothesisResult]Return the :class:HypothesisResult with name if present.
method Result.print_tree
Section titled “method Result.print_tree”print_tree(fmt: 'str' = 'treatment > replicate > step') → NonePrint a color-coded tree of execution provenance.
The fmt string controls the hierarchy of the output. Valid tokens are "treatment", "replicate", "step" and "action". When "action" is included as the final element, each step lists the values read, metrics written and context mutations that occurred.
The function uses :mod:rich to render a pretty tree if the package is installed; otherwise a plain-text version is printed.
Parameters ---------- fmt: Format specification controlling how provenance records are grouped. The default groups by treatment, replicate and step.
Raises
------ ValueError If the format specification contains unknown tokens or "action" is not the final element.
method Result.to_dict
Section titled “method Result.to_dict”to_dict() → Dict[str, Any]Convert results to a serializable dictionary.
Returns ------- Dict[str, Any] Dictionary containing metrics, hypotheses, artifacts metadata, errors, and provenance. Safe for JSON serialization.
method Result.to_json
Section titled “method Result.to_json”to_json( path: 'Optional[Union[str, Path]]' = None, indent: 'int' = 2) → Optional[str]Serialize results to JSON.
Parameters ---------- path: If provided, write JSON to this file path. If None, return as string. indent: JSON indentation level. Default is 2.
Returns ------- Optional[str] JSON string if no path provided, otherwise None (writes to file).
Example
------- result.to_json("experiment_results.json")
# or get as string json_str = result.to_json()
method Result.to_parquet
Section titled “method Result.to_parquet”to_parquet(path: 'Union[str, Path]') → NoneSave metrics as a Parquet file for efficient analysis.
Creates a flat table with columns: condition, metric, values, hypothesis_*
Parameters ---------- path: File path for the Parquet output.
Raises ------ ImportError If pandas or pyarrow is not installed.
Example
------- result.to_parquet("experiment_results.parquet")
# Load later with pandas import pandas as pd
df = pd.read_parquet("experiment_results.parquet")