fedn.utils package

The utils package is responsible for providing utility functions for the FEDn framework. Such as logging, checksums and other model helper functions to aggregate models. THe helper functions is there to support aggregating various models from different ML frameworks, such as Tensorflow, PyTorch and Keras.

Subpackages

Submodules

fedn.utils.checksum module

fedn.utils.checksum.sha(fname)[source]

Calculate the sha256 checksum of a file. Used for computing checksums of compute packages.

Parameters:

fname (str) – The file path.

Returns:

The sha256 checksum.

Return type:

hashlib.sha256

fedn.utils.dispatcher module

Portions of this code are derived from the Apache 2.0 licensed project mlflow (https://mlflow.org/)., with modifications made by Scaleout Systems AB. Copyright (c) 2018 Databricks, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class fedn.utils.dispatcher.Dispatcher(config, project_dir)[source]

Bases: object

Dispatcher class for compute packages.

Parameters:
  • config (dict) – The configuration.

  • dir (str) – The directory to dispatch to.

run_cmd(cmd_type, capture_output=False, extra_env=None, synchronous=True, stream_output=False)[source]

Run a command.

Parameters:

cmd_type (str) – The command type.

Returns:

fedn.utils.dispatcher.remove_on_error(path: PathLike, onerror=None)[source]

A context manager that removes a file or directory if an exception is raised during execution.

fedn.utils.process module

Portions of this code are derived from the Apache 2.0 licensed project mlflow (https://mlflow.org/)., with modifications made by Scaleout Systems AB. Copyright (c) 2018 Databricks, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

exception fedn.utils.process.ShellCommandException[source]

Bases: Exception

classmethod from_completed_process(process)[source]
fedn.utils.process.run_process(args, cwd)[source]

Run a process and log the output.

Parameters:
  • args (list) – The arguments to the process.

  • cwd (str) – The current working directory.

Returns: