MEDfl 0.1.0__py3-none-any.whl → 0.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,181 @@
1
+ import pandas as pd
2
+
3
+ from scripts.base import *
4
+ from .net_helper import *
5
+ from .net_manager_queries import *
6
+ from Medfl.LearningManager.utils import params
7
+
8
+
9
+ class Node:
10
+ """
11
+ A class representing a node in the network.
12
+
13
+ Attributes:
14
+ name (str): The name of the node.
15
+ train (int): An integer flag representing whether the node is used for training (1) or testing (0).
16
+ test_fraction (float, optional): The fraction of data used for testing when train=1. Default is 0.2.
17
+ """
18
+
19
+ def __init__(
20
+ self, name: str, train: int, test_fraction: float = 0.2, engine=my_eng
21
+ ):
22
+ """
23
+ Initialize a Node instance.
24
+
25
+ Parameters:
26
+ name (str): The name of the node.
27
+ train (int): An integer flag representing whether the node is used for training (1) or testing (0).
28
+ test_fraction (float, optional): The fraction of data used for testing when train=1. Default is 0.2.
29
+ """
30
+ self.name = name
31
+ self.train = train
32
+ self.test_fraction = 1.0 if self.train == 0 else test_fraction
33
+ self.engine = engine
34
+
35
+ def validate(self):
36
+ """Validate name, train, test_fraction"""
37
+ if not isinstance(self.name, str):
38
+ raise TypeError("name argument must be a string")
39
+
40
+ if not isinstance(self.train, int):
41
+ raise TypeError("train argument must be an int")
42
+
43
+ if not isinstance(self.test_fraction, float):
44
+ raise TypeError("test_fraction argument must be a float")
45
+
46
+ def create_node(self, NetId: int):
47
+ """Create a node in the database.
48
+ Parameters:
49
+ NetId (int): The ID of the network to which the node belongs.
50
+
51
+ Returns:
52
+ None
53
+ """
54
+ self.engine.execute(
55
+ text(INSERT_NODE_QUERY.format(self.name, NetId, self.train))
56
+ )
57
+
58
+ def delete_node(self):
59
+ """Delete the node from the database."""
60
+ self.engine.execute(text(DELETE_NODE_QUERY.format(self.name)))
61
+
62
+ def check_dataset_compatibility(self, data_df):
63
+ """Check if the dataset is compatible with the master dataset.
64
+ Parameters:
65
+ data_df (DataFrame): The dataset to check.
66
+
67
+ Returns:
68
+ None
69
+ """
70
+ if master_table_exists() != 1:
71
+ print("MasterDataset doesn't exist")
72
+ else:
73
+ columns = data_df.columns.tolist()
74
+ # get master_dataset columns
75
+ master_table_columns = pd.read_sql(
76
+ text(SELECT_MASTER_COLUMNS_QUERY), self.engine
77
+ ).columns.tolist()
78
+ assert [x == y for x, y in zip(master_table_columns, columns)]
79
+
80
+ def update_node(self):
81
+ """Update the node information (not implemented)."""
82
+ pass
83
+
84
+ def get_dataset(self, column_name: str = None):
85
+ """Get the dataset for the node based on the given column name.
86
+ Parameters:
87
+ column_name (str, optional): The column name to filter the dataset. Default is None.
88
+
89
+ Returns:
90
+ DataFrame: The dataset associated with the node.
91
+ """
92
+ NodeId = get_nodeid_from_name(self.name)
93
+ if column_name is not None:
94
+
95
+ node_dataset = pd.read_sql(
96
+ text(
97
+ SELECT_DATASET_BY_COLUMN_QUERY.format(
98
+ column_name, self.name
99
+ )
100
+ ),
101
+ self.engine,
102
+ )
103
+
104
+ else:
105
+ node_dataset = pd.read_sql(
106
+ text(SELECT_DATASET_BY_NODE_ID_QUERY.format(NodeId)),
107
+ self.engine,
108
+ )
109
+ return node_dataset
110
+
111
+ def upload_dataset(self, dataset_name: str, path_to_csv: str = params['path_to_test_csv']):
112
+ """Upload the dataset to the database for the node.
113
+ Parameters:
114
+ dataset_name (str): The name of the dataset.
115
+ path_to_csv (str, optional): Path to the CSV file containing the dataset. Default is the path in params.
116
+
117
+ Returns:
118
+ None
119
+ """
120
+ data_df = pd.read_csv(path_to_csv)
121
+
122
+ nodeId = get_nodeid_from_name(self.name)
123
+ columns = data_df.columns.tolist()
124
+ self.check_dataset_compatibility(data_df)
125
+
126
+ data_df = process_eicu(data_df)
127
+ for index, row in data_df.iterrows():
128
+ query_1 = "INSERT INTO DataSets(DataSetName,nodeId," + "".join(
129
+ f"{x}," for x in columns
130
+ )
131
+ query_2 = f" VALUES ('{dataset_name}',{nodeId}, " + "".join(
132
+ f"{is_str(data_df, row, x)}," for x in columns
133
+ )
134
+ query = query_1[:-1] + ")" + query_2[:-1] + ")"
135
+ self.engine.execute(text(query))
136
+
137
+ def assign_dataset(self, dataset_name:str):
138
+ """Assigning existing dataSet to node
139
+ Parameters:
140
+ dataset_name (str): The name of the dataset to assign.
141
+
142
+ Returns:
143
+ None
144
+ """
145
+
146
+ nodeId = get_nodeid_from_name(self.name)
147
+ query = f"UPDATE DataSets SET nodeId = {nodeId} WHERE DataSetName = '{dataset_name}'"
148
+ self.engine.execute(text(query))
149
+
150
+ def unassign_dataset(self, dataset_name:str):
151
+ """unssigning existing dataSet to node
152
+ Parameters:
153
+ dataset_name (str): The name of the dataset to assign.
154
+
155
+ Returns:
156
+ None
157
+ """
158
+
159
+ query = f"UPDATE DataSets SET nodeId = {-1} WHERE DataSetName = '{dataset_name}'"
160
+ self.engine.execute(text(query))
161
+
162
+ def list_alldatasets(self):
163
+ """List all datasets associated with the node.
164
+ Returns:
165
+ DataFrame: A DataFrame containing information about all datasets associated with the node.
166
+
167
+ """
168
+ return pd.read_sql(
169
+ text(SELECT_ALL_DATASETS_QUERY.format(self.name)), my_eng
170
+ )
171
+
172
+ @staticmethod
173
+ def list_allnodes():
174
+ """List all nodes in the database.
175
+ Returns:
176
+ DataFrame: A DataFrame containing information about all nodes in the database.
177
+
178
+ """
179
+ query = text(SELECT_ALL_NODES_QUERY)
180
+ res = pd.read_sql(query, my_eng)
181
+ return res
Medfl/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ from .LearningManager import *
2
+ from .NetManager import *
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Medfl
3
- Version: 0.1.0
3
+ Version: 0.1.4
4
4
  Summary: Python Open-source package for simulating federated learning and differential privacy
