tempor.core.plugins package¶
Submodules¶
- tempor.core.plugins.plugin_typing module
- tempor.core.plugins.plugin_typing.PluginType
- tempor.core.plugins.plugin_typing.PluginTypeArgAll
- tempor.core.plugins.plugin_typing.PluginTypeArg
- tempor.core.plugins.plugin_typing.PluginName
- tempor.core.plugins.plugin_typing.PluginFullName
- tempor.core.plugins.plugin_typing.PluginCategory
- tempor.core.plugins.plugin_typing.DEFAULT_PLUGIN_TYPE
- tempor.core.plugins.plugin_typing.ALL_PLUGIN_TYPES_INDICATOR
Module contents¶
This module contains the core plugin functionality of TemporAI.
-
tempor.core.plugins.parse_plugin_type(plugin_type: None | Literal[all] | str, must_be_one_of: list[str] | None =
None) None | Literal[all] | str[source]¶ Get the default plugin type if
plugin_typeisNone. Ifplugin_typeis"all", raise error, as that is a reserved value.
- tempor.core.plugins.create_fqn(suffix: str, plugin_type: None | Literal[all] | str) str[source]¶
Create a fully-qualified name for a plugin or category, like
[plugin_type].category.nameor[plugin_type].categoryrespectively.
- tempor.core.plugins.filter_list_by_plugin_type(lst: list[str], plugin_type: None | Literal[all] | str) list[str][source]¶
Filter a list of plugin FQNs by plugin type.
- tempor.core.plugins.filter_dict_by_plugin_type(d: dict[str, Any], plugin_type: None | Literal[all] | str) dict[str, Any][source]¶
Filter a dictionary with plugin FQN keys by plugin type.
- tempor.core.plugins.remove_plugin_type_from_fqn(fqn: str) str[source]¶
Remove the plugin type part of a plugin FQN or category FQN.
- tempor.core.plugins.get_plugin_type_from_fqn(fqn: str) None | Literal[all] | str[source]¶
Get the plugin type part of a plugin FQN or category FQN.
- class tempor.core.plugins.Plugin[source]¶
Bases:
objectThe base class that all plugins must inherit from.
-
name : ClassVar[str] =
'NOT_SET'¶ Plugin name, such as
'my_nn_classifier'. Must be set by the plugin class using@register_plugin.
-
category : ClassVar[str] =
'NOT_SET'¶ Plugin category, such as
'prediction.one_off.classification'. Must be set by the plugin class using@register_plugin.
-
name : ClassVar[str] =
-
tempor.core.plugins.PLUGIN_CATEGORY_REGISTRY : dict[str, type[Plugin]] =
{'[dataformat].event_samples': <class 'tempor.data.samples.EventSamplesBase'>, '[dataformat].static_samples': <class 'tempor.data.samples.StaticSamplesBase'>, '[dataformat].time_series_samples': <class 'tempor.data.samples.TimeSeriesSamplesBase'>, '[datasource].prediction.one_off': <class 'tempor.datasources.datasource.OneOffPredictionDataSource'>, '[datasource].prediction.temporal': <class 'tempor.datasources.datasource.TemporalPredictionDataSource'>, '[datasource].time_to_event': <class 'tempor.datasources.datasource.TimeToEventAnalysisDataSource'>, '[datasource].treatments.one_off': <class 'tempor.datasources.datasource.OneOffTreatmentEffectsDataSource'>, '[datasource].treatments.temporal': <class 'tempor.datasources.datasource.TemporalTreatmentEffectsDataSource'>, '[method].prediction.one_off.classification': <class 'tempor.methods.prediction.one_off.classification.BaseOneOffClassifier'>, '[method].prediction.one_off.regression': <class 'tempor.methods.prediction.one_off.regression.BaseOneOffRegressor'>, '[method].prediction.temporal.classification': <class 'tempor.methods.prediction.temporal.classification.BaseTemporalClassifier'>, '[method].prediction.temporal.regression': <class 'tempor.methods.prediction.temporal.regression.BaseTemporalRegressor'>, '[method].preprocessing.encoding.static': <class 'tempor.methods.preprocessing.encoding._base.BaseEncoder'>, '[method].preprocessing.encoding.temporal': <class 'tempor.methods.preprocessing.encoding._base.BaseEncoder'>, '[method].preprocessing.imputation.static': <class 'tempor.methods.preprocessing.imputation._base.BaseImputer'>, '[method].preprocessing.imputation.temporal': <class 'tempor.methods.preprocessing.imputation._base.BaseImputer'>, '[method].preprocessing.nop': <class 'tempor.methods.core._base_transformer.BaseTransformer'>, '[method].preprocessing.scaling.static': <class 'tempor.methods.preprocessing.scaling._base.BaseScaler'>, '[method].preprocessing.scaling.temporal': <class 'tempor.methods.preprocessing.scaling._base.BaseScaler'>, '[method].time_to_event': <class 'tempor.methods.time_to_event.BaseTimeToEventAnalysis'>, '[method].treatments.one_off.regression': <class 'tempor.methods.treatments.one_off._base.BaseOneOffTreatmentEffects'>, '[method].treatments.temporal.classification': <class 'tempor.methods.treatments.temporal._base.BaseTemporalTreatmentEffects'>, '[method].treatments.temporal.regression': <class 'tempor.methods.treatments.temporal._base.BaseTemporalTreatmentEffects'>, '[metric].prediction.one_off.classification': <class 'tempor.metrics.metric.OneOffClassificationMetric'>, '[metric].prediction.one_off.regression': <class 'tempor.metrics.metric.OneOffRegressionMetric'>, '[metric].time_to_event': <class 'tempor.metrics.metric.TimeToEventMetric'>}¶ Important dictionary for plugin functionality. Records all plugin categories (
'[plugin_type].category.<0 or more subcategories if applicable>') and their corresponding plugin classes.
-
tempor.core.plugins.PLUGIN_REGISTRY : dict[str, type[Plugin]] =
{'[dataformat].event_samples.event_samples_dask': <class 'tempor.data.samples_experimental.EventSamplesDask'>, '[dataformat].event_samples.event_samples_df': <class 'tempor.data.samples.EventSamples'>, '[dataformat].static_samples.static_samples_dask': <class 'tempor.data.samples_experimental.StaticSamplesDask'>, '[dataformat].static_samples.static_samples_df': <class 'tempor.data.samples.StaticSamples'>, '[dataformat].time_series_samples.time_series_samples_dask': <class 'tempor.data.samples_experimental.TimeSeriesSamplesDask'>, '[dataformat].time_series_samples.time_series_samples_df': <class 'tempor.data.samples.TimeSeriesSamples'>, '[datasource].prediction.one_off.google_stocks': <class 'tempor.datasources.prediction.one_off.plugin_google_stocks.GoogleStocksDataSource'>, '[datasource].prediction.one_off.sine': <class 'tempor.datasources.prediction.one_off.plugin_sine.SineDataSource'>, '[datasource].prediction.temporal.dummy_prediction': <class 'tempor.datasources.prediction.temporal.plugin_dummy_prediction.DummyTemporalPredictionDataSource'>, '[datasource].prediction.temporal.uci_diabetes': <class 'tempor.datasources.prediction.temporal.plugin_uci_diabetes.UCIDiabetesDataSource'>, '[datasource].time_to_event.pbc': <class 'tempor.datasources.time_to_event.plugin_pbc.PBCDataSource'>, '[datasource].treatments.one_off.pkpd': <class 'tempor.datasources.treatments.one_off.plugin_pkpd.PKPDDataSource'>, '[datasource].treatments.temporal.dummy_treatments': <class 'tempor.datasources.treatments.temporal.plugin_dummy_treatments.DummyTemporalTreatmentEffectsDataSource'>, '[method].prediction.one_off.classification.cde_classifier': <class 'tempor.methods.prediction.one_off.classification.plugin_cde_classifier.CDEClassifier'>, '[method].prediction.one_off.classification.laplace_ode_classifier': <class 'tempor.methods.prediction.one_off.classification.plugin_laplace_classifier.LaplaceODEClassifier'>, '[method].prediction.one_off.classification.nn_classifier': <class 'tempor.methods.prediction.one_off.classification.plugin_nn_classifier.NeuralNetClassifier'>, '[method].prediction.one_off.classification.ode_classifier': <class 'tempor.methods.prediction.one_off.classification.plugin_ode_classifier.ODEClassifier'>, '[method].prediction.one_off.regression.cde_regressor': <class 'tempor.methods.prediction.one_off.regression.plugin_cde_regressor.CDERegressor'>, '[method].prediction.one_off.regression.laplace_ode_regressor': <class 'tempor.methods.prediction.one_off.regression.plugin_laplace_regressor.LaplaceODERegressor'>, '[method].prediction.one_off.regression.nn_regressor': <class 'tempor.methods.prediction.one_off.regression.plugin_nn_regressor.NeuralNetRegressor'>, '[method].prediction.one_off.regression.ode_regressor': <class 'tempor.methods.prediction.one_off.regression.plugin_ode_regressor.ODERegressor'>, '[method].prediction.temporal.classification.seq2seq_classifier': <class 'tempor.methods.prediction.temporal.classification.plugin_seq2seq_classifier.Seq2seqClassifier'>, '[method].prediction.temporal.regression.seq2seq_regressor': <class 'tempor.methods.prediction.temporal.regression.plugin_seq2seq_regressor.Seq2seqRegressor'>, '[method].preprocessing.encoding.static.static_onehot_encoder': <class 'tempor.methods.preprocessing.encoding.static.plugin_static_onehot_encoder.StaticOneHotEncoder'>, '[method].preprocessing.encoding.temporal.ts_onehot_encoder': <class 'tempor.methods.preprocessing.encoding.temporal.plugin_ts_onehot_encoder.TimeSeriesOneHotEncoder'>, '[method].preprocessing.imputation.static.static_tabular_imputer': <class 'tempor.methods.preprocessing.imputation.static.plugin_static_tabular_imputer.StaticTabularImputer'>, '[method].preprocessing.imputation.temporal.bfill': <class 'tempor.methods.preprocessing.imputation.temporal.plugin_bfill.BFillImputer'>, '[method].preprocessing.imputation.temporal.ffill': <class 'tempor.methods.preprocessing.imputation.temporal.plugin_ffill.FFillImputer'>, '[method].preprocessing.imputation.temporal.ts_tabular_imputer': <class 'tempor.methods.preprocessing.imputation.temporal.plugin_ts_tabular_imputer.TemporalTabularImputer'>, '[method].preprocessing.nop.nop_transformer': <class 'tempor.methods.preprocessing.nop.NopTransformer'>, '[method].preprocessing.scaling.static.static_minmax_scaler': <class 'tempor.methods.preprocessing.scaling.static.plugin_static_minmax_scaler.StaticMinMaxScaler'>, '[method].preprocessing.scaling.static.static_standard_scaler': <class 'tempor.methods.preprocessing.scaling.static.plugin_static_standard_scaler.StaticStandardScaler'>, '[method].preprocessing.scaling.temporal.ts_minmax_scaler': <class 'tempor.methods.preprocessing.scaling.temporal.plugin_ts_minmax_scaler.TimeSeriesMinMaxScaler'>, '[method].preprocessing.scaling.temporal.ts_standard_scaler': <class 'tempor.methods.preprocessing.scaling.temporal.plugin_ts_standard_scaler.TimeSeriesStandardScaler'>, '[method].time_to_event.dynamic_deephit': <class 'tempor.methods.time_to_event.plugin_ddh.DynamicDeepHitTimeToEventAnalysis'>, '[method].time_to_event.ts_coxph': <class 'tempor.methods.time_to_event.plugin_ts_coxph.CoxPHTimeToEventAnalysis'>, '[method].time_to_event.ts_xgb': <class 'tempor.methods.time_to_event.plugin_ts_xgb.XGBTimeToEventAnalysis'>, '[method].treatments.one_off.regression.synctwin_regressor': <class 'tempor.methods.treatments.one_off.regression.plugin_synctwin_regressor.SyncTwinTreatmentsRegressor'>, '[method].treatments.temporal.classification.crn_classifier': <class 'tempor.methods.treatments.temporal.classification.plugin_crn_classifier.CRNTreatmentsClassifier'>, '[method].treatments.temporal.regression.crn_regressor': <class 'tempor.methods.treatments.temporal.regression.plugin_crn_regressor.CRNTreatmentsRegressor'>, '[metric].prediction.one_off.classification.accuracy': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.AccuracyOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.aucprc': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.AucPrcOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.aucroc': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.AucRocOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.f1_score_macro': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.F1ScoreMacroOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.f1_score_micro': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.F1ScoreMicroOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.f1_score_weighted': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.F1ScoreWeightedOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.kappa': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.KappaOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.kappa_quadratic': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.KappaQuadraticOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.mcc': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.MccOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.precision_macro': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.PrecisionMacroOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.precision_micro': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.PrecisionMicroOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.precision_weighted': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.PrecisionWeightedOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.recall_macro': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.RecallMacroOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.recall_micro': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.RecallMicroOneOffClassificationMetric'>, '[metric].prediction.one_off.classification.recall_weighted': <class 'tempor.metrics.prediction.one_off.plugin_builtin_classification.RecallWeightedOneOffClassificationMetric'>, '[metric].prediction.one_off.regression.mae': <class 'tempor.metrics.prediction.one_off.plugin_builtin_regression.MaeOneOffRegressionMetric'>, '[metric].prediction.one_off.regression.mse': <class 'tempor.metrics.prediction.one_off.plugin_builtin_regression.MseOneOffRegressionMetric'>, '[metric].prediction.one_off.regression.r2': <class 'tempor.metrics.prediction.one_off.plugin_builtin_regression.R2OneOffRegressionMetric'>, '[metric].time_to_event.brier_score': <class 'tempor.metrics.time_to_event.plugin_builtin_time_to_event.BrierScoreTimeToEventMetric'>, '[metric].time_to_event.c_index': <class 'tempor.metrics.time_to_event.plugin_builtin_time_to_event.CIndexTimeToEventMetric'>}¶ Important dictionary for plugin functionality. Records all plugins by their fully-qualified name
'[plugin_type].category.<0 or more subcategories if applicable>.plugin_name'.
-
tempor.core.plugins.register_plugin_category(category: str, expected_class: type, plugin_type: None | Literal[all] | str =
None) None[source]¶ A decorator to register a plugin category (with optional subcategories). If
plugin_typeis provided, this will also be assigned (or created, if such plugin type doesn’t yet exist), otherwise the default plugin type will be used.- Parameters:¶
- category : plugin_typing.PluginCategory¶
Plugin category, dot-separated, with optional subcategories, such as
'prediction.one_off.classification'.- expected_class : Type¶
The expected plugin class for this category. The plugin class must be a subclass of this class. Note that this class must itself be a subclass of
Plugin.- plugin_type : plugin_typing.PluginTypeArg, optional¶
Plugin type to register the category under. Different plugin types should be used to indicate different domains of your code (e.g. methods vs metrics vs datasets). Defaults to
None.
- Raises:¶
TypeError – If the
expected_classis not correctly defined.
-
tempor.core.plugins.register_plugin(name: str, category: str, plugin_type: None | Literal[all] | str =
None) Callable[[Callable[[P], T]], Callable[[P], T]][source]¶ A decorator to register a plugin class. If
plugin_typeis provided, this will also be assigned, otherwise the default plugin type will be used. Thecategorymust have already been registered with@register_plugin_categorybefore this can be used to register a plugin.- Parameters:¶
- name : str¶
Plugin name, such as
'my_nn_classifier'.- category : plugin_typing.PluginCategory¶
Plugin category, dot-separated, with optional subcategories, such as
'prediction.one_off.classification'.- plugin_type : plugin_typing.PluginTypeArg, optional¶
Plugin type of the category. If left as
None, default plugin type is assumed.plugin_typemust correctly correspond to thecategorybeing specified. Defaults toNone.
- Returns:¶
Decorated class.
- Return type:¶
Callable[[Callable[P, T]], Callable[P, T]]
- tempor.core.plugins.ListCategoriesReturn¶
Type alias for the return type of
list_categories.alias of
Union[Dict[str,Type[Plugin]],Dict[str,Dict[str,Type[Plugin]]]]
- class tempor.core.plugins.PluginLoader[source]¶
Bases:
objectA class to load plugins. Provides functionality to list and get plugins.
-
list(plugin_type: None | Literal[all] | str =
None) dict[source]¶ List all plugins of
plugin_typeas a nested dictionary, where the keys are the plugin categories and optional subcategories. The values of the dictionary are the plugin names.If
plugin_typeis"all", will list for all plugin types, outputting inside a nested dictionary with plugin type keys.
-
list_full_names(plugin_type: None | Literal[all] | str =
None) list[str] | dict[str, list[str]][source]¶ List all plugins of
plugin_typeas a list of plugin full names (including categories).If
plugin_typeis"all", will list for all plugin types, outputting inside a nested dictionary with plugin type keys.- Parameters:¶
- Returns:¶
A list as described above (
List[PluginFullName]) ifplugin_typeis not"all". Otherwise a nested dictionary with plugin type keys and such lists as values (Dict[str, List[PluginFullName]]]).- Return type:¶
Union[List[plugin_typing.PluginFullName], Dict[str, List[plugin_typing.PluginFullName]]]
-
list_classes(plugin_type: None | Literal[all] | str =
None) dict[source]¶ List all plugin classes of
plugin_typeas a nested dictionary, where the keys are the plugin categories and optional subcategories. The values of the dictionary are the plugin classes.If
plugin_typeis"all", will list for all plugin types, outputting inside a nested dictionary with plugin type keys.
-
list_categories(plugin_type: None | Literal[all] | str =
None) dict[str, type[Plugin]] | dict[str, dict[str, type[Plugin]]][source]¶ List all plugin categories of
plugin_typeas a dictionary, where the keys are the plugin category names (including optional subcategories) and the values are the expected plugin classes for that category.If
plugin_typeis"all", will list for all plugin types, outputting inside a nested dictionary with plugin type keys.
- get(name: str, *args: Any, **kwargs: Any) type[source]¶
- get(name: str, plugin_type: None | Literal[all] | str, *args: Any, **kwargs: Any) type
-
get(name: str, *args: Any, plugin_type: None | Literal[all] | str =
None, **kwargs: Any) type Get a plugin by its full name (including category, i.e. of form
'my_category.my_subcategory.my_plugin'). Use*argsand**kwargsto pass arguments to the plugin initializer. The returned object is an instance of the plugin class. If the plugin is not of the default plugin type, must provideplugin_typealso.The method can be called with
plugin_typeand plugin initializer arguments, as follows:As first positional argument after the plugin name:
plugin_instance = get( "my_category.my_subcategory.my_plugin", # Plugin full name. "method", # Plugin type provided as a positional argument (first). 0.4, # First positional argument to plugin initializer. 123, # Second positional argument to plugin initializer... kwarg=2, # Keyword argument(s) to plugin initializer from here on. )As keyword argument:
plugin_instance = get( "my_category.my_subcategory.my_plugin", # Plugin full name. 0.4, # First positional argument to plugin initializer. 123, # Second positional argument to plugin initializer... plugin_type="method", # Plugin type provided as a keyword argument. kwarg=2, # Keyword argument(s) to plugin initializer from here on. )- Parameters:¶
- name : plugin_typing.PluginFullName¶
Plugin full name including all (sub)categories, of form
'my_category.my_subcategory.my_plugin'- *args : Any
Arguments to pass to the plugin initializer.
- plugin_type : plugin_typing.PluginTypeArg, optional¶
Plugin type. If left as
None, default plugin type is assumed.plugin_typemust correctly correspond to the category implied by plugin full name. Defaults toNone.- **kwargs : Any
Keyword arguments to pass to the plugin initializer.
- Returns:¶
The plugin instance initialised with
*argsand**kwargsas provided.- Return type:¶
Any
-
get_class(name: str, plugin_type: None | Literal[all] | str =
None) type[source]¶ Get a plugin class (not instance) by its full name (including category, i.e. of form
'my_category.my_subcategory.my_plugin'). If the plugin is not of the default plugin type, must provideplugin_type.- Parameters:¶
- name : plugin_typing.PluginFullName¶
Plugin full name including all (sub)categories, of form
'my_category.my_subcategory.my_plugin'- plugin_type : plugin_typing.PluginTypeArg, optional¶
Plugin type. If left as
None, default plugin type is assumed.plugin_typemust correctly correspond to the category implied by plugin full name. Defaults toNone.
- Returns:¶
Plugin class (not instance).
- Return type:¶
Type
-
list(plugin_type: None | Literal[all] | str =
-
tempor.core.plugins.PLUGIN_FILENAME_PREFIX =
'plugin_'¶ Prefix expected for plugin filenames of python files that contain plugin code.
- class tempor.core.plugins.importing[source]¶
Bases:
objectA namespace for plugin importing functionality.
- static import_plugins(init_file: str) None[source]¶
Import all plugin modules inside the package directory associated with
init_file(__init__.py). Importing in this context means programmatic import and execution of the plugin modules.- Parameters:¶
- Raises:¶
RuntimeError – Raised if there are import problems with any of the plugin modules.