Skip to content

simet.parser.provider

simet.parser.provider

ProviderParser

Factory wrapper that builds concrete providers from a config dict.

Parses a ProviderSchema from a plain mapping (e.g., YAML/JSON) and delegates construction to :meth:ProviderType.get_provider.

parse_provider staticmethod

parse_provider(provider_data)

Parse provider config and return a concrete Provider.

Parameters:

Name Type Description Default
provider_data dict

Mapping that must match ProviderSchema fields, e.g.: {"type": "LocalProviderWithClass", "path": "data/pets"}.

required

Returns:

Name Type Description
Provider Provider

An instance of the requested provider.

Raises:

Type Description
TypeError

If provider_data is missing required fields for ProviderSchema.

ValueError

If the "type" value is unknown/unsupported.

Example

cfg = {"type": "LocalProviderWithoutClass", "path": "data/unlabeled"} p = ProviderParser.parse_provider(cfg) p.class.name 'LocalProviderWithoutClass'

Source code in simet/parser/provider.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@staticmethod
def parse_provider(provider_data: dict) -> Provider:
    """Parse provider config and return a concrete `Provider`.

    Args:
        provider_data (dict):
            Mapping that must match `ProviderSchema` fields, e.g.:
            `{"type": "LocalProviderWithClass", "path": "data/pets"}`.

    Returns:
        Provider: An instance of the requested provider.

    Raises:
        TypeError: If `provider_data` is missing required fields for `ProviderSchema`.
        ValueError: If the `"type"` value is unknown/unsupported.

    Example:
        >>> cfg = {"type": "LocalProviderWithoutClass", "path": "data/unlabeled"}
        >>> p = ProviderParser.parse_provider(cfg)
        >>> p.__class__.__name__
        'LocalProviderWithoutClass'
    """
    provider_schema = ProviderSchema(**provider_data)
    return ProviderType.get_provider(provider_schema)

ProviderType

Bases: StrEnum

Enum of supported providers (string-valued).

get_provider staticmethod

get_provider(provider_schema)

Construct a Provider from a validated ProviderSchema.

Converts the path to a Path and instantiates the provider indicated by provider_schema.type.

Parameters:

Name Type Description Default
provider_schema ProviderSchema

Validated schema with type and path.

required

Returns:

Name Type Description
Provider Provider

Concrete provider instance: - "LocalProviderWithClass"LocalProviderWithClass(path) - "LocalProviderWithoutClass"LocalProviderWithoutClass(path) - "CIFARProvider"CIFARProvider(path)

Raises:

Type Description
ValueError

If provider_schema.type is not a recognized ProviderType.

Notes
  • Local providers expect path to exist on disk; validation occurs when their get_data(...) is called.
  • CIFARProvider will download the dataset into path if missing.
Source code in simet/parser/provider.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
@staticmethod
def get_provider(provider_schema: ProviderSchema) -> Provider:
    """Construct a `Provider` from a validated `ProviderSchema`.

    Converts the `path` to a `Path` and instantiates the provider indicated
    by `provider_schema.type`.

    Args:
        provider_schema (ProviderSchema): Validated schema with `type` and `path`.

    Returns:
        Provider: Concrete provider instance:
            - `"LocalProviderWithClass"` → `LocalProviderWithClass(path)`
            - `"LocalProviderWithoutClass"` → `LocalProviderWithoutClass(path)`
            - `"CIFARProvider"` → `CIFARProvider(path)`

    Raises:
        ValueError: If `provider_schema.type` is not a recognized `ProviderType`.

    Notes:
        - Local providers expect `path` to exist on disk; validation occurs
          when their `get_data(...)` is called.
        - `CIFARProvider` will download the dataset into `path` if missing.
    """
    try:
        provider_type = ProviderType(provider_schema.type)
        path = Path(provider_schema.path)
        match provider_type:
            case ProviderType.LOCALPROVIDERCLASS:
                return LocalProviderWithClass(path)
            case ProviderType.LOCALPROVIDERNOCLASS:
                return LocalProviderWithoutClass(path)
            case ProviderType.CIFAR:
                return CIFARProvider(path)
    except ValueError as e:
        logger.error(f"Unknown provider type: {provider_schema.type}")
        raise ValueError(f"Unknown provider type: {provider_schema.type}") from e