5
5
  Home-page: https://github.com/HaithemLamri/MEDfl
6
6
  Author: MEDomics consortium
@@ -14,24 +14,25 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
14
  Classifier: License :: OSI Approved :: MIT License
15
15
  Classifier: Programming Language :: Python :: 3.8
16
16
  Classifier: Programming Language :: Python :: 3.9
17
- Requires-Python: >=3.8,<3.10
17
+ Requires-Python: >=3.8,<3.11
18
18
  Description-Content-Type: text/markdown
19
- Requires-Dist: flwr (~=1.7.0)
20
- Requires-Dist: matplotlib (~=3.6.3)
21
- Requires-Dist: numpy (~=1.24.2)
22
- Requires-Dist: opacus (~=1.3.0)
23
- Requires-Dist: pandas (~=1.5.2)
24
- Requires-Dist: PyYAML (~=6.0)
25
- Requires-Dist: setuptools (~=68.0.0)
26
- Requires-Dist: Sphinx (~=5.3.0)
27
- Requires-Dist: SQLAlchemy (~=1.4.47)
28
- Requires-Dist: torch (~=1.13.1)
29
- Requires-Dist: datetime (~=5.1)
30
- Requires-Dist: scikit-learn (~=1.1.1)
31
- Requires-Dist: sphinx-jsonschema (==1.19.1)
32
- Requires-Dist: sphinx-rtd-dark-mode (==1.2.4)
33
- Requires-Dist: plotly (==5.19.0)
34
- Requires-Dist: optuna (==3.5.0)
19
+ Requires-Dist: flwr ~=1.7.0
20
+ Requires-Dist: matplotlib ~=3.6.3
21
+ Requires-Dist: numpy ~=1.24.2
22
+ Requires-Dist: opacus ~=1.3.0
23
+ Requires-Dist: pandas ~=1.5.2
24
+ Requires-Dist: PyYAML ~=6.0
25
+ Requires-Dist: setuptools ~=68.0.0
26
+ Requires-Dist: Sphinx ~=5.3.0
27
+ Requires-Dist: SQLAlchemy ~=1.4.47
28
+ Requires-Dist: torch ~=1.13.1
29
+ Requires-Dist: datetime ~=5.1
30
+ Requires-Dist: scikit-learn ~=1.1.1
31
+ Requires-Dist: sphinx-jsonschema ==1.19.1
32
+ Requires-Dist: sphinx-rtd-dark-mode ==1.2.4
33
+ Requires-Dist: plotly ==5.19.0
34
+ Requires-Dist: optuna ==3.5.0
35
+ Requires-Dist: mysql
35
36
 
