Skip to content

Commit

Permalink
Review comments incor
Browse files Browse the repository at this point in the history
Signed-off-by: noopur <[email protected]>
  • Loading branch information
noopurintel committed Jan 15, 2025
1 parent d1f42e8 commit 024220c
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 52 deletions.
30 changes: 7 additions & 23 deletions .github/workflows/federated_runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ jobs:
with:
python-version: "3.10"

- name: Install Jupyter Lab Package
run: pip install jupyterlab

- name: Install dependencies # Without this step, fx command will not work
id: install_dependencies
run: |
python -m pip install --upgrade pip
pip install .
- name: Install Jupyter Lab Package
run: pip install jupyterlab

- name: Create results folder for logs
run: | # Present working director - /home/runner/work/openfl/openfl
mkdir -p /home/runner/results
Expand All @@ -66,26 +66,10 @@ jobs:
- name: Check if envoys are connected to the director
run: |
cd openfl-tutorials/experimental/workflow/FederatedRuntime/301_MNIST_Watermarking
timeout=60
connected=false
while [ $timeout -gt 0 ]; do
if grep "Bangalore is connected to the director" ~/results/bangalore.log && grep "Chandler is connected to the director" ~/results/chandler.log; then
connected=true
break
else
echo "Waiting for both envoys to connect to the director"
fi
sleep 5
timeout=$((timeout-5))
done
if [ $connected = false ]; then
echo "Envoys are not connected to the director in 60 seconds"
echo "| Failure Reason |" >> $GITHUB_STEP_SUMMARY
echo "| -------------- |" >> $GITHUB_STEP_SUMMARY
echo "Envoys are not connected to the director in 60 seconds" >> $GITHUB_STEP_SUMMARY
exit 1
fi
python_path="tests/end_to_end/utils/github_helper.py"
python3 $python_path --func_name "verify_envoys_director_conn_federated_runtime" \
--notebook_path "openfl-tutorials/experimental/workflow/FederatedRuntime/301_MNIST_Watermarking/workspace/MNIST_Watermarking.ipynb" \
--expected_envoys "['Bangalore', 'Chandler']"
- name: Run Notebook
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "d79eacbd",
"metadata": {},
"outputs": [],
"source": [
"#| default_exp experiment"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aab0576a",
"metadata": {},
"outputs": [],
"source": [
"# Below code is to display the output of the code in the notebook during GitHub workflow run\n",
"# Comment it out if you are running the code in your local environment/Google Colab\n",
"import sys\n",
"sys.stdout = open('/dev/stdout', 'w')"
]
},
{
"cell_type": "markdown",
"id": "62449b5f",
Expand All @@ -79,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "f7475cba",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -108,7 +95,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "9bd8ac2d",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -206,7 +193,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "89cf4866",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -238,7 +225,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "52c4a752",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -284,7 +271,6 @@
" )\n",
" self.round_number = round_number\n",
" self.n_rounds = n_rounds\n",
" self.current_round = 1\n",
" self.watermark_pretraining_completed = False\n",
"\n",
" @aggregator\n",
Expand Down Expand Up @@ -446,12 +432,12 @@
" \"\"\"\n",
" Internal loop to continue the Federated Learning process.\n",
" \"\"\"\n",
" if self.current_round == self.n_rounds:\n",
" print(f\"\\nCompleted training for all {self.n_rounds} round(s)\\n\")\n",
" if self.round_number == self.n_rounds - 1:\n",
" print(f\"\\nCompleted training for all {self.n_rounds} round(s)\")\n",
" self.next(self.end)\n",
" else:\n",
" print(f\"\\nCompleted round: {self.current_round}\\n\")\n",
" self.current_round += 1\n",
" self.round_number += 1\n",
" print(f\"\\nCompleted round: {self.round_number}\")\n",
" self.next(self.aggregated_model_validation, foreach='collaborators')\n",
"\n",
" @aggregator\n",
Expand All @@ -476,7 +462,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "1715a373",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -509,7 +495,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "1f1be87f",
"metadata": {},
"outputs": [],
Expand All @@ -527,7 +513,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "c6d19819",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -579,7 +565,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "fed_run",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -593,7 +579,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.15"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
10 changes: 9 additions & 1 deletion openfl/experimental/workflow/runtime/federated_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ def get_flow_state(self) -> Tuple[bool, Any]:
return status, flow_object

def get_envoys(self) -> None:
"""Prints the status of Envoys in a formatted way."""
"""
Prints the status of Envoys in a formatted way.
Also returns the list of online envoys.
"""
# Fetch envoy data
envoys = self._dir_client.get_envoys()
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
Expand All @@ -204,6 +207,7 @@ def get_envoys(self) -> None:
headers = ["Name", "Online", "Last Updated", "Experiment Running", "Experiment Name"]
# Prepare the table rows
rows = []
online_envoys = []
for envoy in envoys.envoy_infos:
rows.append(
[
Expand All @@ -214,11 +218,15 @@ def get_envoys(self) -> None:
envoy.experiment_name if envoy.experiment_name else "None",
]
)
if envoy.is_online:
online_envoys.append(envoy.envoy_name)

# Use tabulate to format the table
result = tabulate(rows, headers=headers, tablefmt="grid")
# Display the current timestamp
print(f"Status of Envoys connected to Federation at: {now}\n")
print(result)
return online_envoys

def stream_experiment_stdout(self, experiment_name) -> None:
"""Stream experiment stdout.
Expand Down
77 changes: 77 additions & 0 deletions tests/end_to_end/utils/github_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2020-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import argparse
import ast
import logging

log = logging.getLogger(__name__)


def fetch_args():
"""
Function to fetch the commandline arguments.
Returns:
Parsed arguments
"""
# Initialize the parser and add arguments
parser = argparse.ArgumentParser()
parser.add_argument(
"--func_name", required=True, default="", type=str, help="Name of function to be called"
)
# All the arguments except for func_name are optional and have default values.
parser.add_argument(
"--notebook_path", required=False, default="", type=str, help="Path to the notebook including name"
)
parser.add_argument(
"--expected_envoys", required=False, default="", type=str, help="List of expected envoy names. For e.g. ['Bangalore', 'Chandler']"
)
parser.add_argument(
"--director_node_fqdn", required=False, default="localhost", type=str, help="Director node FQDN"
)
parser.add_argument(
"--director_port", required=False, default=50050, type=int, help="Director port number"
)
args = parser.parse_args()
return args


def verify_envoys_director_conn_federated_runtime(notebook_path, expected_envoys, director_node_fqdn="localhost", director_port=50050):
"""
Function to get the envoys specifically for the Federated Runtime notebooks
Args:
notebook_path (str): Path to the notebook including name
expected_envoys (list): List of expected envoy names
director_node_fqdn (str): Director node FQDN (default is localhost)
director_port (int): Director port number (default is 50050)
"""
from openfl.experimental.workflow.runtime import FederatedRuntime

log.debug(f"Notebook path: {notebook_path}")
expected_envoys = ast.literal_eval(expected_envoys)
log.debug(f"Expected envoys: {expected_envoys}")

director_info = {
'director_node_fqdn': director_node_fqdn,
'director_port': director_port,
}

federated_runtime = FederatedRuntime(
collaborators=expected_envoys,
director=director_info,
notebook_path=notebook_path
)
actual_envoys = federated_runtime.get_envoys()
if all(sorted(expected_envoys) == sorted(actual_envoys) for expected_envoys, actual_envoys in [(expected_envoys, actual_envoys)]):
log.info("All the envoys are connected to the director")
return True
else:
raise Exception("Not all envoys are connected to the director")


if __name__ == "__main__":
# Fetch input arguments
args = fetch_args()
func_name = args.func_name

if func_name == "verify_envoys_director_conn_federated_runtime":
verify_envoys_director_conn_federated_runtime(args.notebook_path, args.expected_envoys, args.director_node_fqdn, args.director_port)

0 comments on commit 024220c

Please sign in to comment.