Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed various type checking and mismatched type errors #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/algos/MetaL2C.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def run_protocol(self) -> None:
total_rounds = self.config["rounds"]

stats = []
avg_alpha = None
avg_alpha : Dict[str, torch.Tensor] = {}
for cur_round in range(start_round, total_rounds):
self.round = cur_round
self.log_utils.log_console(f"Starting round {cur_round}")
Expand Down
2 changes: 1 addition & 1 deletion src/algos/attack_add_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from collections import OrderedDict
from typing import Dict
from torch import Tensor
from utils.types import ConfigType
from utils.custom_types import ConfigType


class AddNoiseAttack:
Expand Down
2 changes: 1 addition & 1 deletion src/algos/attack_bad_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from collections import OrderedDict
from typing import Dict
from torch import Tensor
from utils.types import ConfigType
from utils.custom_types import ConfigType


class BadWeightsAttack:
Expand Down
2 changes: 1 addition & 1 deletion src/algos/attack_sign_flip.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from collections import OrderedDict
from typing import Dict
from torch import Tensor
from utils.types import ConfigType
from utils.custom_types import ConfigType


class SignFlipAttack:
Expand Down
2 changes: 1 addition & 1 deletion src/algos/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
get_dset_balanced_communities,
get_dset_communities,
)
from utils.types import ConfigType
from utils.custom_types import ConfigType
from utils.dropout_utils import NodeDropout

import torchvision.transforms as T # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion src/algos/topologies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import networkx as nx

from utils.types import ConfigType
from utils.custom_types import ConfigType

class BaseTopology(ABC):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/algos/topologies/collections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from algos.topologies.base import BaseTopology
from utils.types import ConfigType
from utils.custom_types import ConfigType

from math import ceil
import networkx as nx
Expand Down
2 changes: 1 addition & 1 deletion src/configs/algo_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Dict, List
from .malicious_config import malicious_config_list
import random
from utils.types import ConfigType
from utils.custom_types import ConfigType


def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, str]:
Expand Down
2 changes: 1 addition & 1 deletion src/configs/algo_config_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from utils.types import ConfigType
from utils.custom_types import ConfigType

