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
- BaseNonModelAlgorithmFactory
- bitfount.federated.algorithms.model_algorithms.base._BaseModelAlgorithmFactory
Variables
- static
fields_dict : ClassVar[dict[str, marshmallow.fields.Field]]
- static
modeller : collections.abc.Callable[..., ~T_ModellerSide]
- static
nested_fields : ClassVar[dict[str, collections.abc.Mapping[str, Any]]]
- static
worker : collections.abc.Callable[..., ~T_WorkerSide]
BaseInitialSetupAlgorithm
class BaseInitialSetupAlgorithm(**kwargs: Any):Base class for algorithms that perform initial setup.
Provides a common base implementation for algorithms that need to run setup operations before batching begins.
Ancestors
- BaseWorkerAlgorithm
- bitfount.federated.algorithms.base._BaseAlgorithm
- abc.ABC
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:Inherited from:
BaseWorkerAlgorithm.initialise :
Initialises the algorithm.
This method is only called once regardless of the number of batches in the task.
This method must call the initialise_data method.
initialise_data
def initialise_data( self, datasource: BaseSource, data_splitter: Optional[DatasetSplitter] = None,) ‑> None:Inherited from:
BaseWorkerAlgorithm.initialise_data :
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.
This is called by the initialise method and should not be called directly by
the algorithm or protocol.
setup_run
def setup_run(self, **kwargs: Any) ‑> None:Run setup operations before batching begins.
This method will be called by protocols tagged with InitialSetupProtocol before any batching occurs.
BaseModellerAlgorithm
class BaseModellerAlgorithm(**kwargs: Any):Modeller side of the algorithm.
Subclasses
- NoResultsModellerAlgorithm
- ResultsOnlyModellerAlgorithm
- 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
- BaseAlgorithmFactory
- abc.ABC
- bitfount.federated.roles._RolesMixIn
- bitfount.types._BaseSerializableObjectMixIn
- typing.Generic
Subclasses
- CSVReportAlgorithm
- EHRPatientInfoDownloadAlgorithm
- EHRPatientQueryAlgorithm
- ImageSelectionAlgorithm
- RecordFilterAlgorithm
- HuggingFaceImageClassificationInference
- HuggingFaceImageSegmentationInference
- HuggingFacePerplexityEvaluation
- HuggingFaceTextClassificationInference
- HuggingFaceTextGenerationInference
- TIMMFineTuning
- TIMMInference
- BscanImageAndMaskGenerationAlgorithm
- CSVReportGeneratorOphthalmologyAlgorithm
- ETDRSAlgorithm
- FluidVolumeCalculationAlgorithm
- FoveaCoordinatesAlgorithm
- GATrialCalculationAlgorithmBase
- GATrialCalculationAlgorithmWithFoveaBase
- BaseGATrialInclusionAlgorithmFactory
- BaseGATrialPDFGeneratorAlgorithm
- ReduceCSVAlgorithmCharcoal
- bitfount.federated.algorithms.ophthalmology.simple_csv_algorithm._SimpleCSVAlgorithm
- PrivateSqlQuery
- S3UploadAlgorithm
- SqlQuery
Variables
- static
fields_dict : ClassVar[dict[str, marshmallow.fields.Field]]
- static
nested_fields : ClassVar[dict[str, collections.abc.Mapping[str, Any]]]
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.
Subclasses
- BaseInitialSetupAlgorithm
- 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.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._BaseWorkerSideWithFovea
- 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.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.
This method must call the initialise_data method.
initialise_data
def initialise_data( self, datasource: BaseSource, data_splitter: Optional[DatasetSplitter] = 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.
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
InitialSetupAlgorithm
class InitialSetupAlgorithm(*args, **kwargs):Protocol defining the interface for algorithms that perform initial setup.
Any algorithm used with InitialSetupProtocol must implement this interface.
Ancestors
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 InitialSetupProtocol before any batching occurs.
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
- BaseModellerAlgorithm
- bitfount.federated.algorithms.base._BaseAlgorithm
- abc.ABC
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
- BaseModellerAlgorithm
- bitfount.federated.algorithms.base._BaseAlgorithm
- abc.ABC
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.