Skip to content

chacana.context

TOML Global Context loader and data models.

chacana.context

TOML Global Context (Γ) loader.

GlobalContext(manifolds: dict[str, ManifoldDecl] = dict(), tensors: dict[str, TensorDecl] = dict(), active_metric: str | None = None, strategy: dict[str, object] = dict(), sparsity: dict[str, SparsityDecl] = dict(), perturbations: dict[str, PerturbationDecl] = dict()) dataclass

ManifoldDecl(name: str, dimension: int, index_type: str = 'Latin') dataclass

TensorDecl(name: str, manifold: str, rank: int, index_pattern: list[Variance] = list(), symmetries: list[SymmetryDecl] = list()) dataclass

SymmetryDecl(indices: list[int], type: str) dataclass

SparsityDecl(name: str, structural_zeros: list[list[int]] = list()) dataclass

PerturbationDecl(name: str, parameter: str, order: int, manifold: str) dataclass

load_context(source: str | Path) -> GlobalContext

Load a GlobalContext from a TOML file path or string.

Prefer :func:load_context_file or :func:load_context_string for unambiguous loading.

Source code in src/chacana/context.py
def load_context(source: str | Path) -> GlobalContext:
    """Load a GlobalContext from a TOML file path or string.

    Prefer :func:`load_context_file` or :func:`load_context_string` for
    unambiguous loading.
    """
    import warnings

    if isinstance(source, Path):
        return load_context_file(source)
    if "\n" not in source and Path(source).is_file():
        warnings.warn(
            "load_context() auto-detected a file path from a string argument. "
            "Use load_context_file() instead for explicit file loading.",
            DeprecationWarning,
            stacklevel=2,
        )
        return load_context_file(source)
    return load_context_string(source)