Source code for jcmsuite.results.opening

# SPDX-License-Identifier: MIT
# Copyright (c) 2001-{{ COPYRIGHT_END_YEAR }} JCMwave GmbH

"""Existing-result opening helpers for post-run analysis workflows."""

from __future__ import annotations

from pathlib import Path

from ..exceptions import InvalidConfigurationError
from .models import SolveResult


[docs] def open( path: str | Path, *, project_file: str | Path | None = None, ) -> SolveResult: """Open an existing solve result without running `solve(...)`. Parameters ---------- path : str | Path Path to a rendered project file (`.jcmp` or `.jcm`) or a ``*_results`` directory. project_file : str | Path | None, optional project file associated with a result directory. Use this option only if `path` is a result directory. Returns ------- SolveResult Solve result with its available result data loaded. Raises ------ InvalidConfigurationError If `path` does not point to a readable project file or result directory. """ resolved_path: Path = Path(path).expanduser().resolve() if resolved_path.is_dir(): return SolveResult.from_result_dir( resolved_path, project_file=project_file, ) if project_file is not None: raise InvalidConfigurationError( "`project_file` is only supported when opening from a result directory." ) if not resolved_path.is_file(): raise InvalidConfigurationError( f"Open path is missing or invalid: {resolved_path}" ) return SolveResult.from_project_file(resolved_path)