Skip to content

manifest

tit.opt.flex.manifest

Flex-search output manifest (flex_meta.json).

Every flex-search run writes a manifest alongside its outputs. This is the single source of truth for run metadata -- downstream consumers (simulator, GUI) read this instead of parsing folder names.

write_manifest

write_manifest(output_folder: str, config: FlexConfig, result: FlexResult, label: str, pareto_data: dict | None = None) -> str

Write flex_meta.json to output_folder.

Parameters:

Name Type Description Default
output_folder str

Directory to write the manifest into.

required
config FlexConfig

The FlexConfig used for this run.

required
result FlexResult

The FlexResult from the completed run.

required
label str

Human-readable summary label for GUI display.

required
pareto_data dict | None

Optional dict with pareto sweep summary (for sweep runs).

None

Returns:

Type Description
str

Absolute path to the written manifest file.

Source code in tit/opt/flex/manifest.py
def write_manifest(
    output_folder: str,
    config: FlexConfig,
    result: FlexResult,
    label: str,
    pareto_data: dict | None = None,
) -> str:
    """Write flex_meta.json to output_folder.

    Args:
        output_folder: Directory to write the manifest into.
        config: The FlexConfig used for this run.
        result: The FlexResult from the completed run.
        label: Human-readable summary label for GUI display.
        pareto_data: Optional dict with pareto sweep summary (for sweep runs).

    Returns:
        Absolute path to the written manifest file.
    """
    data = {
        "version": MANIFEST_VERSION,
        "created": datetime.now().isoformat(timespec="seconds"),
        "subject_id": config.subject_id,
        "goal": (
            str(config.goal.value)
            if hasattr(config.goal, "value")
            else str(config.goal)
        ),
        "postproc": (
            str(config.postproc.value)
            if hasattr(config.postproc, "value")
            else str(config.postproc)
        ),
        "current_mA": config.current_mA,
        "electrode": {
            "shape": config.electrode.shape,
            "dimensions": list(config.electrode.dimensions),
            "gel_thickness": config.electrode.gel_thickness,
        },
        "roi": _serialize_roi(config.roi),
        "non_roi": _serialize_roi(config.non_roi) if config.non_roi else None,
        "non_roi_method": (
            str(config.non_roi_method.value)
            if config.non_roi_method and hasattr(config.non_roi_method, "value")
            else str(config.non_roi_method) if config.non_roi_method else None
        ),
        "thresholds": config.thresholds,
        "n_multistart": config.n_multistart,
        "result": {
            "success": result.success,
            "best_value": result.best_value,
            "best_run_index": result.best_run_index,
            "all_values": result.function_values,
        },
        "pareto": pareto_data,
        "label": label,
    }

    path = os.path.join(output_folder, MANIFEST_FILENAME)
    with open(path, "w") as f:
        json.dump(data, f, indent=2)
    return path

read_manifest

read_manifest(output_folder: str) -> dict | None

Read flex_meta.json from a folder.

Parameters:

Name Type Description Default
output_folder str

Directory that should contain the manifest.

required

Returns:

Type Description
dict | None

Parsed manifest dict, or None if missing or invalid.

Source code in tit/opt/flex/manifest.py
def read_manifest(output_folder: str) -> dict | None:
    """Read flex_meta.json from a folder.

    Args:
        output_folder: Directory that should contain the manifest.

    Returns:
        Parsed manifest dict, or None if missing or invalid.
    """
    path = os.path.join(output_folder, MANIFEST_FILENAME)
    if not os.path.isfile(path):
        return None
    try:
        with open(path) as f:
            return json.load(f)
    except (json.JSONDecodeError, OSError):
        return None