MEDfl 0.1.0__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,22 @@
1
+ echo '#!/bin/bash
2
+
3
+ # Update package lists
4
+ sudo apt update
5
+
6
+ # Install MySQL
7
+ sudo apt install mysql-server
8
+
9
+ # Secure MySQL installation
10
+ sudo mysql_secure_installation
11
+
12
+ # Install phpMyAdmin
13
+ sudo apt install phpmyadmin
14
+
15
+ # Create symbolic link for Apache
16
+ sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
17
+ sudo a2enconf phpmyadmin
18
+ sudo systemctl reload apache2
19
+
20
+ # Print completion message
21
+ echo "MySQL and phpMyAdmin setup complete."
22
+ ' > setup_mysql.sh && chmod +x setup_mysql.sh && python3 scripts/create_db.py
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.1
2
+ Name: Medfl
3
+ Version: 0.1.0
4
+ Summary: Python Open-source package for simulating federated learning and differential privacy
5
+ Home-page: https://github.com/HaithemLamri/MEDfl
6
+ Author: MEDomics consortium
7
+ Author-email: medomics.info@gmail.com
8
+ Project-URL: Documentation, https://
9
+ Project-URL: Github, https://github.com/HaithemLamri/MEDfl
10
+ Keywords: federated learning differential privacy medical research
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Requires-Python: >=3.8,<3.10
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)
35
+
36
+ # MEDfl : Federated Learning and Differential Privacy Simulation Tool for Tabular Data
37
+ ![Python Versions](https://img.shields.io/badge/python-3.9-blue)
38
+ ![Build Status](https://travis-ci.org/MEDomics-UdeS/MEDfl.svg?branch=main)
39
+
40
+ ![GitHub contributors](https://img.shields.io/github/contributors/scottydocs/README-template.md)
41
+ ![License: MIT](https://img.shields.io/badge/license-MIT-green)
42
+
43
+
44
+
45
+
46
+ ## Table of Contents
47
+ * [1. Introduction](#1-introduction)
48
+ * [2. Installation](#2-installation)
49
+ * [3. Documentation](#3-documentation)
50
+ * [4. Getting started](#4-Getting-started)
51
+ * [5. Acknowledgement](#5-acknowledgement)
52
+ * [6. Authors](#6-authors)
53
+ * [7. Statement](#7-statement)
54
+
55
+ ## 1. Introduction
56
+ This Python package is an open-source tool designed for simulating federated learning and incorporating differential privacy. It empowers researchers and developers to effortlessly create, execute, and assess federated learning pipelines while seamlessly working with various tabular datasets.
57
+
58
+
59
+
60
+
61
+
62
+ ## 2. Installation
63
+
64
+ ### Python installation
65
+ The MEDfl package requires *python 3.9* or more to be run. If you don't have it installed on your machine, check out the following link [Python ](https://www.python.org/downloads/).
66
+ It also requires MySQL database
67
+
68
+ ### Package installation
69
+ For now, you can install the ``MEDfl``package as:
70
+ ```
71
+ git clone https://github.com/MEDomics-UdeS/MEDfl.git
72
+ cd MEDfl
73
+ pip install -e .
74
+ ```
75
+ ### MySQL DB configuration
76
+ MEDfl requires a MySQL DB connection, and this is in order to allow users to work with their own tabular datasets, we have created a bash script to install and configure A MySQL DB with phpmyadmin monitoring system, run the following command then change your credential on the MEDfl/scripts/base.py and MEDfl/scripts/config.ini files
77
+ ```
78
+ sudo bash MEDfl/scripts/setup_mysql.sh
79
+ ```
80
+
81
+ ### Project Base URL Update
82
+ Please ensure to modify the `base_url` parameter in the `MEDfl/global_params.yaml` file. The `base_url` represents the path to the MEDfl project on your local machine. Update this value accordingly.
83
+
84
+ ## 3. Documentation
85
+ We used sphinx to create the documentation for this project. you can generate and host it locally by compiling the documentation source code using:
86
+ ```
87
+ cd docs
88
+ make clean
89
+ make html
90
+ ```
91
+
92
+ Then open it locally using:
93
+
94
+ ```
95
+ cd _build/html
96
+ python -m http.server
97
+ ```
98
+
99
+ ## 4. Getting started
100
+
101
+ We have created a complete tutorial for the different functionalities of the package. it can be found here [tutorial](https://github.com/MEDomics-UdeS/MEDfl/notebooks/First_tuto.ipynb)
102
+
103
+
104
+
105
+ ## 5. Acknowledgment
106
+ MEDfl is an open-source package that welcomes any contribution and feedback. We wish that this package could serve the growing private AI research community.
107
+
108
+ ## 6. Authors
109
+ * [MEDomics](https://github.com/medomics/): MEDomics consortium.
110
+
111
+ ## 7. Statement
112
+
113
+ This package is part of https://github.com/medomics, a package providing research utility tools for developing precision medicine applications.
114
+
115
+ ```
116
+ MIT License
117
+
118
+ Copyright (C) 2022 MEDomics consortium
119
+
120
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
121
+
122
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
123
+
124
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
125
+ ```
@@ -0,0 +1,10 @@
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,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.34.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ alembic
2
+ scripts
alembic/__init__.py ADDED
File without changes
alembic/env.py ADDED
@@ -0,0 +1,61 @@
1
+ from logging.config import fileConfig
2
+ import logging
3
+ from sqlalchemy import engine_from_config, create_engine
4
+ from sqlalchemy import pool
5
+ import sys
6
+ import os
7
+ from alembic import context
8
+
9
+ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10
+ from scripts.base import my_eng
11
+
12
+ # this is the Alembic Config object, which provides
13
+ # access to the values within the .ini file in use.
14
+ config = context.config
15
+
16
+ # Interpret the config file for Python logging.
17
+ # This line sets up loggers basically.
18
+ fileConfig(config.config_file_name)
19
+
20
+ # add your model's MetaData object here
21
+ # for 'autogenerate' support
22
+ # from myapp import mymodel
23
+ # target_metadata = mymodel.Base.metadata
24
+ target_metadata = None
25
+
26
+ # other values from the config, defined by the needs of env.py,
27
+ # can be acquired:
28
+ # my_important_option = config.get_main_option("my_important_option")
29
+ # ... etc.
30
+ def configure_logger(name):
31
+ # This is the standard logging configuration
32
+ logging.config.fileConfig(
33
+ 'alembic_logging.ini', # Path to your logging configuration file
34
+ defaults={
35
+ 'logfilename': 'alembic.log', # Log file name
36
+ },
37
+ disable_existing_loggers=False,
38
+ )
39
+
40
+ return logging.getLogger(name)
41
+
42
+
43
+
44
+ def run_migrations_offline():
45
+ """Run migrations in 'offline' mode."""
46
+ pass
47
+
48
+ def run_migrations_online():
49
+ """Run migrations in 'online' mode."""
50
+ pass
51
+
52
+ if context.is_offline_mode():
53
+ run_migrations_offline()
54
+ else:
55
+ run_migrations_online()
56
+
57
+
58
+ if context.is_offline_mode():
59
+ run_migrations_offline()
60
+ else:
61
+ run_migrations_online()
scripts/__init__.py ADDED
File without changes
scripts/base.py ADDED
@@ -0,0 +1,33 @@
1
+ import mysql.connector
2
+ from sqlalchemy import create_engine, text
3
+ from configparser import ConfigParser
4
+ import yaml
5
+ import pkg_resources
6
+ import os
7
+
8
+ # Load base_url from global_params.yaml
9
+ parent_directory = os.path.abspath(os.path.join(pkg_resources.resource_filename(__name__, ''), '..'))
10
+ global_params_path = os.path.join(parent_directory, 'global_params.yaml')
11
+
12
+ with open(global_params_path, 'r') as file:
13
+ params = yaml.safe_load(file)
14
+ base_url = params['base_url']
15
+
16
+ # Load configuration from the config file
17
+ config = ConfigParser()
18
+ config.read(base_url + '/scripts/config.ini')
19
+ mysql_config = config['mysql']
20
+
21
+
22
+
23
+ connection_string = (
24
+ f"mysql+mysqlconnector://{mysql_config['user']}:{mysql_config['password']}@"
25
+ f"{mysql_config['host']}:{mysql_config['port']}/{mysql_config['database']}"
26
+ )
27
+
28
+ eng = create_engine(
29
+ connection_string,
30
+ execution_options={"autocommit": True},
31
+ )
32
+
33
+ my_eng = eng.connect()
scripts/create_db.py ADDED
@@ -0,0 +1,113 @@
1
+ import mysql.connector
2
+ import pandas as pd
3
+ from mysql.connector import Error
4
+ from Medfl.LearningManager.utils import params
5
+
6
+ try:
7
+ mydb = mysql.connector.connect(host="localhost", user="ouael", password="ouael")
8
+ mycursor = mydb.cursor()
9
+
10
+ # Create the 'MEDfl' database if it doesn't exist
11
+ mycursor.execute("CREATE DATABASE IF NOT EXISTS MEDfl")
12
+
13
+ # Select the 'MEDfl' database
14
+ mycursor.execute("USE MEDfl")
15
+
16
+ # Get the list of all tables in the database
17
+ mycursor.execute("SHOW TABLES")
18
+ tables = mycursor.fetchall()
19
+
20
+
21
+
22
+
23
+ # Drop each table one by one
24
+ for table in tables:
25
+ table_name = table[0]
26
+ mycursor.execute(f"DROP TABLE IF EXISTS {table_name}")
27
+
28
+ # Create Networks table
29
+ mycursor.execute(
30
+ "CREATE TABLE Networks( \
31
+ NetId INT NOT NULL AUTO_INCREMENT, \
32
+ NetName VARCHAR(255), \
33
+ PRIMARY KEY (NetId) \
34
+ );"
35
+ )
36
+
37
+ # Create FLsetup table
38
+ mycursor.execute("CREATE TABLE FLsetup (\
39
+ FLsetupId int NOT NULL AUTO_INCREMENT,\
40
+ name varchar(255) NOT NULL, \
41
+ description varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,\
42
+ creation_date datetime NOT NULL,\
43
+ NetId int NOT NULL,\
44
+ column_name varchar(255) DEFAULT NULL,\
45
+ PRIMARY KEY (`FLsetupId`) \
46
+ )")
47
+
48
+ # Create Nodes table
49
+ mycursor.execute("CREATE TABLE Nodes ( \
50
+ NodeId int NOT NULL AUTO_INCREMENT,\
51
+ NodeName varchar(255) DEFAULT NULL,\
52
+ train tinyint(1) DEFAULT '1',\
53
+ NetId int DEFAULT NULL,\
54
+ PRIMARY KEY (NodeId)\
55
+ )")
56
+
57
+ data_df = pd.read_csv(params['path_to_master_csv'])
58
+ columns = data_df.columns.tolist()
59
+ column_map = {"object": "VARCHAR(255)", "int64": "INT", "float64": "FLOAT"}
60
+ sub_query = "".join(f"{col} {column_map[str(data_df[col].dtype)]}," for col in columns)
61
+
62
+ # Create Datasets table by getting columns from the master csv file
63
+ mycursor.execute(
64
+ f"CREATE TABLE DataSets( \
65
+ DataSetId INT NOT NULL AUTO_INCREMENT, \
66
+ DataSetName VARCHAR(255), \
67
+ NodeId INT CHECK (NodeId = -1 OR NodeId IS NOT NULL),\
68
+ {sub_query}\
69
+ PRIMARY KEY (DataSetId)\
70
+ )"
71
+ )
72
+
73
+ # Create FLpipeline table
74
+ mycursor.execute("CREATE TABLE FLpipeline(\
75
+ id int NOT NULL AUTO_INCREMENT,\
76
+ name varchar(255) NOT NULL, \
77
+ description varchar(255) NOT NULL,\
78
+ creation_date datetime NOT NULL,\
79
+ results longtext NOT NULL,\
80
+ PRIMARY KEY (id)\
81
+ ) ")
82
+
83
+ # Create test results table
84
+ mycursor.execute("CREATE TABLE testResults(\
85
+ pipelineId INT,\
86
+ nodename VARCHAR(100) NOT NULL, \
87
+ confusionmatrix VARCHAR(255),\
88
+ accuracy LONG,\
89
+ sensivity LONG,\
90
+ ppv LONG,\
91
+ npv LONG,\
92
+ f1score LONG,\
93
+ fpr LONG,\
94
+ tpr LONG, \
95
+ PRIMARY KEY (pipelineId , nodename)\
96
+ ) ")
97
+
98
+ # Create FederatedDataset table
99
+ mycursor.execute("CREATE TABLE FedDatasets (\
100
+ FedId int NOT NULL AUTO_INCREMENT,\
101
+ FLsetupId int DEFAULT NULL,\
102
+ FLpipeId int DEFAULT NULL,\
103
+ name varchar(255) NOT NULL,\
104
+ PRIMARY KEY (FedId)\
105
+ )")
106
+
107
+ # Commit and close the cursor
108
+ mydb.commit()
109
+ mycursor.close()
110
+ mydb.close()
111
+
112
+ except Error as e:
113
+ print(f"Error: {e}")