class_docstr: Implementation of ``ClientAlgo`` to allow federated learning with MONAI bundle configurations.
  
  Args:
      bundle_root: directory path of the bundle.
      local_epochs: number of local epochs to execute during each round of local training; defaults to 1.
      send_weight_diff: whether to send weight differences rather than full weights; defaults to `True`.
      config_train_filename: bundle training config path relative to bundle_root. can be a list of files.
          defaults to "configs/train.json". only useful when `train_workflow` is None.
      train_kwargs: other args of the `ConfigWorkflow` of train, except for `config_file`, `meta_file`,
          `logging_file`, `workflow_type`. only useful when `train_workflow` is None.
      config_evaluate_filename: bundle evaluation config path relative to bundle_root. can be a list of files.
          if "default", ["configs/train.json", "configs/evaluate.json"] will be used.
          this arg is only useful when `eval_workflow` is None.
      eval_kwargs: other args of the `ConfigWorkflow` of evaluation, except for `config_file`, `meta_file`,
          `logging_file`, `workflow_type`. only useful when `eval_workflow` is None.
      config_filters_filename: filter configuration file. Can be a list of files; defaults to `None`.
      disable_ckpt_loading: do not use any CheckpointLoader if defined in train/evaluate configs; defaults to `True`.
      best_model_filepath: location of best model checkpoint; defaults "models/model.pt" relative to `bundle_root`.
      final_model_filepath: location of final model checkpoint; defaults "models/model_final.pt" relative to `bundle_root`.
      save_dict_key: If a model checkpoint contains several state dicts,
          the one defined by `save_dict_key` will be returned by `get_weights`; defaults to "model".
          If all state dicts should be returned, set `save_dict_key` to None.
      data_stats_transform_list: transforms to apply for the data stats result.
      eval_workflow_name: the workflow name corresponding to the "config_evaluate_filename", default to "train"
          as the default "config_evaluate_filename" overrides the train workflow config.
          this arg is only useful when `eval_workflow` is None.
      train_workflow: the bundle workflow to execute training, if None, will create a `ConfigWorkflow` internally
          based on `config_train_filename` and `train_kwargs`.
      eval_workflow: the bundle workflow to execute evaluation, if None, will create a `ConfigWorkflow` internally
          based on `config_evaluate_filename`, `eval_kwargs`, `eval_workflow_name`.
class_docstr_tok: ["Implementation","of","``","ClientAlgo","``","to","allow","federated","learning","with","MONAI","bundle","configurations",".","Args",":","bundle_root",":","directory","path","of","the","bundle",".","local_epochs",":","number","of","local","epochs","to","execute","during","each","round","of","local","training",";","defaults","to","1.","send_weight_diff",":","whether","to","send","weight","differences","rather","than","full","weights",";","defaults","to","`","True","`",".","config_train_filename",":","bundle","training","config","path","relative","to","bundle_root",".","can","be","a","list","of","files",".","defaults","to","``","configs\/train.json","''",".","only","useful","when","`","train_workflow","`","is","None",".","train_kwargs",":","other","args","of","the","`","ConfigWorkflow","`","of","train",",","except","for","`","config_file","`",",","`","meta_file","`",",","`","logging_file","`",",","`","workflow_type","`",".","only","useful","when","`","train_workflow","`","is","None",".","config_evaluate_filename",":","bundle","evaluation","config","path","relative","to","bundle_root",".","can","be","a","list","of","files",".","if","``","default","''",",","[","``","configs\/train.json","''",",","``","configs\/evaluate.json","''","]","will","be","used",".","this","arg","is","only","useful","when","`","eval_workflow","`","is","None",".","eval_kwargs",":","other","args","of","the","`","ConfigWorkflow","`","of","evaluation",",","except","for","`","config_file","`",",","`","meta_file","`",",","`","logging_file","`",",","`","workflow_type","`",".","only","useful","when","`","eval_workflow","`","is","None",".","config_filters_filename",":","filter","configuration","file",".","Can","be","a","list","of","files",";","defaults","to","`","None","`",".","disable_ckpt_loading",":","do","not","use","any","CheckpointLoader","if","defined","in","train\/evaluate","configs",";","defaults","to","`","True","`",".","best_model_filepath",":","location","of","best","model","checkpoint",";","defaults","``","models\/model.pt","''","relative","to","`","bundle_root","`",".","final_model_filepath",":","location","of","final","model","checkpoint",";","defaults","``","models\/model_final.pt","''","relative","to","`","bundle_root","`",".","save_dict_key",":","If","a","model","checkpoint","contains","several","state","dicts",",","the","one","defined","by","`","save_dict_key","`","will","be","returned","by","`","get_weights","`",";","defaults","to","``","model","''",".","If","all","state","dicts","should","be","returned",",","set","`","save_dict_key","`","to","None",".","data_stats_transform_list",":","transforms","to","apply","for","the","data","stats","result",".","eval_workflow_name",":","the","workflow","name","corresponding","to","the","``","config_evaluate_filename","''",",","default","to","``","train","''","as","the","default","``","config_evaluate_filename","''","overrides","the","train","workflow","config",".","this","arg","is","only","useful","when","`","eval_workflow","`","is","None",".","train_workflow",":","the","bundle","workflow","to","execute","training",",","if","None",",","will","create","a","`","ConfigWorkflow","`","internally","based","on","`","config_train_filename","`","and","`","train_kwargs","`",".","eval_workflow",":","the","bundle","workflow","to","execute","evaluation",",","if","None",",","will","create","a","`","ConfigWorkflow","`","internally","based","on","`","config_evaluate_filename","`",",","`","eval_kwargs","`",",","`","eval_workflow_name","`","."]
docstr: Returns the current weights of the model.
  
  Args:
      extra: Dict with additional information that can be provided by the FL system.
  
  Returns:
      return_weights: `ExchangeObject` containing current weights (default)
          or load requested model type from disk (`ModelType.BEST_MODEL` or `ModelType.FINAL_MODEL`).
