-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy patharguments.py
172 lines (158 loc) · 5.34 KB
/
arguments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# ===============================================================================
# Copyright 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
import argparse
from typing import Dict, List
import pandas as pd
from ..report import add_report_generator_arguments
def get_parser_description(parser: argparse.ArgumentParser) -> pd.DataFrame:
"""Convert parser description to Markdown-style table."""
def get_argument_actions(parser: argparse.ArgumentParser) -> List:
arg_actions = []
for action in parser._actions:
if isinstance(action, argparse._ArgumentGroup):
for subaction in action._group_actions:
arg_actions.append(subaction)
else:
arg_actions.append(action)
return arg_actions
def parse_action(action: argparse.Action) -> Dict:
return {
"Name": "</br>".join(map(lambda x: f"`{x}`", action.option_strings)),
"Type": action.type.__name__ if action.type is not None else None,
"Default value": (
action.default if action.default is not argparse.SUPPRESS else None
),
"Choices": action.choices,
"Description": action.help,
}
return pd.DataFrame(map(parse_action, get_argument_actions(parser))).to_markdown(
index=False
)
def add_runner_arguments(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
# verbosity levels
parser.add_argument(
"--runner-log-level",
default="WARNING",
type=str,
choices=("ERROR", "WARNING", "INFO", "DEBUG"),
help="Logging level for benchmarks runner.",
)
parser.add_argument(
"--bench-log-level",
default="WARNING",
type=str,
choices=("ERROR", "WARNING", "INFO", "DEBUG"),
help="Logging level for each running benchmark.",
)
parser.add_argument(
"--log-level",
"-l",
default=None,
type=str,
choices=("ERROR", "WARNING", "INFO", "DEBUG"),
help="Global logging level for benchmarks: "
"overwrites runner, benchmarks and report logging levels.",
)
# benchmarking cases finding, overwriting and filtering
parser.add_argument(
"--config",
"--configs",
"-c",
type=str,
nargs="+",
default=None,
help="Paths to a configuration files or/and "
"directories that contain configuration files.",
)
parser.add_argument(
"--parameters",
"--params",
"-p",
default="",
type=str,
nargs="+",
help="Globally defines or overwrites config parameters. "
"For example: `-p data:dtype=float32 data:order=F`.",
)
parser.add_argument(
"--parameter-filters",
"--filters",
"-f",
default="",
type=str,
nargs="+",
help="Filters benchmarking cases by parameter values. "
"For example: `-f data:dtype=float32 data:order=F`.",
)
parser.add_argument(
"--result-file",
"-r",
type=str,
default="result.json",
help="File path to store scikit-learn_bench's runned cases results.",
)
parser.add_argument(
"--environment-name",
"--env-name",
"-e",
type=str,
default=None,
help="Environment name to use instead of it's configuration hash.",
)
parser.add_argument(
"--prefetch-datasets",
default=False,
action="store_true",
help="Load all requested datasets in parallel before running benchmarks.",
)
parser.add_argument(
"--describe-datasets",
default=False,
action="store_true",
help="Load all requested datasets in parallel and show their parameters.",
)
# workflow control
parser.add_argument(
"--exit-on-error",
default=False,
action="store_true",
help="Interrupt runner and exit if last benchmark failed with error.",
)
# option to get parser description in Markdown table format for READMEs
parser.add_argument(
"--describe-parser",
default=False,
action="store_true",
help="Print parser description in Markdown table format and exit.",
)
# report generator arguments for optional usage
parser.add_argument(
"--report",
default=False,
action="store_true",
help="Enables generation of report.",
)
add_report_generator_arguments(parser)
return parser
def get_runner_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="python -m sklbench",
description="""
Scikit-learn_bench runner
""",
)
add_runner_arguments(parser)
return parser