Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
IcyFeather233 authored Oct 30, 2024
2 parents 179d39d + 9553051 commit fa4d8c6
Show file tree
Hide file tree
Showing 270 changed files with 40,278 additions and 184 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/main-doc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI

on:
push:
branches:
- main
tags:
paths:
- '**.md'
pull_request:

jobs:
pylint:
runs-on: ubuntu-20.04
name: pylint
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9" ]
steps:
- run: 'echo "only docs modified, no need to trigger CI"'
12 changes: 10 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
- main
tags:
pull_request:
paths-ignore:
- '**.md'

jobs:
pylint:
Expand All @@ -24,10 +26,16 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install libgl1-mesa-glx -y
python -m pip install --upgrade pip
python -m pip install pip==24.0
python -m pip install pylint
python -m pip install ${{github.workspace}}/examples/resources/third_party/*
python -m pip install -r ${{github.workspace}}/requirements.txt
- name: Analysing code of core with pylint
# `--max-positional-arguments=10` is set for Python 3.9 to avoid `R0917: too-many-positional-arguments`.
# See details at https://github.com/kubeedge/ianvs/issues/157
run: |
pylint '${{github.workspace}}/core'
if [ "${{ matrix.python-version }}" = "3.9" ]; then
pylint --max-positional-arguments=10 '${{github.workspace}}/core'
else
pylint '${{github.workspace}}/core'
fi
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
dataset/
initial_model/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -134,4 +136,10 @@ dmypy.json

# generated files by MacOS
.DS_Store
*/.DS_Store
*/.DS_Store

# pycharm
.idea
.idea/misc.xml
.idea/workspace.xml
.idea/vcs.xml
4 changes: 1 addition & 3 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# KubeEdge Community Code of Conduct

