Base Modules

Base

class BaseModel(device=None, model_name='BaseModel', verbose='none')[source]

Bases: ABC

Base class for molecular models with shared functionality.

This abstract class provides common methods and utilities for molecular models, including model initialization, saving/loading, and parameter management.

Parameters:
  • device (torch.device, optional) – Device to run the model on. If None, automatically selects CUDA if available, otherwise CPU.

  • model_name (str, default="BaseModel") – String identifier for the model name which can be specified by the user.

  • verbose (str, default="none") – Whether to display progress info. Options are: “none”, “progress_bar”, “print_statement”. If any other, “none” is automatically chosen.

model_class

The class of the model used to initialize the model instance.

Type:

type or None

model

The fitted model instance if the model has been trained, None otherwise.

Type:

object or None

is_fitted_

Whether the model has been fitted/trained. False by default.

Type:

bool

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

Dictionary of parameter names mapped to their values

Return type:

Dict[str, Any]

load(path=None, repo_id=None, **kwargs)[source]

Automatic load from either local disk or Hugging Face Hub.

Parameters:
  • path (Optional[str], default=None) – File path for local loading.

  • repo_id (Optional[str], default=None) – Hugging Face repository ID for remote loading. If path is provided, repo_id is ignored.

  • **kwargs – Additional arguments passed to load_from_hf

Raises:

FileNotFoundError – If no local file is found and no repo_id is provided

Return type:

None

load_from_hf(repo_id, local_cache=None, config_filename='config.json')[source]

Load model from Hugging Face Hub.

Parameters:
  • repo_id (str) – Hugging Face repository ID

  • local_cache (str, default=None) – Local path to save the model

  • config_filename (str, default='config.json') – Name of the configuration file to load from the repository

Return type:

None

load_from_local(path)[source]

Load model from local disk.

Parameters:

path (str) – File path to load the model from

Return type:

None

save(path=None, repo_id=None, **kwargs)[source]

Automatic save to either local disk or Hugging Face Hub.

Parameters:
  • path (Optional[str], default=None) – File path for local saving (required if repo_id is None)

  • repo_id (Optional[str], default=None) – Hugging Face repository ID for remote saving

  • **kwargs – Additional arguments passed to save_to_hf

Raises:

ValueError – If path is None when repo_id is None

Return type:

None

save_to_hf(repo_id, task_id='default', metadata_dict=None, metrics=None, commit_message='Update model', hf_token=None, private=False, config_filename='config.json')[source]

Save model to Hugging Face Hub.

Parameters:
  • repo_id (str) – Hugging Face repository ID

  • task_id (str, default="default") – Task identifier for the model

  • metadata_dict (Optional[Dict[str, Any]], default=None) – Optional metadata to store with the model

  • metrics (Optional[Dict[str, float]], default=None) – Optional performance metrics to store with the model

  • commit_message (str, default="Update model") – Git commit message

  • hf_token (Optional[str], default=None) – Hugging Face authentication token

  • private (bool, default=False) – Whether the repository should be private

  • config_filename (Optional[str], default='config.json') – Name of the configuration file to save to the repository

Raises:

ValueError – If the model is not fitted

Return type:

None

save_to_local(path)[source]

Save model to local disk.

Parameters:

path (str) – File path to save the model

Raises:

ValueError – If the model is not fitted

Return type:

None

set_params(**params)[source]

Set parameters for this estimator.

Parameters:

**params – Parameter names mapped to their values

Returns:

Self instance for method chaining

Return type:

BaseModel

Raises:

ValueError – If an invalid parameter is provided

Base Predictor

class BaseMolecularPredictor(*, device=None, model_name='BaseMolecularPredictor', num_task=0, task_type=None, verbose='none')[source]

Bases: BaseModel, ABC

Base class for molecular discovery estimators.

Parameters:
  • device (device | str | None)

  • model_name (str)

  • num_task (int)

  • task_type (str | None)

  • verbose (str)

abstractmethod autofit(X_train, y_train, X_val=None, y_val=None, search_parameters=None, n_trials=10)[source]
Parameters:
  • search_parameters (dict | None)

  • n_trials (int)

Return type:

BaseMolecularPredictor

abstractmethod fit(X_train, y_train, X_val=None, y_val=None, search_parameters=None, n_trials=10)[source]
Parameters:
  • search_parameters (dict | None)

  • n_trials (int)

Return type:

BaseMolecularPredictor

abstractmethod predict(X)[source]
Parameters:

X (ndarray)

Return type:

ndarray

Base Generator

class BaseMolecularGenerator(*, device=None, model_name='BaseMolecularGenerator', verbose='none')[source]

Bases: BaseModel, ABC

Base class for molecular generation.

Parameters:
  • device (device | str | None)

  • model_name (str)

  • verbose (str)

abstractmethod fit(X, y=None)[source]
Parameters:
  • X (List[str])

  • y (ndarray | None)

Return type:

BaseMolecularGenerator

abstractmethod generate(n_samples, **kwargs)[source]

Generate molecular structures.

Parameters:

n_samples (int)

Return type:

List[str]

Base Encoder

class BaseMolecularEncoder(*, device=None, model_name='BaseMolecularEncoder', verbose='none')[source]

Bases: BaseModel, ABC

Base class for molecular representation learning.

Parameters:
  • device (device | str | None)

  • model_name (str)

  • verbose (str)

abstractmethod encode(X, return_type='pt')[source]
Parameters:
  • X (List[str])

  • return_type (Literal['np', 'pt'])

Return type:

ndarray | Tensor

abstractmethod fit(X, y=None)[source]
Parameters:
  • X (List[str])

  • y (ndarray | None)

Return type:

BaseMolecularEncoder