From 97bc1f6b9ce3a0d3bae4e8b404e879c8b164524b Mon Sep 17 00:00:00 2001
From: huongdm1896 <domaihuong1451997@gmail.com>
Date: Tue, 25 Feb 2025 16:57:16 +0100
Subject: [PATCH] reduce instances to 6, reduce epoch client_1 to 1, update
 readme

---
 Flower_v1/client_1.py                         |   2 +-
 README.md                                     |  23 +-
 Run/config_instances.json                     | 332 +-----------------
 Run/config_instances_CPU.json                 | 114 ++++++
 ...ances_1.json => config_instances_GPU.json} |   0
 Run/measure_campaign.py                       |   2 +-
 Run/measure_instance.py                       |   5 +-
 7 files changed, 133 insertions(+), 345 deletions(-)
 create mode 100644 Run/config_instances_CPU.json
 rename Run/{config_instances_1.json => config_instances_GPU.json} (100%)

diff --git a/Flower_v1/client_1.py b/Flower_v1/client_1.py
index af26d00..8d0aed8 100644
--- a/Flower_v1/client_1.py
+++ b/Flower_v1/client_1.py
@@ -87,7 +87,7 @@ class FederatedClient(fl.client.NumPyClient):
 
     def fit(self, parameters, config):
         model.set_weights(parameters)
-        model.fit(x_train, y_train, epochs=5, batch_size=32, validation_data=(x_val, y_val))
+        model.fit(x_train, y_train, epochs=1, batch_size=32, validation_data=(x_val, y_val))
         return model.get_weights(), len(x_train), {}
 
     def evaluate(self, parameters, config):
diff --git a/README.md b/README.md
index 62c3af3..a9a03c0 100644
--- a/README.md
+++ b/README.md
@@ -188,16 +188,18 @@ cd Run
 ```
 
 ### Step 2. Configure
-Two JSON configuration files (e.g. `config_instances.json` for CPU and `config_instances_1.json` for GPU) to specify experiment details includes one or more instances. 
+Two JSON configuration files (e.g. `config_instances_CPU.json` for CPU and `config_instances_GPU.json` for GPU) to specify experiment details includes one or more instances. 
 
 ```bash
-cat config_instances.json
+cat config_instances_CPU.json
 ```
 
-<u>For example</u>: `config_instances.json` provides two examples of instance configuration. All fields are configured except "`output_dir`" and "`args`" must be updated with your directories setting.
+<u>For example</u>: `config_instances_CPU.json` provides two examples of instance configuration.
 - instance "`1`": fedAvg, cifar10, dvfs with min and max CPU freq, 1 round.
 - instance "`2`": fedAvg2Clients, cifar10, dvfs with min and max CPU freq, 1 round.
 
+Total test time is about 5 minutes.
+
 ### Step 3. Collect IP
 
 Run the following command to collect/generate a node list:
@@ -207,19 +209,19 @@ uniq $OAR_NODEFILE > nodelist
 
 Automatically populate missing IP addresses in the JSON file:
 ```bash
-python3 collect_ip.py -n nodelist -c config_instances.json
+python3 collect_ip.py -n nodelist -c config_instances_CPU.json
 ```
 
 ### Step 4. Run the Campaign or Single Instance
 
 Run single instance with instance `1`, and 2 repetitions:
 ```bash
-python3 measure_instance.py -c config_instances.json -i 1 -x SingleTest -r 2
+python3 measure_instance.py -x SingleTest -c config_instances_CPU.json -i 1 -r 2
 ```
 
 Run a campaign with all instances (`1` and `2`), and 2 repetitions:
 ```bash
-python3 measure_campaign.py -x CampaignTest -c config_instances.json -r 2
+python3 measure_campaign.py -x CampaignTest -c config_instances_CPU.json -r 2
 ```
 
 ### Step 5. Output
@@ -229,10 +231,10 @@ The logs and energy monitoring data will be saved in the directory specified in
 Output dir structure:
 
 ```plaintext
-/Flower_<x>
-├── Flower_instance_<instance_name>
+Log/Flower_CampaignTest
+├── Flower_instance_Flower_instance_fedAvg_cifar10
 │   ├── Expetator
-|   |   ├── config_instance*.json
+|   |   ├── config_instance_1.json
 │   ├── Expetator_<host_info>_<timestamp>_mojitos: mojitos outputs
 │   ├── Expetator_<host_info>_<timestamp>_power: wattmetter outputs
 │   ├── Expetator_<host_info>_<timestamp>: measurement log
@@ -243,7 +245,8 @@ Output dir structure:
 │   ├── Flwr_<timestamp>
 │   │   ├── Client_<ip>
 │   │   ├── Server_<ip>
