Skip to main content

base

Base classes for all algorithms.

Each module in this package defines a single algorithm.

Attributes: registry: A read-only dictionary of algorithm factory names to their implementation classes.

Classes

AlgorithmDecoratorMetaClass

class AlgorithmDecoratorMetaClass(*args, **kwargs):

Decorates the __init__, initialise and run algorithm methods.

Ancestors

  • bitfount.hooks.BaseDecoratorMetaClass
  • builtins.type

Subclasses

  • types.AbstractAlgorithmDecoratorMetaClass

Static methods


decorator

def decorator(f: Callable)> collections.abc.Callable:

Hook and federated error decorators.

do_decorate

def do_decorate(attr: str, value: Any)> bool:

Checks if an object should be decorated.

Only the init, initialise and run methods should be decorated.

BaseAlgorithmFactory

class BaseAlgorithmFactory(**kwargs: Any):

Base algorithm factory from which all other algorithms must inherit.

Attributes

  • class_name: The name of the algorithm class.

Ancestors

  • abc.ABC
  • bitfount.federated.roles._RolesMixIn
  • bitfount.types._BaseSerializableObjectMixIn

Variables

BaseModellerAlgorithm

class BaseModellerAlgorithm(**kwargs: Any):

Modeller side of the algorithm.

Ancestors

  • bitfount.federated.algorithms.base._BaseAlgorithm
  • abc.ABC

Subclasses

Methods


initialise

def initialise(self, task_id: Optional[str], **kwargs: Any)> None:

Initialise the algorithm.

BaseWorkerAlgorithm

class BaseWorkerAlgorithm(**kwargs: Any):

Worker side of the algorithm.

Ancestors

  • bitfount.federated.algorithms.base._BaseAlgorithm
  • abc.ABC

Subclasses

  • bitfount.federated.algorithms.csv_report_algorithm._WorkerSide
  • bitfount.federated.algorithms.hugging_face_algorithms.hugging_face_image_classification._WorkerSide
  • bitfount.federated.algorithms.hugging_face_algorithms.hugging_face_image_segmentation._WorkerSide
  • bitfount.federated.algorithms.hugging_face_algorithms.hugging_face_perplexity._WorkerSide
  • bitfount.federated.algorithms.hugging_face_algorithms.hugging_face_text_classification._WorkerSide
  • bitfount.federated.algorithms.hugging_face_algorithms.hugging_face_text_generation._WorkerSide
  • bitfount.federated.algorithms.hugging_face_algorithms.timm_fine_tuning._WorkerSide
  • bitfount.federated.algorithms.hugging_face_algorithms.timm_inference._WorkerSide
  • bitfount.federated.algorithms.model_algorithms.base._BaseWorkerModelAlgorithm
  • bitfount.federated.algorithms.ophthalmology.csv_report_generation_ophth_algorithm._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.etdrs_calculation_algorithm._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.fovea_coordinates_algorithm._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.ga_trial_calculation_algorithm_jade._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.ga_trial_inclusion_criteria_match_algorithm_amethyst._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.ga_trial_inclusion_criteria_match_algorithm_jade._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.ga_trial_pdf_algorithm_amethyst._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.ga_trial_pdf_algorithm_jade._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.simple_csv_algorithm._WorkerSide
  • bitfount.federated.algorithms.private_sql_query._WorkerSide
  • bitfount.federated.algorithms.sql_query._WorkerSide

Methods


initialise

def initialise(    self,    datasource: BaseSource,    pod_dp: Optional[DPPodConfig] = None,    pod_identifier: Optional[str] = None,    **kwargs: Any,)> None:

Initialises the algorithm.

This method is only called once regardless of the number of batches in the task.

note

This method must call the initialise_data method.

initialise_data

def initialise_data(self, datasource: BaseSource)> None:

Initialises the algorithm with data.

This method will be called once per task batch. It is expected that algorithms will override this method to initialise their data in the required way.

note

This is called by the initialise method and should not be called directly by the algorithm or protocol.

NoResultsModellerAlgorithm

class NoResultsModellerAlgorithm(    log_message: Optional[str] = None,    save_path: Optional[Union[os.PathLike, str]] = None,    **kwargs: Any,):

Modeller side of any algorithm that does not return any results.

Arguments

  • log_message: A message to log when the algorithm is run on the modeller side.
  • save_path: The path the worker results should be saved to. This might be checked by the modeller if both modeller and worker are running on the same machine.
  • ****kwargs**: Additional keyword arguments.

Ancestors

Methods


initialise

def initialise(self, task_id: Optional[str] = None, **kwargs: Any)> None:

Nothing to initialise here.

run

def run(self, results: Mapping[str, Any])> None:

Modeller side just logs the log message.

ResultsOnlyModellerAlgorithm

class ResultsOnlyModellerAlgorithm(**kwargs: Any):

Modeller side of any algorithm that only returns results.

Ancestors

Methods


initialise

def initialise(self, task_id: Optional[str] = None, **kwargs: Any)> None:

Nothing to initialise here.

run

def run(self, results: Mapping[str, Any])> dict:

Modeller side just returns the results as a dictionary.