core.common.registry#
Copyright (c) Meta, Inc. and its affiliates.
This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
# Copyright (c) Meta, Inc. and its affiliates. # Borrowed from facebookresearch/pythia.
Registry is central source of truth. Inspired from Redux’s concept of global store, Registry maintains mappings of various information to unique keys. Special functions in registry can be used as decorators to register different kind of classes.
Import the global registry object using
from fairchem.core.common.registry import registry
Various decorators for registry different kind of classes with unique keys
Register a model:
@registry.register_model
Attributes#
Classes#
Class for registry object which acts as central source of truth. |
Functions#
|
Module Contents#
- core.common.registry.R#
- core.common.registry.NestedDict#
- core.common.registry._get_absolute_mapping(name: str)#
- class core.common.registry.Registry#
Class for registry object which acts as central source of truth.
- mapping: ClassVar[NestedDict]#
- classmethod register_task(name: str)#
Register a new task to registry with key ‘name’ :param name: Key with which the task will be registered.
- Usage::
from fairchem.core.common.registry import registry from fairchem.core.tasks import BaseTask @registry.register_task(“train”) class TrainTask(BaseTask):
…
- classmethod register_dataset(name: str)#
Register a dataset to registry with key ‘name’
- Parameters:
name – Key with which the dataset will be registered.
Usage:
from fairchem.core.common.registry import registry from fairchem.core.datasets import BaseDataset @registry.register_dataset("qm9") class QM9(BaseDataset): ...
- classmethod register_model(name: str)#
Register a model to registry with key ‘name’
- Parameters:
name – Key with which the model will be registered.
Usage:
from fairchem.core.common.registry import registry from fairchem.core.modules.layers import CGCNNConv @registry.register_model("cgcnn") class CGCNN(): ...
- classmethod register_logger(name: str)#
Register a logger to registry with key ‘name’
- Parameters:
name – Key with which the logger will be registered.
Usage:
from fairchem.core.common.registry import registry @registry.register_logger("wandb") class WandBLogger(): ...
- classmethod register_trainer(name: str)#
Register a trainer to registry with key ‘name’
- Parameters:
name – Key with which the trainer will be registered.
Usage:
from fairchem.core.common.registry import registry @registry.register_trainer("active_discovery") class ActiveDiscoveryTrainer(): ...
- classmethod register(name: str, obj) None #
Register an item to registry with key ‘name’
- Parameters:
name – Key with which the item will be registered.
Usage:
from fairchem.core.common.registry import registry registry.register("config", {})
- classmethod __import_error(name: str, mapping_name: str) RuntimeError #
- classmethod get_class(name: str, mapping_name: str)#
- classmethod get_task_class(name: str)#
- classmethod get_dataset_class(name: str)#
- classmethod get_model_class(name: str)#
- classmethod get_logger_class(name: str)#
- classmethod get_trainer_class(name: str)#
- classmethod get(name: str, default=None, no_warning: bool = False)#
Get an item from registry with key ‘name’
- Parameters:
name (string) – Key whose value needs to be retrieved.
default – If passed and key is not in registry, default value will be returned with a warning. Default: None
no_warning (bool) – If passed as True, warning when key doesn’t exist will not be generated. Useful for cgcnn’s internal operations. Default: False
Usage:
from fairchem.core.common.registry import registry config = registry.get("config")
- classmethod unregister(name: str)#
Remove an item from registry with key ‘name’
- Parameters:
name – Key which needs to be removed.
Usage:
from fairchem.core.common.registry import registry config = registry.unregister("config")
- core.common.registry.registry#