fedstatic: ConfigType = {
# Collaboration setup
Expand Down
2 changes: 1 addition & 1 deletion src/configs/malicious_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Malicious Configuration
from utils.types import ConfigType
from utils.custom_types import ConfigType
from typing import Dict

# Weight Update Attacks
Expand Down
32 changes: 16 additions & 16 deletions src/configs/non_iid_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@ def get_domain_support(
return support


CIFAR10_ROT_DMN: List[str] = ["r0", "r90", "r180", "r270"]
CIFAR10_ROT_DMN: List[str | int] = ["r0", "r90", "r180", "r270"]


def get_cifar10_rot_support(
num_clients: int, domains: List[str] = CIFAR10_ROT_DMN
num_clients: int, domains: List[str | int] = CIFAR10_ROT_DMN
) -> Dict[str, str]:
return get_domain_support(num_clients, "cifar10", domains)


DOMAINNET_DMN: List[str] = ["real", "sketch", "clipart"]
DOMAINNET_DMN: List[str | int] = ["real", "sketch", "clipart"]


def get_domainnet_support(
num_clients: int, domains: List[str] = DOMAINNET_DMN
num_clients: int, domains: List[str | int] = DOMAINNET_DMN
) -> Dict[str, str]:
return get_domain_support(num_clients, "domainnet", domains)


DOMAINNET_DMN_FULL: List[str] = [
DOMAINNET_DMN_FULL: List[str | int] = [
"real",
"sketch",
"clipart",
Expand All @@ -130,42 +130,42 @@ def get_domainnet_support(


def get_domainnet_support_full(
num_clients: int, domains: List[str] = DOMAINNET_DMN_FULL
num_clients: int, domains: List[str | int] = DOMAINNET_DMN_FULL
) -> Dict[str, str]:
return get_domain_support(num_clients, "domainnet", domains)


DOMAINNET_DMN_V2: List[str] = ["infograph", "quickdraw", "painting"]
DOMAINNET_DMN_V2: List[str | int] = ["infograph", "quickdraw", "painting"]


def get_domainnet_support_v2(
num_clients: int, domains: List[str] = DOMAINNET_DMN_V2
num_clients: int, domains: List[str | int] = DOMAINNET_DMN_V2
) -> Dict[str, str]:
return get_domain_support(num_clients, "domainnet", domains)


IWILDCAM_DMN: List[int] = list(range(1, 5)) # 245 possible
IWILDCAM_DMN: List[str | int] = list(range(1, 5)) # 245 possible


def get_iwildcam_support(
num_clients: int, domains: List[int] = IWILDCAM_DMN
num_clients: int, domains: List[str | int] = IWILDCAM_DMN
) -> Dict[str, str]:
return get_domain_support(num_clients, "wilds_iwildcam", domains)


# 2 classes
# 3 domains: 0:116'959, 3:132'052, 4:5'3425 in training set
CAMELYON17_DMN: List[int] = [0, 3, 4] # + 1, 2 in test set
CAMELYON17_DMN: List[str | int] = [0, 3, 4] # + 1, 2 in test set


def get_camelyon17_support(
num_clients: int, domains: List[int] = CAMELYON17_DMN
num_clients: int, domains: List[str | int] = CAMELYON17_DMN
) -> Dict[str, str]:
return get_domain_support(num_clients, "wilds_camelyon17", domains)


# Issue every of the 1139 classes has only 1 sample per domain => how to create in domain test set ?
RXRX1_DMN = [
RXRX1_DMN: List[str | int] = [
0,
1,
2,
Expand All @@ -175,15 +175,15 @@ def get_camelyon17_support(
] # in train set: 0-6, 11-26, 35-41, 46-48, in test set: 7-10, 27-34, 42-45, 49-50


def get_rxrx1_support(num_clients, domains=RXRX1_DMN):
def get_rxrx1_support(num_clients: int, domains: List[str|int] =RXRX1_DMN):
return get_domain_support(num_clients, "wilds_rxrx1", domains)


# 0: 17'809, 1: 34'816, 2: 1'582, 3: 20'973, 4:1'641, 5: 42
FMOW_DMN = [0, 1, 3]
FMOW_DMN : List[str|int] = [0, 1, 3]


def get_fmow_support(num_clients, domains=FMOW_DMN):
def get_fmow_support(num_clients: int, domains : List[str|int] =FMOW_DMN):
return get_domain_support(num_clients, "wilds_fmow", domains)


Expand Down
4 changes: 2 additions & 2 deletions src/configs/sys_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# is to simulate different real-world scenarios without changing the algorithm configuration.
from typing import Dict, List, Literal, Optional
import random
from utils.types import ConfigType
from utils.custom_types import ConfigType

# from utils.config_utils import get_sliding_window_support, get_device_ids
from .algo_config import (
Expand Down Expand Up @@ -334,7 +334,7 @@ def get_digit_five_support(num_users: int, domains: List[str] = DIGIT_FIVE):

# for swift or fedavgpush, just modify the algo_configs list
# for swift, synchronous should preferable be False
gpu_ids = [2, 3, 5, 6]
gpu_ids : List[int | Literal['cpu']] = [2, 3, 5, 6]

grpc_system_config: ConfigType = {
"exp_id": "static",
Expand Down
6 changes: 3 additions & 3 deletions src/configs/sys_config_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Dict, List, Literal, Optional
import random
from utils.types import ConfigType
from utils.custom_types import ConfigType

from .algo_config_test import (
traditional_fl,
#traditional_fl,
fedstatic
)

Expand Down Expand Up @@ -99,7 +99,7 @@ def get_algo_configs(
for i in range(1, num_users + 1):
dropout_dicts[f"node_{i}"] = dropout_dict

gpu_ids = [2, 3, 5, 6]
gpu_ids : List[int | Literal['cpu']] = [2, 3, 5, 6]

grpc_system_config: ConfigType = {
"exp_id": "static",
Expand Down
2 changes: 1 addition & 1 deletion src/main_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# Command for opening each process
command_list: List[str] = ["python", "main.py", "-host", args.host]
if args.dev == True:
command_list: List[str] = ["python", "main.py", "-b", "./configs/algo_config_test.py", "-s", "./configs/sys_config_test.py", "-host", args.host]
command_list = ["python", "main.py", "-b", "./configs/algo_config_test.py", "-s", "./configs/sys_config_test.py", "-host", args.host]

# Start process for each user
for i in range(args.n):
Expand Down
Loading