civiqhub_selene.registry

Registry of estimators, read from entry points. Standard library only.

The registry is the extension point of the engine. A package adds a method by declaring a class in its metadata; no class of the engine is modified:

[project.entry-points."civiqhub_selene.estimators"]
"coclustering.single" = "civiqhub_selene.blocks.single:LatentBlockModel"

A key reads family.choice in lower case. Facades translate a plain word ("single", "mixed") into an estimator through the registry:

spec = default_registry()["coclustering.single"]
estimator_class = spec.load()

Reading the registry imports nothing: a class is imported when its entry is loaded.

civiqhub_selene.registry.GROUP = 'civiqhub_selene.estimators'

Entry-point group under which estimators are declared.

class civiqhub_selene.registry.EstimatorSpec(key, target)[source]

Bases: object

One entry of the registry.

key

family.choice, lower case, for example coclustering.single.

Type:

str

target

Where the class lives, written module:Class.

Type:

str

Raises:

InvalidParameterError – If the key or the target is malformed.

Parameters:
  • key (str)

  • target (str)

property family: str

The first half of the key: the family of methods.

property choice: str

The second half of the key: the method chosen within its family.

load()[source]

Import the module and return the estimator class. The class is kept.

Raises:
Return type:

type[Estimator[Any, Any]]

class civiqhub_selene.registry.Registry(specs=())[source]

Bases: Mapping[str, EstimatorSpec]

Immutable mapping from family.choice keys to EstimatorSpec.

Iteration yields the keys in sorted order. A missing key raises UnknownEstimatorError, which lists the choices of the same family. left | right gives a new registry where right wins on a shared key.

Parameters:

specs (Iterable[EstimatorSpec]) – The entries. When two entries share a key, the last one wins.

classmethod from_entry_points(group=GROUP)[source]

Read the installed entry points of group. No class is imported.

Raises:
Parameters:

group (str)

Return type:

Registry

classmethod from_classes(classes)[source]

Build a registry from classes at hand, for tests and uses without install.

Raises:
Parameters:

classes (Mapping[str, type[Estimator[Any, Any]]])

Return type:

Registry

get(key: str, /) → EstimatorSpec | None[source]
get(key: str, /, default: EstimatorSpec | _DefaultT) → EstimatorSpec | _DefaultT

Return the entry under key, or default when there is none.

Parameters:
Return type:

EstimatorSpec | _DefaultT | None

family(name)[source]

Return the entries of one family, indexed by choice.

Parameters:

name (str)

Return type:

dict[str, EstimatorSpec]

civiqhub_selene.registry.default_registry()[source]

Return the registry of the installed entry points, read once per process.

Return type:

Registry