KubeEdge follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected].
Please refer to our [KubeEdge Community Code of Conduct](https://github.com/kubeedge/community/blob/master/CODE_OF_CONDUCT.md).
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ianvs

[![CI](https://github.com/kubeedge/ianvs/workflows/CI/badge.svg?branch=main)](https://github.com/sedna/ianvs/actions)
[![CI](https://github.com/kubeedge/ianvs/actions/workflows/main-doc.yaml/badge.svg?branch=main)](https://github.com/kubeedge/ianvs/actions/workflows/main-doc.yaml)
[![LICENSE SCAN](https://app.fossa.com/api/projects/custom%2B32178%2Fgithub.com%2Fkubeedge%2Fianvs.svg?type=shield)](https://app.fossa.com/projects/custom%2B32178%2Fgithub.com%2Fkubeedge%2Fianvs?ref=badge_shield)
[![LICENSE](https://img.shields.io/github/license/kubeedge-sedna/ianvs.svg)](/LICENSE)

Expand Down Expand Up @@ -117,7 +117,7 @@ If you need support, start with the [troubleshooting guide](./docs/troubleshooti

If you have questions, feel free to reach out to us in the following ways:

- [slack channel](https://app.slack.com/client/TDZ5TGXQW/C01EG84REVB/details)
- [slack channel](https://kubeedge.io/docs/community/slack/)

## Contributing

Expand Down
1 change: 1 addition & 0 deletions core/cmd/obj/benchmarkingjob.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=R0801
# Copyright 2022 The KubeEdge Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
11 changes: 11 additions & 0 deletions core/common/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DatasetFormat(Enum):
File format of inputting dataset.
Currently, file formats are as follows: txt, csv.
"""

CSV = "csv"
TXT = "txt"
JSON = "json"
Expand All @@ -32,16 +33,20 @@ class ParadigmType(Enum):
"""
Algorithm paradigm type.
"""

SINGLE_TASK_LEARNING = "singletasklearning"
INCREMENTAL_LEARNING = "incrementallearning"
MULTIEDGE_INFERENCE = "multiedgeinference"
LIFELONG_LEARNING = "lifelonglearning"
FEDERATED_LEARNING = "federatedlearning"
FEDERATED_CLASS_INCREMENTAL_LEARNING = "federatedclassincrementallearning"


class ModuleType(Enum):
"""
Algorithm module type.
"""

BASEMODEL = "basemodel"

# HEM
Expand All @@ -64,20 +69,26 @@ class ModuleType(Enum):
UNSEEN_SAMPLE_RECOGNITION = "unseen_sample_recognition"
UNSEEN_SAMPLE_RE_RECOGNITION = "unseen_sample_re_recognition"

# FL_AGG
AGGREGATION = "aggregation"


class SystemMetricType(Enum):
"""
System metric type of ianvs.
"""

SAMPLES_TRANSFER_RATIO = "samples_transfer_ratio"
FWT = "FWT"
BWT = "BWT"
TASK_AVG_ACC = "task_avg_acc"
MATRIX = "MATRIX"
FORGET_RATE = "forget_rate"


class TestObjectType(Enum):
"""
Test object type of ianvs.
"""

ALGORITHMS = "algorithms"
117 changes: 71 additions & 46 deletions core/storymanager/rank/rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@ class Rank:

def __init__(self, config):
self.sort_by: list = []
self.visualization: dict = {
"mode": "selected_only",
"method": "print_table"
}
self.visualization: dict = {"mode": "selected_only", "method": "print_table"}
self.selected_dataitem: dict = {
"paradigms": ["all"],
"modules": ["all"],
"hyperparameters": ["all"],
"metrics": ["all"]
"metrics": ["all"],
}
self.save_mode: str = "selected_and_all"

Expand All @@ -62,15 +59,21 @@ def _parse_config(self, config):

def _check_fields(self):
if not self.sort_by and not isinstance(self.sort_by, list):
raise ValueError(f"rank's sort_by({self.sort_by}) must be provided and be list type.")
raise ValueError(
f"rank's sort_by({self.sort_by}) must be provided and be list type."
)

if not self.visualization and not isinstance(self.visualization, dict):
raise ValueError(f"rank's visualization({self.visualization}) "
f"must be provided and be dict type.")
raise ValueError(
f"rank's visualization({self.visualization}) "
f"must be provided and be dict type."
)

if not self.selected_dataitem and not isinstance(self.selected_dataitem, dict):
raise ValueError(f"rank's selected_dataitem({self.selected_dataitem}) "
f"must be provided and be dict type.")
raise ValueError(
f"rank's selected_dataitem({self.selected_dataitem}) "
f"must be provided and be dict type."
)

if not self.selected_dataitem.get("paradigms"):
raise ValueError("not found paradigms of selected_dataitem in rank.")
Expand All @@ -82,8 +85,10 @@ def _check_fields(self):
raise ValueError("not found metrics of selected_dataitem in rank.")

if not self.save_mode and not isinstance(self.save_mode, list):
raise ValueError(f"rank's save_mode({self.save_mode}) "
f"must be provided and be list type.")
raise ValueError(
f"rank's save_mode({self.save_mode}) "
f"must be provided and be list type."
)

@classmethod
def _get_all_metric_names(cls, test_results) -> list:
Expand Down Expand Up @@ -133,50 +138,57 @@ def _sort_all_df(self, all_df, all_metric_names):

if metric_name not in all_metric_names:
continue

print(metric_name)
sort_metric_list.append(metric_name)
is_ascend_list.append(ele.get(metric_name) == "ascend")

return all_df.sort_values(by=sort_metric_list, ascending=is_ascend_list)

def _get_all(self, test_cases, test_results) -> pd.DataFrame:
all_df = pd.DataFrame(columns=self.all_df_header)

for i, test_case in enumerate(test_cases):
all_df.loc[i] = [np.NAN for i in range(len(self.all_df_header))]
# fill name column of algorithm
algorithm = test_case.algorithm
all_df.loc[i][0] = algorithm.name
# fill metric columns of algorithm
for metric_name in test_results[test_case.id][0]:
all_df.loc[i][metric_name] = test_results[test_case.id][0].get(metric_name)
test_result = test_results[test_case.id][0]

# file paradigm column of algorithm
all_df.loc[i]["paradigm"] = algorithm.paradigm_type
# add algorithm, paradigm, time, url of algorithm
row_data = {
"algorithm": algorithm.name,
"paradigm": algorithm.paradigm_type,
"time": test_results[test_case.id][1],
"url": test_case.output_dir
}

# fill module columns of algorithm
for module_type, module in algorithm.modules.items():
all_df.loc[i][module_type] = module.name
# add metric of algorithm
row_data.update(test_result)

# fill hyperparameters columns of algorithm modules
hps = self._get_algorithm_hyperparameters(algorithm)
# add module of algorithm
row_data.update({
module_type: module.name
for module_type, module in algorithm.modules.items()
})

# pylint: disable=C0103
for k, v in hps.items():
all_df.loc[i][k] = v
# fill time and output dir of testcase
all_df.loc[i][-2:] = [test_results[test_case.id][1], test_case.output_dir]
# add hyperparameters of algorithm modules
row_data.update(self._get_algorithm_hyperparameters(algorithm))

if utils.is_local_file(self.all_rank_file):
old_df = pd.read_csv(self.all_rank_file, delim_whitespace=True, index_col=0)
all_df = all_df.append(old_df)
# fill data
all_df.loc[i] = row_data

new_df = self._concat_existing_data(all_df)

return self._sort_all_df(all_df, self._get_all_metric_names(test_results))
return self._sort_all_df(new_df, self._get_all_metric_names(test_results))

def _concat_existing_data(self, new_df):
if utils.is_local_file(self.all_rank_file):
old_df = pd.read_csv(self.all_rank_file, index_col=0)
new_df = pd.concat([old_df, new_df])
return new_df

def _save_all(self):
# pylint: disable=E1101
all_df = copy.deepcopy(self.all_df)
all_df.index = pd.np.arange(1, len(all_df) + 1)
all_df.to_csv(self.all_rank_file, index_label="rank", encoding="utf-8", sep=" ")
all_df.index = np.arange(1, len(all_df) + 1)
all_df.to_csv(self.all_rank_file, index_label="rank", encoding="utf-8")

def _get_selected(self, test_cases, test_results) -> pd.DataFrame:
module_types = self.selected_dataitem.get("modules")
Expand All @@ -191,7 +203,15 @@ def _get_selected(self, test_cases, test_results) -> pd.DataFrame:
if metric_names == ["all"]:
metric_names = self._get_all_metric_names(test_results)

header = ["algorithm", *metric_names, "paradigm", *module_types, *hps_names, "time", "url"]
header = [
"algorithm",
*metric_names,
"paradigm",
*module_types,
*hps_names,
"time",
"url",
]

all_df = copy.deepcopy(self.all_df)
selected_df = pd.DataFrame(all_df, columns=header)
Expand All @@ -205,25 +225,30 @@ def _get_selected(self, test_cases, test_results) -> pd.DataFrame:
def _save_selected(self, test_cases, test_results):
# pylint: disable=E1101
selected_df = self._get_selected(test_cases, test_results)
selected_df.index = pd.np.arange(1, len(selected_df) + 1)
selected_df.to_csv(self.selected_rank_file, index_label="rank", encoding="utf-8", sep=" ")
selected_df.index = np.arange(1, len(selected_df) + 1)
selected_df.to_csv(self.selected_rank_file, index_label="rank", encoding="utf-8")

def _draw_pictures(self, test_cases, test_results):
# pylint: disable=E1101
for test_case in test_cases:
out_put = test_case.output_dir
test_result = test_results[test_case.id][0]
matrix = test_result.get('Matrix')
#print(out_put)
matrix = test_result.get("Matrix")
# print(out_put)
for key in matrix.keys():
draw_heatmap_picture(out_put, key, matrix[key])

def _prepare(self, test_cases, test_results, output_dir):
all_metric_names = self._get_all_metric_names(test_results)
print(f"in_prepare all_metric_names: {all_metric_names}")
all_hps_names = self._get_all_hps_names(test_cases)
print(f"in_prepare all_hps_names: {all_hps_names}")
all_module_types = self._get_all_module_types(test_cases)
self.all_df_header = ["algorithm", *all_metric_names, "paradigm",
*all_module_types, *all_hps_names, "time", "url"]
self.all_df_header = [
"algorithm", *all_metric_names,
"paradigm", *all_module_types,
*all_hps_names, "time", "url"
]

rank_output_dir = os.path.join(output_dir, "rank")
if not utils.is_local_dir(rank_output_dir):
Expand All @@ -246,7 +271,6 @@ def save(self, test_cases, test_results, output_dir):
output_dir: string
"""

self._prepare(test_cases, test_results, output_dir)

if self.save_mode == "selected_and_all":
Expand Down Expand Up @@ -276,4 +300,5 @@ def plot(self):
except Exception as err:
raise RuntimeError(
f"process visualization(method={method}) of "
f"rank file({self.selected_rank_file}) failed, error: {err}.") from err
f"rank file({self.selected_rank_file}) failed, error: {err}."
) from err
Loading

0 comments on commit fa4d8c6

Please sign in to comment.