Skip to content

nexuml.core.factory

nexuml.core.factory

Portable importable-factory helpers for typed Python configuration.

normalize_json_value

normalize_json_value(value: Any, path: str) -> JsonValue

Normalize one constructor value to portable JSON data.

Returns:

Type Description
JsonValue

Normalized JSON value.

Raises:

Type Description
ValueError

If the value cannot be represented portably.

resolve_factory

resolve_factory(
    target: str, *, label: str = "factory"
) -> Callable[..., object]

Resolve a portable module:name target.

Returns:

Type Description
Callable[..., object]

Imported callable.

Raises:

Type Description
TypeError

If the imported target is not callable.

ValueError

If the target is malformed or cannot be imported.

factory_target

factory_target(
    factory: object, *, label: str = "factory"
) -> str

Return and verify the portable target for an importable callable.

Returns:

Type Description
str

Portable module:name target.

Raises:

Type Description
TypeError

If factory is not callable.

ValueError

If factory cannot be re-imported safely.

callback

callback(
    factory: Callable[P, Callback],
    *args: args,
    **kwargs: kwargs,
) -> CallbackSpec

Configure an importable Lightning callback factory.

Returns:

Type Description
CallbackSpec

Portable callback specification.

optimizer

optimizer(
    factory: Callable[Concatenate[Any, P], Optimizer],
    *args: args,
    **kwargs: kwargs,
) -> OptimizerSpec

Configure an optimizer factory; model parameters are supplied at runtime.

Returns:

Type Description
OptimizerSpec

Portable optimizer specification.

scheduler

scheduler(
    factory: Callable[
        Concatenate[Optimizer, P], LRScheduler
    ],
    *args: args,
    **kwargs: kwargs,
) -> SchedulerSpec

Configure a scheduler factory; its optimizer is supplied at runtime.

Returns:

Type Description
SchedulerSpec

Portable scheduler specification.

strategy

strategy(
    factory: Callable[P, Strategy],
    *args: args,
    **kwargs: kwargs,
) -> StrategySpec

Configure an importable Lightning strategy factory.

Returns:

Type Description
StrategySpec

Portable strategy specification.

writer

writer(
    factory: Callable[P, ExportBackend],
    *args: args,
    **kwargs: kwargs,
) -> WriterSpec

Configure an importable dataset export backend factory.

Returns:

Type Description
WriterSpec

Portable writer specification.

Raises:

Type Description
TypeError

If factory is not an export backend class.

factory_values

factory_values(
    factory: object,
    args: tuple[object, ...],
    kwargs: Mapping[str, object],
    *,
    label: str,
) -> dict[str, object]

Build validated Pydantic field values for a factory helper.

Returns:

Type Description
dict[str, object]

Factory target and constructor arguments.