docstr_tok: ["Returns","the","current","weights","of","the","model",".","Args",":","extra",":","Dict","with","additional","information","that","can","be","provided","by","the","FL","system",".","Returns",":","return_weights",":","`","ExchangeObject","`","containing","current","weights","(","default",")","or","load","requested","model","type","from","disk","(","`","ModelType.BEST_MODEL","`","or","`","ModelType.FINAL_MODEL","`",")","."]
code: def get_weights(self, extra=None):
      """
      Returns the current weights of the model.
  
      Args:
          extra: Dict with additional information that can be provided by the FL system.
  
      Returns:
          return_weights: `ExchangeObject` containing current weights (default)
              or load requested model type from disk (`ModelType.BEST_MODEL` or `ModelType.FINAL_MODEL`).
  
      """
  
      self._set_cuda_device()
      if extra is None:
          extra = {}
  
      # by default return current weights, return best if requested via model type.
      self.phase = FlPhase.GET_WEIGHTS
  
      if ExtraItems.MODEL_TYPE in extra:
          model_type = extra.get(ExtraItems.MODEL_TYPE)
          if not isinstance(model_type, ModelType):
              raise ValueError(
                  f"Expected requested model type to be of type `ModelType` but received {type(model_type)}"
              )
          if model_type in self.model_filepaths:
              model_path = os.path.join(
                  self.bundle_root,
                  cast(str, self.model_filepaths[model_type]),
              )
              if not os.path.isfile(model_path):
                  raise ValueError(
                      f"No best model checkpoint exists at {model_path}"
                  )
              weights = torch.load(model_path, map_location="cpu")
              # if weights contain several state dicts, use the one defined by `save_dict_key`
              if (
                  isinstance(weights, dict)
                  and self.save_dict_key in weights
              ):
                  weights = weights.get(self.save_dict_key)
              weigh_type: WeightType | None = WeightType.WEIGHTS
              stats: dict = {}
              self.logger.info(
                  f"Returning {model_type} checkpoint weights from {model_path}."
              )
          else:
              raise ValueError(
                  f"Requested model type {model_type} not specified in `model_filepaths`: {self.model_filepaths}"
              )
      else:
          if self.trainer:
              weights = get_state_dict(self.trainer.network)
              # returned weights will be on the cpu
              for k in weights.keys():
                  weights[k] = weights[k].cpu()
              weigh_type = WeightType.WEIGHTS
              stats = self.trainer.get_stats()
              # calculate current iteration and epoch data after training.
              stats[FlStatistics.NUM_EXECUTED_ITERATIONS] = (
                  self.trainer.state.iteration - self.iter_of_start_time
              )
              # compute weight differences
              if self.send_weight_diff:
                  weights = compute_weight_diff(
                      global_weights=self.global_weights,
                      local_var_dict=weights,
                  )
                  weigh_type = WeightType.WEIGHT_DIFF
                  self.logger.info(
                      "Returning current weight differences."
                  )
              else:
                  self.logger.info("Returning current weights.")
          else:
              weights = None
              weigh_type = None
              stats = dict()
  
      if not isinstance(stats, dict):
          raise ValueError(f"stats is not a dict, {stats}")
      return_weights = ExchangeObject(
          weights=weights,
          optim=None,  # could be self.optimizer.state_dict()
          weight_type=weigh_type,
          statistics=stats,
      )
  
      # filter weights if needed (use to apply differential privacy, encryption, compression, etc.)
      if self.post_weight_filters is not None:
          for _filter in self.post_weight_filters:
              return_weights = _filter(return_weights, extra)
  
      return return_weights
  
imports: from __future__ import annotations
  import os
  import time
  from collections.abc import Mapping, MutableMapping
  from typing import Any, cast
  import torch
  import torch.distributed
  from monai.apps.auto3dseg.data_analyzer import DataAnalyzer
  from monai.apps.utils import get_logger
  from monai.auto3dseg import SegSummarizer
  from monai.bundle import BundleWorkflow, ConfigComponent, ConfigItem, ConfigParser, ConfigWorkflow
  from monai.engines import SupervisedEvaluator, SupervisedTrainer, Trainer
  from monai.fl.client import ClientAlgo, ClientAlgoStats
  from monai.fl.utils.constants import ExtraItems, FiltersType, FlPhase, FlStatistics, ModelType, WeightType
  from monai.fl.utils.exchange_object import ExchangeObject
  from monai.networks.utils import copy_model_state, get_state_dict
  from monai.utils import min_version, require_pkg
  from monai.utils.enums import DataStatsKeys
label_desc: Use image node_id 4 for calling the MonaiAlgo obj's underlying member method code with example usage: obj.get_weights(extra) and returns: return_weights