Skip to content

Commit

Permalink
ruff linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Hellander committed Dec 16, 2024
1 parent 500563c commit dd5db2f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
8 changes: 3 additions & 5 deletions examples/load-test/client/model.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# /bin/python
import sys
import time

import numpy as np

from fedn.utils.helpers.helpers import get_helper, save_metadata, save_metrics
from fedn.utils.helpers.helpers import get_helper

HELPER_MODULE = 'numpyhelper'
HELPER_MODULE = "numpyhelper"
ARRAY_SIZE = 20000000


Expand Down Expand Up @@ -35,7 +33,7 @@ def load_model(model_path):
return weights


def init_seed(out_path='seed.npz'):
def init_seed(out_path="seed.npz"):
""" Initialize seed model.
:param out_path: The path to save the seed model to.
Expand Down
7 changes: 3 additions & 4 deletions examples/load-test/client/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import numpy as np
from model import load_model, save_model

from fedn.utils.helpers.helpers import get_helper, save_metadata, save_metrics
from fedn.utils.helpers.helpers import save_metadata

HELPER_MODULE = 'numpyhelper'
HELPER_MODULE = "numpyhelper"
ARRAY_SIZE = 10000


def train(in_model_path, out_model_path):
""" Train model.
"""

# Load model
weights = load_model(in_model_path)

Expand All @@ -24,7 +23,7 @@ def train(in_model_path, out_model_path):

# Metadata needed for aggregation server side
metadata = {
'num_examples': ARRAY_SIZE,
"num_examples": ARRAY_SIZE,
}

# Save JSON metadata file
Expand Down
7 changes: 3 additions & 4 deletions examples/load-test/client/validate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# /bin/python
import sys
import time

import numpy as np
from model import load_model, save_model
from model import load_model

from fedn.utils.helpers.helpers import get_helper, save_metadata, save_metrics
from fedn.utils.helpers.helpers import save_metrics

HELPER_MODULE = 'numpyhelper'
HELPER_MODULE = "numpyhelper"
ARRAY_SIZE = 1000000


Expand Down
4 changes: 2 additions & 2 deletions fedn/network/combiner/aggregators/fedavg.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def combine_models(self, helper=None, delete_models=True, parameters=None):
tic = time.time()
model_next, metadata = self.update_handler.load_model_update(
model_update, helper)
data['time_model_load'] += time.time()-tic
data["time_model_load"] += time.time()-tic

logger.info("AGGREGATOR({}): Processing model update {}, metadata: {} ".format(
self.name, model_update.model_update_id, metadata))
Expand All @@ -72,7 +72,7 @@ def combine_models(self, helper=None, delete_models=True, parameters=None):
else:
model = helper.increment_average(
model, model_next, metadata["num_examples"], total_examples)
data['time_model_aggregation'] += time.time()-tic
data["time_model_aggregation"] += time.time()-tic

nr_aggregated_models += 1
# Delete model from storage
Expand Down
4 changes: 2 additions & 2 deletions fedn/network/combiner/aggregators/fedopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def combine_models(self, helper=None, delete_models=True, parameters=None):
tic = time.time()
model_next, metadata = self.update_handler.load_model_update(
model_update, helper)
data['time_model_load'] += time.time()-tic
data["time_model_load"] += time.time()-tic

logger.info("AGGREGATOR({}): Processing model update {}".format(
self.name, model_update.model_update_id))
Expand All @@ -129,7 +129,7 @@ def combine_models(self, helper=None, delete_models=True, parameters=None):
model_next, model_old)
pseudo_gradient = helper.increment_average(
pseudo_gradient, pseudo_gradient_next, metadata["num_examples"], total_examples)
data['time_model_aggregation'] += time.time()-tic
data["time_model_aggregation"] += time.time()-tic

nr_aggregated_models += 1
# Delete model from storage
Expand Down

0 comments on commit dd5db2f

Please sign in to comment.