Skip to content

Commit 628db50

Browse files
author
Sunil Thaha
authored
Merge pull request #431 from vprashar2929/add-hatch-fmt
feat(ci): Integrate hatch fmt for code formatting
2 parents 869fa1a + 6736f27 commit 628db50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+698
-216
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ In addition to approval, the author must confirm the following check list:
77
- [ ] Run the following command to format your code:
88

99
```bash
10-
hatch fmt
10+
make fmt
1111
```
1212

1313
- [ ] Create issues for unresolved comments and link them to this PR. Use one of the following labels:

.github/workflows/lint.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ jobs:
2828
shell: bash
2929
run: |
3030
make lint
31+
32+
# run hatch fmt
33+
- name: Run formatter using hatch
34+
shell: bash
35+
run: |
36+
make fmt
37+
git diff --exit-code

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ PYTHON := python3.10
1515
DOCKERFILES_PATH := ./dockerfiles
1616
MODEL_PATH := ${PWD}/tests/models
1717

18+
.PHONY: fmt
19+
fmt:
20+
@hatch fmt -f
21+
1822
.PHONY: lint
1923
lint:
2024
@hatch run pymarkdownlnt scan -r .

model_training/s3/src/s3/loader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def aws_download(client, bucket_name, machine_id, mnt_path, pipeline_name):
5858

5959
def ibm_download(client, bucket_name, machine_id, mnt_path, pipeline_name):
6060
print("IBM Download")
61-
bucket_file_map = get_bucket_file_map(client, bucket_name, machine_id=machine_id, mnt_path=mnt_path, pipeline_name=pipeline_name, list_func=ibmcloud_list_keys)
61+
bucket_file_map = get_bucket_file_map(
62+
client, bucket_name, machine_id=machine_id, mnt_path=mnt_path, pipeline_name=pipeline_name, list_func=ibmcloud_list_keys
63+
)
6264
for key, filepath in bucket_file_map.items():
6365
print(key, filepath)
6466
dir = os.path.dirname(filepath)

model_training/s3/src/s3/util.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ def new_ibm_client(args):
77
import ibm_boto3
88
from ibm_botocore.client import Config
99

10-
cos = ibm_boto3.resource("s3", ibm_api_key_id=args.api_key, ibm_service_instance_id=args.service_instance_id, config=Config(signature_version="oauth"), endpoint_url=args.service_endpoint)
10+
cos = ibm_boto3.resource(
11+
"s3",
12+
ibm_api_key_id=args.api_key,
13+
ibm_service_instance_id=args.service_instance_id,
14+
config=Config(signature_version="oauth"),
15+
endpoint_url=args.service_endpoint,
16+
)
1117
return cos
1218

1319

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ exclude_lines = [
111111
]
112112

113113
[tool.ruff]
114-
line-length = 320
114+
line-length = 160
115115

