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
  • typing.Generic

Subclasses

Variables

BaseModellerAlgorithm

class BaseModellerAlgorithm(**kwargs: Any):

Modeller side of the algorithm.

Ancestors

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

Subclasses

  • NoResultsModellerAlgorithm
  • ResultsOnlyModellerAlgorithm
  • bitfount.federated.algorithms.filtering_algorithm._ModellerSide
  • bitfount.federated.algorithms.hugging_face_algorithms.base._HFModellerSide
  • bitfount.federated.algorithms.model_algorithms.base._BaseModellerModelAlgorithm
  • bitfount.federated.algorithms.s3_upload_algorithm._ModellerSide

Methods


initialise

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

Initialise the algorithm.

BaseNonModelAlgorithmFactory

class BaseNonModelAlgorithmFactory(*, datastructure: DataStructure, **kwargs: Any):

Base factory for algorithms not involving an underlying model.

Arguments

  • datastructure: The data structure to use for the algorithm.
  • ****kwargs**: Additional keyword arguments.

Attributes

  • datastructure: The data structure to use for the algorithm.

Ancestors

Variables

Methods


modeller

def modeller(self, *, context: ProtocolContext, **kwargs: Any)> ~T_ModellerSide:

Modeller-side of the algorithm.

worker

def worker(self, *, context: ProtocolContext, **kwargs: Any)> ~T_WorkerSide:

Worker-side of 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
  • BaseEHRWorkerAlgorithm
  • bitfount.federated.algorithms.ehr.image_selection_algorithm._WorkerSide
  • bitfount.federated.algorithms.filtering_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.bscan_image_and_mask_generation_algorithm._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.cst_calculation_algorithm._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.csv_report_generation_ophth_algorithm._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.etdrs_calculation_algorithm._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.fluid_volume_calculation_algorithm._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.fovea_coordinates_algorithm._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.ga_trial_calculation_algorithm_base._WorkerSide
  • BaseGATrialInclusionWorkerAlgorithm
  • bitfount.federated.algorithms.ophthalmology.ga_trial_pdf_algorithm_base._BasePDFWorkerSide
  • bitfount.federated.algorithms.ophthalmology.longitudinal_algorithm._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.reduce_csv_algorithm_charcoal._WorkerSide
  • bitfount.federated.algorithms.ophthalmology.simple_csv_algorithm._WorkerSide
  • bitfount.federated.algorithms.private_sql_query._WorkerSide
  • bitfount.federated.algorithms.s3_upload_algorithm._WorkerSide
  • bitfount.federated.algorithms.sql_query._WorkerSide

Methods


initialise

def initialise(    self,    *,    datasource: BaseSource,    task_id: str,    data_splitter: Optional[DatasetSplitter] = None,    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,    data_splitter: Optional[DatasetSplitter] = None,    cached_data: Optional[pd.DataFrame] = None,)> 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.

FinalStepAlgorithm

class FinalStepAlgorithm():

Tagging interface for algorithms that contain a final "reduce" step.

These algorithms have steps that can be operated batch-wise (normal run()) followed by step(s) at the end that cannot be executed batch-wise but instead require access to outputs from all batch steps (reduce step(s)).

Subclasses

  • 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.ophthalmology.csv_report_generation_ophth_algorithm._WorkerSide

Methods


run_final_step

def run_final_step(self, *, context: ProtocolContext, **kwargs: Any)> Any:

Execute the final step without datasource access.

This method is called after all batch processing is complete and should not access the datasource directly.

Arguments

  • context: The protocol context containing runtime information for the protocol.
  • ****kwargs**: Additional context like accumulated results, task_id, etc.

Returns Final processed results

InitialSetupModellerAlgorithm

class InitialSetupModellerAlgorithm(*args, **kwargs):

Protocol defining the interface for Modeller algorithms that do initial setup.

Any algorithm used with InitialSetupModellerProtocol must implement this interface.

Variables

  • remote_modeller : bool - Whether the algorithm needs to accommodate a remote modeller.

    If True, calls values_to_send_to_worker to get the values to send to the worker side of the algorithm.

Methods


values_to_send_to_worker

def values_to_send_to_worker(self)> dict[str, typing.Any]:

Get the values to send to the worker side of the algorithm.

InitialSetupWorkerAlgorithm

class InitialSetupWorkerAlgorithm(*args, **kwargs):

Protocol defining the interface for Worker algorithms that perform initial setup.

Any algorithm used with InitialSetupWorkerProtocol must implement this interface.

Variables

  • remote_modeller : bool - Whether the algorithm needs to accommodate a remote modeller.

    If True, calls values_to_send_to_worker to get the values to send to the worker side of the algorithm.

Methods


setup_run

def setup_run(self, **kwargs: Any)> None:

Run setup operations before batching begins.

This method will be called by protocols tagged with InitialSetupWorkerProtocol before any batching occurs.

update_values_from_modeller

def update_values_from_modeller(self, values: dict[str, Any])> None:

Update the values sent from the modeller side of the algorithm.

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 modeller results should be saved to, if any.
  • ****kwargs**: Additional keyword arguments.

Ancestors

Subclasses

  • bitfount.federated.algorithms.ehr.ehr_patient_query_algorithm._ModellerSide

Methods


initialise

def initialise(self, *, task_id: str, **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: str, **kwargs: Any)> None:

Nothing to initialise here.

run

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

Modeller side just returns the results as a dictionary.