-│── Flower_instance_<instance_name>
+│── Flower_instance_Flower_instance_fedAvg2Clients_cifar10
+...
 ```
 
 ### Step 6. Clean Up
diff --git a/Run/config_instances.json b/Run/config_instances.json
index b8bac0b..924bd9b 100644
--- a/Run/config_instances.json
+++ b/Run/config_instances.json
@@ -329,336 +329,6 @@
                 "ip": "172.16.66.79"
             }
             ]
-        },
-        "7": {
-            "instance": "fedProx_cifar10",
-            "output_dir": "./Log",
-            "dvfs_cpu": {
-                "dummy": true,
-                "baseline": false,
-                "frequencies": null
-            },
-            "server": {
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/server_1.py",
-                    "-r 1",
-                    "-s fedProx"
-                ],
-                "ip": "172.16.66.76",
-                "modules": ["logger"],
-                "port": 8080
-            },
-            "clients": [
-            {
-                "name": "client1",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar10",
-                    "0",
-                    "3"
-                ],
-                "ip": "172.16.66.77"
-            },
-            {
-                "name": "client2",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar10",
-                    "1",
-                    "3"
-                ],
-                "ip": "172.16.66.78"
-            },
-            {
-                "name": "client3",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar10",
-                    "2",
-                    "3"
-                ],
-                "ip": "172.16.66.79"
-            }
-            ]
-        },
-        "8": {
-            "instance": "fedProx_cifar100",
-            "output_dir": "./Log",
-            "dvfs_cpu": {
-                "dummy": true,
-                "baseline": false,
-                "frequencies": null
-            },
-            "server": {
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/server_1.py",
-                    "-r 1",
-                    "-s fedProx"
-                ],
-                "ip": "172.16.66.76",
-                "modules": ["logger"],
-                "port": 8080
-            },
-            "clients": [
-            {
-                "name": "client1",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar100",
-                    "0",
-                    "3"
-                ],
-                "ip": "172.16.66.77"
-            },
-            {
-                "name": "client2",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar100",
-                    "1",
-                    "3"
-                ],
-                "ip": "172.16.66.78"
-            },
-            {
-                "name": "client3",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar100",
-                    "2",
-                    "3"
-                ],
-                "ip": "172.16.66.79"
-            }
-            ]
-        },
-        "9": {
-            "instance": "fedProx_mnist",
-            "output_dir": "./Log",
-            "dvfs_cpu": {
-                "dummy": true,
-                "baseline": false,
-                "frequencies": null
-            },
-            "server": {
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/server_1.py",
-                    "-r 1",
-                    "-s fedProx"
-                ],
-                "ip": "172.16.66.76",
-                "modules": ["logger"],
-                "port": 8080
-            },
-            "clients": [
-            {
-                "name": "client1",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "mnist",
-                    "0",
-                    "3"
-                ],
-                "ip": "172.16.66.77"
-            },
-            {
-                "name": "client2",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "mnist",
-                    "1",
-                    "3"
-                ],
-                "ip": "172.16.66.78"
-            },
-            {
-                "name": "client3",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "mnist",
-                    "2",
-                    "3"
-                ],
-                "ip": "172.16.66.79"
-            }
-            ]
-        },
-        "10": {
-            "instance": "fedAdam_cifar10",
-            "output_dir": "./Log",
-            "dvfs_cpu": {
-                "dummy": true,
-                "baseline": false,
-                "frequencies": null
-            },
-            "server": {
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/server_1.py",
-                    "-r 1",
-                    "-s fedAdam"
-                ],
-                "ip": "172.16.66.76",
-                "modules": ["logger"],
-                "port": 8080
-            },
-            "clients": [
-            {
-                "name": "client1",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar10",
-                    "0",
-                    "3"
-                ],
-                "ip": "172.16.66.77"
-            },
-            {
-                "name": "client2",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar10",
-                    "1",
-                    "3"
-                ],
-                "ip": "172.16.66.78"
-            },
-            {
-                "name": "client3",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar10",
-                    "2",
-                    "3"
-                ],
-                "ip": "172.16.66.79"
-            }
-            ]
-        },
-        "11": {
-            "instance": "fedAdam_cifar100",
-            "output_dir": "./Log",
-            "dvfs_cpu": {
-                "dummy": true,
-                "baseline": false,
-                "frequencies": null
-            },
-            "server": {
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/server_1.py",
-                    "-r 1",
-                    "-s fedAdam"
-                ],
-                "ip": "172.16.66.76",
-                "modules": ["logger"],
-                "port": 8080
-            },
-            "clients": [
-            {
-                "name": "client1",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar100",
-                    "0",
-                    "3"
-                ],
-                "ip": "172.16.66.77"
-            },
-            {
-                "name": "client2",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar100",
-                    "1",
-                    "3"
-                ],
-                "ip": "172.16.66.78"
-            },
-            {
-                "name": "client3",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "cifar100",
-                    "2",
-                    "3"
-                ],
-                "ip": "172.16.66.79"
-            }
-            ]
-        },        
-        "12": {
-            "instance": "fedAdam_mnist",
-            "output_dir": "./Log",
-            "dvfs_cpu": {
-                "dummy": true,
-                "baseline": false,
-                "frequencies": null
-            },
-            "server": {
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/server_1.py",
-                    "-r 1",
-                    "-s fedAdam"
-                ],
-                "ip": "172.16.66.76",
-                "modules": ["logger"],
-                "port": 8080
-            },
-            "clients": [
-            {
-                "name": "client1",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "mnist",
-                    "0",
-                    "3"
-                ],
-                "ip": "172.16.66.77"
-            },
-            {
-                "name": "client2",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "mnist",
-                    "1",
-                    "3"
-                ],
-                "ip": "172.16.66.78"
-            },
-            {
-                "name": "client3",
-                "command": "python3",
-                "args": [
-                    "./Flower_v1/client_1.py",
-                    "mnist",
-                    "2",
-                    "3"
-                ],
-                "ip": "172.16.66.79"
-            }
-            ]
         }
     }
-}
+}
\ No newline at end of file
diff --git a/Run/config_instances_CPU.json b/Run/config_instances_CPU.json
new file mode 100644
index 0000000..86c1b1a
--- /dev/null
+++ b/Run/config_instances_CPU.json
@@ -0,0 +1,114 @@
+{
+    "instances": {
+        "1": {
+            "instance": "fedAvg_cifar10",
+            "output_dir": "./Log",
+            "dvfs_cpu": {
+                "dummy": true,
+                "baseline": false,
+                "frequencies": null
+            },
+            "server": {
+                "command": "python3",
+                "args": [
+                    "./Flower_v1/server_1.py",
+                    "-r 1",
+                    "-s fedAvg"
+                ],
+                "ip": "172.16.66.76",
+                "modules": ["logger"],
+                "port": 8080
+                },
+            "clients": [
+            {
+                "name": "client1",
+                "command": "python3",
+                "args": [
+                    "./Flower_v1/client_1.py",
+                    "cifar10",
+                    "0",
+                    "3"
+                ],
+                "ip": "172.16.66.77"
+            },
+            {
+                "name": "client2",
+                "command": "python3",
+                "args": [
+                    "./Flower_v1/client_1.py",
+                    "cifar10",
+                    "1",
+                    "3"
+                ],
+                "ip": "172.16.66.78"
+            },
+            {
+                "name": "client3",
+                "command": "python3",
+                "args": [
+                    "./Flower_v1/client_1.py",
+                    "cifar10",
+                    "2",
+                    "3"
+                ],
+                "ip": "172.16.66.79"
+            }
+            ]
+        },
+        "2": {
+            "instance": "fedAvg2Clients_cifar10",
+            "output_dir": "./Log",
+            "dvfs_cpu": {
+                "dummy": true,
+                "baseline": false,
+                "frequencies": null
+            },
+            "server": {
+                "command": "python3",
+                "args": [
+                    "./Flower_v1/server_1.py",
+                    "-r 1",
+                    "-s fedAvg2Clients"
+                ],
+                "ip": "172.16.66.76",
+                "modules": ["logger"],
+                "port": 8080
+            },
+            "clients": [
+            {
+                "name": "client1",
+                "command": "python3",
+                "args": [
+                    "./Flower_v1/client_1.py",
+                    "cifar10",
+                    "0",
+                    "3"
+                ],
+                "ip": "172.16.66.77"
+            },
+            {
+                "name": "client2",
+                "command": "python3",
+                "args": [
+                    "./Flower_v1/client_1.py",
+                    "cifar10",
+                    "1",
+                    "3"
+                ],
+                "ip": "172.16.66.78"
+            },
+            {
+                "name": "client3",
+                "command": "python3",
+                "args": [
+                    "./Flower_v1/client_1.py",
+                    "cifar10",
+                    "2",
+                    "3"
+                ],
+                "ip": "172.16.66.79"
+            }
+            ]
+        }
+    }
+}
\ No newline at end of file
diff --git a/Run/config_instances_1.json b/Run/config_instances_GPU.json
similarity index 100%
rename from Run/config_instances_1.json
rename to Run/config_instances_GPU.json
diff --git a/Run/measure_campaign.py b/Run/measure_campaign.py
index 773d631..0df6269 100644
--- a/Run/measure_campaign.py
+++ b/Run/measure_campaign.py
@@ -22,7 +22,7 @@ def main():
     args = parser.parse_args()
 
     # Path to the combined config.json file
-    config_path = parser.config
+    config_path = args.config
 
     # Read the config.json file
     try:
diff --git a/Run/measure_instance.py b/Run/measure_instance.py
index d1cf3b2..73b2a7f 100644
--- a/Run/measure_instance.py
+++ b/Run/measure_instance.py
@@ -5,7 +5,7 @@ import argparse
 import json
 import time
 import expetator.experiment as experiment
-from expetator.monitors import Mojitos
+from expetator.monitors import Mojitos, kwollect
 from expetator.leverages import Dvfs, GpuClock
 #import run_flwr as run_flwr
 
@@ -99,6 +99,7 @@ if __name__ == "__main__":
         flower_log_dir, 
         [DemoBench()],
         leverages= LEVERAGES,
-        monitors=[Mojitos(sensor_set={'user', 'rxp', 'dram0'})],
+        monitors=[Mojitos(sensor_set={'user', 'rxp', 'dram0'}),
+        kwollect.Power(metric=kwollect.get_g5k_target_metric())],
         times=args.repeat
     )
\ No newline at end of file
-- 
GitLab