36
37
  # MEDfl : Federated Learning and Differential Privacy Simulation Tool for Tabular Data
37
38
  ![Python Versions](https://img.shields.io/badge/python-3.9-blue)
@@ -0,0 +1,29 @@
1
+ Medfl/__init__.py,sha256=iJB4XxXxnyh_pnLFKAz3USENmFuMIuEwbLTKDiZqL3M,56
2
+ Medfl/LearningManager/__init__.py,sha256=ZLYv8hF2Jz0JEwdlrvgwsOC_67x-mQ_cJ7aCdrtW-ow,321
3
+ Medfl/LearningManager/client.py,sha256=t3fQ8SugGSYJ1cqN9vfB-KWj-wzHiqPLuCFkJVl0RY8,5933
4
+ Medfl/LearningManager/dynamicModal.py,sha256=q8u7xPpj_TdZnSr8kYj0Xx7Sdz-diXsKBAfVce8-qSU,10534
5
+ Medfl/LearningManager/federated_dataset.py,sha256=4ZnZA1YDx1JG51qE7CdlhwNQdKPxYX54iiMBRgp02dI,1925
6
+ Medfl/LearningManager/flpipeline.py,sha256=Fd44ZDLgvUCZQ5OJLMo8pcMjzGpT9wxiBJRBQg-RCwE,6958
7
+ Medfl/LearningManager/model.py,sha256=vp8FIMxBdz3FTF5wJaea2IO_WGeANLZgBxTKVe3gW3Q,7456
8
+ Medfl/LearningManager/params_optimiser.py,sha256=4uiR2ly9dsgJXjcsvX8hoxoUdTPaAvxI4k8MRgbHdgA,17618
9
+ Medfl/LearningManager/plot.py,sha256=A6Z8wC8J-H-OmWBPKqwK5eiTB9vzOBGMaFv1SaNA9Js,7698
10
+ Medfl/LearningManager/server.py,sha256=8AKBGYLC0PXa7jAoy29orixhgB9bF3q0TEQjxssDvow,7026
11
+ Medfl/LearningManager/strategy.py,sha256=pPqhqMtv_ycPxyGbeH9UpvrTY7H5lOfeQckqiYTKHdM,3434
12
+ Medfl/LearningManager/utils.py,sha256=nZDelVsuyctrzjQIbIo057FwBaEpNrnUimMtZkw--wY,7389
13
+ Medfl/NetManager/__init__.py,sha256=-1Ox7WSmMT1RAqjfbqT85GUqt3Bqq-iRvkNVCE9gmDc,221
14
+ Medfl/NetManager/dataset.py,sha256=X5zzlWT7uWdsHkrTcSfJa_R6Z_uZwgjb1wQkpuog2z4,2691
15
+ Medfl/NetManager/flsetup.py,sha256=eoJbQHV9RKvEog3jq8NlT-IsAoQli0EOFKpr7sZV0QE,11001
16
+ Medfl/NetManager/net_helper.py,sha256=r4I3ZwhjEHweV5DaYc4lamucCe_OdB-gevteVeTiuiA,6108
17
+ Medfl/NetManager/net_manager_queries.py,sha256=2jEIJ6qWLJv8AgusqTnRjJwq_keU6M3V0v09Azwf9fs,4190
18
+ Medfl/NetManager/network.py,sha256=nRvdrNheE5gi84wNbVS09T1jMEq9YADYbV9M_DryP3A,5091
19
+ Medfl/NetManager/node.py,sha256=c3DxcOXGfVmQvz-tzT2GKFWW7V2rcFuuw44uKOvdm_k,6153
20
+ Medfl-0.1.4.data/scripts/setup_mysql.sh,sha256=r4ygRl7zdasUSZT-ccC1Tjtt6GKDS5Puza9hCec2Cns,538
21
+ alembic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ alembic/env.py,sha256=-aSZ6SlJeK1ZeqHgM-54hOi9LhJRFP0SZGjut-JnY-4,1588
23
+ scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
+ scripts/base.py,sha256=xyiLkJ46nVrs3rNHP39LIH_03bmn5FU_gqpSTGJ_nVE,923
25
+ scripts/create_db.py,sha256=NYysjkiMWNjEawpOJL8iLAwNGUk4YITUMudiJgLQIGA,3364
26
+ Medfl-0.1.4.dist-info/METADATA,sha256=eSK0g_9_z0TJYQsBURopolN1JijwgHJOdxsuPziOzak,5411
27
+ Medfl-0.1.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
28
+ Medfl-0.1.4.dist-info/top_level.txt,sha256=CmLt1TC7PJj-V55rhffMZ9LSOiuSaaEbz9FJm_zOw_E,22
29
+ Medfl-0.1.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.34.2)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,2 +1,3 @@
1
+ Medfl
1
2
  alembic
