Skip to content

safestructures.load_file

Load data using Safestructures.

The file must be a valid Safestructures file, i.e Safetensors file with additional Safestructures metadata.

Parameters:

Name Type Description Default
load_path Union[str, PosixPath]

Path to a valid Safestructures file.

required
framework str

The framework to load tensors into. Defaults to "np" for Numpy.

'np'
device str

Device to allocate tensors to. Defaults to "cpu" to allocate on CPU.

'cpu'
plugins Optional[Union[PROCESSOR_TYPES, list[PROCESSOR_TYPES]]]

Additional plugins to serialize data for data types not covered by safestructures. Defaults to None for no plugins.

None

Returns:

Type Description

The loaded data.

Source code in src/safestructures/wrapper.py
def load_file(
    load_path: Union[str, PosixPath],
    framework: str = "np",
    device: str = "cpu",
    plugins: Optional[Union[PROCESSOR_TYPES, list[PROCESSOR_TYPES]]] = None,
):
    """Load data using Safestructures.

    The file must be a valid Safestructures file,
    i.e Safetensors file with additional Safestructures metadata.

    Args:
        load_path (Union[str, PosixPath]): Path to a valid Safestructures file.
        framework (str, optional): The framework to load tensors into.
            Defaults to "np" for Numpy.
        device (str, optional): Device to allocate tensors to.
            Defaults to "cpu" to allocate on CPU.
        plugins (Optional[Union[PROCESSOR_TYPES, list[PROCESSOR_TYPES]]], optional):
            Additional plugins to serialize data for data types not covered
            by safestructures. Defaults to None for no plugins.

    Returns:
        The loaded data.
    """
    if plugins and not isinstance(plugins, list):
        plugins = [plugins]

    return Serializer(plugins=plugins).load(
        load_path, framework=framework, device=device
    )