116116
[tool.pytest.ini_options]
117117
markers = [

src/kepler_model/cmd/cmd_plot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ def metadata_plot(args, energy_source, metadata_df, output_folder, name):
140140
ax = axes
141141
else:
142142
ax = axes[i]
143-
sns.barplot(data=metadata_df, x="feature_group", y="mae", hue="trainer", ax=ax, hue_order=sorted(metadata_df["trainer"].unique()), errorbar=None, palette="Set3")
143+
sns.barplot(
144+
data=metadata_df, x="feature_group", y="mae", hue="trainer", ax=ax, hue_order=sorted(metadata_df["trainer"].unique()), errorbar=None, palette="Set3"
145+
)
144146
ax.set_title(component)
145147
ax.set_ylabel("MAE (Watt)")
146148
ax.set_xlabel("Feature Group")
@@ -166,7 +168,9 @@ def power_curve_plot(args, data_path, energy_source, output_folder, name):
166168
node_collection = NodeTypeIndexCollection(pipeline_path)
167169
all_node_types = sorted(list(node_collection.node_type_index.keys()))
168170
output_type = ModelOutputType[args.output_type]
169-
models, _, cpu_ms_max = _load_all_models(model_toppath=model_toppath, output_type=output_type, name=pipeline_name, node_types=all_node_types, energy_source=energy_source)
171+
models, _, cpu_ms_max = _load_all_models(
172+
model_toppath=model_toppath, output_type=output_type, name=pipeline_name, node_types=all_node_types, energy_source=energy_source
173+
)
170174
if len(models) > 0:
171175
_plot_models(models, cpu_ms_max, energy_source, output_folder, name)
172176

src/kepler_model/cmd/cmd_util.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ def get_isolator(data_path, isolator, profile, pipeline_name, target_hints, bg_h
316316
profile_isolator = ProfileBackgroundIsolator(profiles, idle_data)
317317
supported_isolator[profile_isolator.get_name()] = profile_isolator
318318
if abs_pipeline_name != "":
319-
trainer_isolator = TrainIsolator(idle_data=idle_data, profiler=DefaultProfiler, target_hints=target_hints, bg_hints=bg_hints, abs_pipeline_name=abs_pipeline_name)
319+
trainer_isolator = TrainIsolator(
320+
idle_data=idle_data, profiler=DefaultProfiler, target_hints=target_hints, bg_hints=bg_hints, abs_pipeline_name=abs_pipeline_name
321+
)
320322
supported_isolator[trainer_isolator.get_name()] = trainer_isolator
321323
elif abs_pipeline_name != "":
322324
trainer_isolator = TrainIsolator(target_hints=target_hints, bg_hints=bg_hints, abs_pipeline_name=abs_pipeline_name)
@@ -338,10 +340,32 @@ def get_extractor(extractor):
338340
return supported_extractor[extractor]
339341

340342

341-
def get_pipeline(data_path, pipeline_name, extractor, profile, target_hints, bg_hints, abs_pipeline_name, isolator, abs_trainer_names, dyn_trainer_names, energy_sources, valid_feature_groups, replace_node_type=default_node_type):
343+
def get_pipeline(
344+
data_path,
345+
pipeline_name,
346+
extractor,
347+
profile,
348+
target_hints,
349+
bg_hints,
350+
abs_pipeline_name,
351+
isolator,
352+
abs_trainer_names,
353+
dyn_trainer_names,
354+
energy_sources,
355+
valid_feature_groups,
356+
replace_node_type=default_node_type,
357+
):
342358
from kepler_model.train import NewPipeline
343359

344360
isolator = get_isolator(data_path, isolator, profile, pipeline_name, target_hints, bg_hints, abs_pipeline_name, replace_node_type=replace_node_type)
345361
extractor = get_extractor(extractor)
346-
pipeline = NewPipeline(pipeline_name, abs_trainer_names, dyn_trainer_names, extractor=extractor, isolator=isolator, target_energy_sources=energy_sources, valid_feature_groups=valid_feature_groups)
362+
pipeline = NewPipeline(
363+
pipeline_name,
364+
abs_trainer_names,
365+
dyn_trainer_names,
366+
extractor=extractor,
367+
isolator=isolator,
368+
target_energy_sources=energy_sources,
369+
valid_feature_groups=valid_feature_groups,
370+
)
347371
return pipeline

src/kepler_model/cmd/main.py

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,20 @@ def train(args):
458458
pipeline = None
459459
if args.id:
460460
machine_id = args.id
461-
pipeline = get_pipeline(data_path, pipeline_name, args.extractor, args.profile, args.target_hints, args.bg_hints, args.abs_pipeline_name, args.isolator, abs_trainer_names, dyn_trainer_names, energy_sources, valid_feature_groups)
461+
pipeline = get_pipeline(
462+
data_path,
463+
pipeline_name,
464+
args.extractor,
465+
args.profile,
466+
args.target_hints,
467+
args.bg_hints,
468+
args.abs_pipeline_name,
469+
args.isolator,
470+
abs_trainer_names,
471+
dyn_trainer_names,
472+
energy_sources,
473+
valid_feature_groups,
474+
)
462475
machine_spec_json = load_machine_spec(data_path, machine_id)
463476
if machine_spec_json is not None:
464477
new_spec = NodeTypeSpec()
@@ -475,7 +488,9 @@ def train(args):
475488
for energy_source in energy_sources:
476489
energy_components = PowerSourceMap[energy_source]
477490
for feature_group in valid_feature_groups:
478-
success, abs_data, dyn_data = pipeline.process_multiple_query(input_query_results_list, energy_components, energy_source, feature_group=feature_group.name, replace_node_type=node_type)
491+
success, abs_data, dyn_data = pipeline.process_multiple_query(
492+
input_query_results_list, energy_components, energy_source, feature_group=feature_group.name, replace_node_type=node_type
493+
)
479494
assert success, f"failed to process pipeline {pipeline.name}"
480495
for trainer in pipeline.trainers:
481496
if trainer.feature_group == feature_group and trainer.energy_source == energy_source:
@@ -488,7 +503,11 @@ def train(args):
488503
if abs_data is not None:
489504
save_csv(data_saved_path, get_general_filename("preprocess", energy_source, feature_group, ModelOutputType.AbsPower, args.extractor), abs_data)
490505
if dyn_data is not None:
491-
save_csv(data_saved_path, get_general_filename("preprocess", energy_source, feature_group, ModelOutputType.DynPower, args.extractor, args.isolator), dyn_data)
506+
save_csv(
507+
data_saved_path,
508+
get_general_filename("preprocess", energy_source, feature_group, ModelOutputType.DynPower, args.extractor, args.isolator),
509+
dyn_data,
510+
)
492511

493512
print(f"=========== Train {energy_source} Summary ============")
494513
# save args
@@ -580,7 +599,20 @@ def estimate(args):
580599
if pipeline_metadata is None:
581600
print(f"no metadata for pipeline {pipeline_name}.")
582601
continue
583-
pipeline = get_pipeline(data_path, pipeline_name, pipeline_metadata["extractor"], args.profile, args.target_hints, args.bg_hints, args.abs_pipeline_name, pipeline_metadata["isolator"], pipeline_metadata["abs_trainers"], pipeline_metadata["dyn_trainers"], energy_sources, valid_fg)
602+
pipeline = get_pipeline(
603+
data_path,
604+
pipeline_name,
605+
pipeline_metadata["extractor"],
606+
args.profile,
607+
args.target_hints,
608+
args.bg_hints,
609+
args.abs_pipeline_name,
610+
pipeline_metadata["isolator"],
611+
pipeline_metadata["abs_trainers"],
612+
pipeline_metadata["dyn_trainers"],
613+
energy_sources,
614+
valid_fg,
615+
)
584616
if pipeline is None:
585617
print(f"cannot get pipeline {pipeline_name}.")
586618
continue
@@ -742,7 +774,16 @@ def plot(args):
742774
predicted_power_cols += [predicted_power_colname]
743775
data_filename = get_general_filename(args.target_data, energy_source, fg, ot, args.extractor, args.isolator)
744776
# plot prediction
745-
ts_plot(data, cols, f"{energy_source} {ot.name} Prediction Result \n by {model_id}", output_folder, f"{data_filename}_{model_id}", subtitles=subtitles, labels=plot_labels, ylabel="Power (W)")
777+
ts_plot(
778+
data,
779+
cols,
780+
f"{energy_source} {ot.name} Prediction Result \n by {model_id}",
781+
output_folder,
782+
f"{data_filename}_{model_id}",
783+
subtitles=subtitles,
784+
labels=plot_labels,
785+
ylabel="Power (W)",
786+
)
746787
# plot correlation to utilization if feature group is set
747788
if fg is not None:
748789
feature_cols = FeatureGroups[fg]
@@ -751,7 +792,17 @@ def plot(args):
751792
# plot raw feature data to confirm min-max value
752793
ts_plot(data, feature_cols, f"Features {fg}", output_folder, f"{data_filename}_{fg}", labels=None, subtitles=None, ylabel=None)
753794
data[feature_cols] = scaler.fit_transform(data[feature_cols])
754-
feature_power_plot(data, model_id, ot.name, energy_source, feature_cols, actual_power_cols, predicted_power_cols, output_folder, f"{data_filename}_{model_id}_corr")
795+
feature_power_plot(
796+
data,
797+
model_id,
798+
ot.name,
799+
energy_source,
800+
feature_cols,
801+
actual_power_cols,
802+
predicted_power_cols,
803+
output_folder,
804+
f"{data_filename}_{model_id}_corr",
805+
)
755806

756807
elif args.target_data == "error":
757808
from sklearn.preprocessing import MaxAbsScaler
@@ -964,7 +1015,9 @@ def run():
9641015
parser.add_argument("-e", "--energy-source", type=str, help="Specify energy source.", default="rapl-sysfs")
9651016
parser.add_argument("--abs-trainers", type=str, help="Specify trainer names for train command (use comma(,) as delimiter).", default="default")
9661017
parser.add_argument("--dyn-trainers", type=str, help="Specify trainer names for train command (use comma(,) as delimiter).", default="default")
967-
parser.add_argument("--trainers", type=str, help="Specify trainer names for train_from_data command (use comma(,) as delimiter).", default="XgboostFitTrainer")
1018+
parser.add_argument(
1019+
"--trainers", type=str, help="Specify trainer names for train_from_data command (use comma(,) as delimiter).", default="XgboostFitTrainer"
1020+
)
9681021

9691022
# Validate arguments
9701023
parser.add_argument("--benchmark", type=str, help="Specify benchmark file name.")

src/kepler_model/estimate/archived_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,3 @@ def get_achived_model(power_request):
8787
print("cannot validate the archived model")
8888
return None
8989
return output_path
90-

0 commit comments

Comments
 (0)