2
3
  scripts
@@ -1,10 +0,0 @@
1
- Medfl-0.1.0.data/scripts/setup_mysql.sh,sha256=r4ygRl7zdasUSZT-ccC1Tjtt6GKDS5Puza9hCec2Cns,538
2
- alembic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- alembic/env.py,sha256=-aSZ6SlJeK1ZeqHgM-54hOi9LhJRFP0SZGjut-JnY-4,1588
4
- scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- scripts/base.py,sha256=xyiLkJ46nVrs3rNHP39LIH_03bmn5FU_gqpSTGJ_nVE,923
6
- scripts/create_db.py,sha256=NYysjkiMWNjEawpOJL8iLAwNGUk4YITUMudiJgLQIGA,3364
7
- Medfl-0.1.0.dist-info/METADATA,sha256=71x4zhRdj7KsRqK8hFiQCAl41NHL1F_P8o3n3Y5TqXw,5422
8
- Medfl-0.1.0.dist-info/WHEEL,sha256=g4nMs7d-Xl9-xC9XovUrsDHGXt-FT0E17Yqo92DEfvY,92
9
- Medfl-0.1.0.dist-info/top_level.txt,sha256=mXk5utWsktWUZwSh3_kKF4Fv3MiV9-MtMMY8okENUBQ,16
10
- Medfl-0.1.0.dist-info/RECORD,,