ear-analytics-core 5.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,277 @@
1
+ Eclipse Public License - v 2.0
2
+
3
+ THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
4
+ PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION
5
+ OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
6
+
7
+ 1. DEFINITIONS
8
+
9
+ "Contribution" means:
10
+
11
+ a) in the case of the initial Contributor, the initial content
12
+ Distributed under this Agreement, and
13
+
14
+ b) in the case of each subsequent Contributor:
15
+ i) changes to the Program, and
16
+ ii) additions to the Program;
17
+ where such changes and/or additions to the Program originate from
18
+ and are Distributed by that particular Contributor. A Contribution
19
+ "originates" from a Contributor if it was added to the Program by
20
+ such Contributor itself or anyone acting on such Contributor's behalf.
21
+ Contributions do not include changes or additions to the Program that
22
+ are not Modified Works.
23
+
24
+ "Contributor" means any person or entity that Distributes the Program.
25
+
26
+ "Licensed Patents" mean patent claims licensable by a Contributor which
27
+ are necessarily infringed by the use or sale of its Contribution alone
28
+ or when combined with the Program.
29
+
30
+ "Program" means the Contributions Distributed in accordance with this
31
+ Agreement.
32
+
33
+ "Recipient" means anyone who receives the Program under this Agreement
34
+ or any Secondary License (as applicable), including Contributors.
35
+
36
+ "Derivative Works" shall mean any work, whether in Source Code or other
37
+ form, that is based on (or derived from) the Program and for which the
38
+ editorial revisions, annotations, elaborations, or other modifications
39
+ represent, as a whole, an original work of authorship.
40
+
41
+ "Modified Works" shall mean any work in Source Code or other form that
42
+ results from an addition to, deletion from, or modification of the
43
+ contents of the Program, including, for purposes of clarity any new file
44
+ in Source Code form that contains any contents of the Program. Modified
45
+ Works shall not include works that contain only declarations,
46
+ interfaces, types, classes, structures, or files of the Program solely
47
+ in each case in order to link to, bind by name, or subclass the Program
48
+ or Modified Works thereof.
49
+
50
+ "Distribute" means the acts of a) distributing or b) making available
51
+ in any manner that enables the transfer of a copy.
52
+
53
+ "Source Code" means the form of a Program preferred for making
54
+ modifications, including but not limited to software source code,
55
+ documentation source, and configuration files.
56
+
57
+ "Secondary License" means either the GNU General Public License,
58
+ Version 2.0, or any later versions of that license, including any
59
+ exceptions or additional permissions as identified by the initial
60
+ Contributor.
61
+
62
+ 2. GRANT OF RIGHTS
63
+
64
+ a) Subject to the terms of this Agreement, each Contributor hereby
65
+ grants Recipient a non-exclusive, worldwide, royalty-free copyright
66
+ license to reproduce, prepare Derivative Works of, publicly display,
67
+ publicly perform, Distribute and sublicense the Contribution of such
68
+ Contributor, if any, and such Derivative Works.
69
+
70
+ b) Subject to the terms of this Agreement, each Contributor hereby
71
+ grants Recipient a non-exclusive, worldwide, royalty-free patent
72
+ license under Licensed Patents to make, use, sell, offer to sell,
73
+ import and otherwise transfer the Contribution of such Contributor,
74
+ if any, in Source Code or other form. This patent license shall
75
+ apply to the combination of the Contribution and the Program if, at
76
+ the time the Contribution is added by the Contributor, such addition
77
+ of the Contribution causes such combination to be covered by the
78
+ Licensed Patents. The patent license shall not apply to any other
79
+ combinations which include the Contribution. No hardware per se is
80
+ licensed hereunder.
81
+
82
+ c) Recipient understands that although each Contributor grants the
83
+ licenses to its Contributions set forth herein, no assurances are
84
+ provided by any Contributor that the Program does not infringe the
85
+ patent or other intellectual property rights of any other entity.
86
+ Each Contributor disclaims any liability to Recipient for claims
87
+ brought by any other entity based on infringement of intellectual
88
+ property rights or otherwise. As a condition to exercising the
89
+ rights and licenses granted hereunder, each Recipient hereby
90
+ assumes sole responsibility to secure any other intellectual
91
+ property rights needed, if any. For example, if a third party
92
+ patent license is required to allow Recipient to Distribute the
93
+ Program, it is Recipient's responsibility to acquire that license
94
+ before distributing the Program.
95
+
96
+ d) Each Contributor represents that to its knowledge it has
97
+ sufficient copyright rights in its Contribution, if any, to grant
98
+ the copyright license set forth in this Agreement.
99
+
100
+ e) Notwithstanding the terms of any Secondary License, no
101
+ Contributor makes additional grants to any Recipient (other than
102
+ those set forth in this Agreement) as a result of such Recipient's
103
+ receipt of the Program under the terms of a Secondary License
104
+ (if permitted under the terms of Section 3).
105
+
106
+ 3. REQUIREMENTS
107
+
108
+ 3.1 If a Contributor Distributes the Program in any form, then:
109
+
110
+ a) the Program must also be made available as Source Code, in
111
+ accordance with section 3.2, and the Contributor must accompany
112
+ the Program with a statement that the Source Code for the Program
113
+ is available under this Agreement, and informs Recipients how to
114
+ obtain it in a reasonable manner on or through a medium customarily
115
+ used for software exchange; and
116
+
117
+ b) the Contributor may Distribute the Program under a license
118
+ different than this Agreement, provided that such license:
119
+ i) effectively disclaims on behalf of all other Contributors all
120
+ warranties and conditions, express and implied, including
121
+ warranties or conditions of title and non-infringement, and
122
+ implied warranties or conditions of merchantability and fitness
123
+ for a particular purpose;
124
+
125
+ ii) effectively excludes on behalf of all other Contributors all
126
+ liability for damages, including direct, indirect, special,
127
+ incidental and consequential damages, such as lost profits;
128
+
129
+ iii) does not attempt to limit or alter the recipients' rights
130
+ in the Source Code under section 3.2; and
131
+
132
+ iv) requires any subsequent distribution of the Program by any
133
+ party to be under a license that satisfies the requirements
134
+ of this section 3.
135
+
136
+ 3.2 When the Program is Distributed as Source Code:
137
+
138
+ a) it must be made available under this Agreement, or if the
139
+ Program (i) is combined with other material in a separate file or
140
+ files made available under a Secondary License, and (ii) the initial
141
+ Contributor attached to the Source Code the notice described in
142
+ Exhibit A of this Agreement, then the Program may be made available
143
+ under the terms of such Secondary Licenses, and
144
+
145
+ b) a copy of this Agreement must be included with each copy of
146
+ the Program.
147
+
148
+ 3.3 Contributors may not remove or alter any copyright, patent,
149
+ trademark, attribution notices, disclaimers of warranty, or limitations
150
+ of liability ("notices") contained within the Program from any copy of
151
+ the Program which they Distribute, provided that Contributors may add
152
+ their own appropriate notices.
153
+
154
+ 4. COMMERCIAL DISTRIBUTION
155
+
156
+ Commercial distributors of software may accept certain responsibilities
157
+ with respect to end users, business partners and the like. While this
158
+ license is intended to facilitate the commercial use of the Program,
159
+ the Contributor who includes the Program in a commercial product
160
+ offering should do so in a manner which does not create potential
161
+ liability for other Contributors. Therefore, if a Contributor includes
162
+ the Program in a commercial product offering, such Contributor
163
+ ("Commercial Contributor") hereby agrees to defend and indemnify every
164
+ other Contributor ("Indemnified Contributor") against any losses,
165
+ damages and costs (collectively "Losses") arising from claims, lawsuits
166
+ and other legal actions brought by a third party against the Indemnified
167
+ Contributor to the extent caused by the acts or omissions of such
168
+ Commercial Contributor in connection with its distribution of the Program
169
+ in a commercial product offering. The obligations in this section do not
170
+ apply to any claims or Losses relating to any actual or alleged
171
+ intellectual property infringement. In order to qualify, an Indemnified
172
+ Contributor must: a) promptly notify the Commercial Contributor in
173
+ writing of such claim, and b) allow the Commercial Contributor to control,
174
+ and cooperate with the Commercial Contributor in, the defense and any
175
+ related settlement negotiations. The Indemnified Contributor may
176
+ participate in any such claim at its own expense.
177
+
178
+ For example, a Contributor might include the Program in a commercial
179
+ product offering, Product X. That Contributor is then a Commercial
180
+ Contributor. If that Commercial Contributor then makes performance
181
+ claims, or offers warranties related to Product X, those performance
182
+ claims and warranties are such Commercial Contributor's responsibility
183
+ alone. Under this section, the Commercial Contributor would have to
184
+ defend claims against the other Contributors related to those performance
185
+ claims and warranties, and if a court requires any other Contributor to
186
+ pay any damages as a result, the Commercial Contributor must pay
187
+ those damages.
188
+
189
+ 5. NO WARRANTY
190
+
191
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
192
+ PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS"
193
+ BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
194
+ IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF
195
+ TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
196
+ PURPOSE. Each Recipient is solely responsible for determining the
197
+ appropriateness of using and distributing the Program and assumes all
198
+ risks associated with its exercise of rights under this Agreement,
199
+ including but not limited to the risks and costs of program errors,
200
+ compliance with applicable laws, damage to or loss of data, programs
201
+ or equipment, and unavailability or interruption of operations.
202
+
203
+ 6. DISCLAIMER OF LIABILITY
204
+
205
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
206
+ PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS
207
+ SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
208
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST
209
+ PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
210
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
211
+ ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
212
+ EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
213
+ POSSIBILITY OF SUCH DAMAGES.
214
+
215
+ 7. GENERAL
216
+
217
+ If any provision of this Agreement is invalid or unenforceable under
218
+ applicable law, it shall not affect the validity or enforceability of
219
+ the remainder of the terms of this Agreement, and without further
220
+ action by the parties hereto, such provision shall be reformed to the
221
+ minimum extent necessary to make such provision valid and enforceable.
222
+
223
+ If Recipient institutes patent litigation against any entity
224
+ (including a cross-claim or counterclaim in a lawsuit) alleging that the
225
+ Program itself (excluding combinations of the Program with other software
226
+ or hardware) infringes such Recipient's patent(s), then such Recipient's
227
+ rights granted under Section 2(b) shall terminate as of the date such
228
+ litigation is filed.
229
+
230
+ All Recipient's rights under this Agreement shall terminate if it
231
+ fails to comply with any of the material terms or conditions of this
232
+ Agreement and does not cure such failure in a reasonable period of
233
+ time after becoming aware of such noncompliance. If all Recipient's
234
+ rights under this Agreement terminate, Recipient agrees to cease use
235
+ and distribution of the Program as soon as reasonably practicable.
236
+ However, Recipient's obligations under this Agreement and any licenses
237
+ granted by Recipient relating to the Program shall continue and survive.
238
+
239
+ Everyone is permitted to copy and distribute copies of this Agreement,
240
+ but in order to avoid inconsistency the Agreement is copyrighted and
241
+ may only be modified in the following manner. The Agreement Steward
242
+ reserves the right to publish new versions (including revisions) of
243
+ this Agreement from time to time. No one other than the Agreement
244
+ Steward has the right to modify this Agreement. The Eclipse Foundation
245
+ is the initial Agreement Steward. The Eclipse Foundation may assign the
246
+ responsibility to serve as the Agreement Steward to a suitable separate
247
+ entity. Each new version of the Agreement will be given a distinguishing
248
+ version number. The Program (including Contributions) may always be
249
+ Distributed subject to the version of the Agreement under which it was
250
+ received. In addition, after a new version of the Agreement is published,
251
+ Contributor may elect to Distribute the Program (including its
252
+ Contributions) under the new version.
253
+
254
+ Except as expressly stated in Sections 2(a) and 2(b) above, Recipient
255
+ receives no rights or licenses to the intellectual property of any
256
+ Contributor under this Agreement, whether expressly, by implication,
257
+ estoppel or otherwise. All rights in the Program not expressly granted
258
+ under this Agreement are reserved. Nothing in this Agreement is intended
259
+ to be enforceable by any entity that is not a Contributor or Recipient.
260
+ No third-party beneficiary rights are created under this Agreement.
261
+
262
+ Exhibit A - Form of Secondary Licenses Notice
263
+
264
+ "This Source Code may also be made available under the following
265
+ Secondary Licenses when the conditions for such availability set forth
266
+ in the Eclipse Public License, v. 2.0 are satisfied: {name license(s),
267
+ version(s), and exceptions or additional permissions here}."
268
+
269
+ Simply including a copy of this Agreement, including this Exhibit A
270
+ is not sufficient to license the Source Code under Secondary Licenses.
271
+
272
+ If it is not possible or desirable to put the notice in a particular
273
+ file, then You may include the notice in a location (such as a LICENSE
274
+ file in a relevant directory) where a recipient would be likely to
275
+ look for such a notice.
276
+
277
+ You may add additional accurate notices of copyright ownership.
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: ear-analytics-core
3
+ Version: 5.0.0
4
+ Summary: Core library for EAR analytics and Energy Models.
5
+ Author-email: Oriol Vidal <oriol.vidal@eas4dc.com>, Jalal Lakhlili <jalal.lakhlili@eas4dc.com>
6
+ License-Expression: EPL-2.0
7
+ Keywords: data,hpc,analysis,ear
8
+ Classifier: Programming Language :: Python :: 3
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: numpy
12
+ Requires-Dist: pandas[output-formatting,performance,plot]
13
+ Requires-Dist: importlib_resources
14
+ Requires-Dist: rich
15
+ Requires-Dist: pylatex
16
+ Requires-Dist: returns
17
+ Provides-Extra: docs
18
+ Requires-Dist: sphinx; extra == "docs"
19
+ Provides-Extra: tests
20
+ Requires-Dist: pytest; extra == "tests"
21
+ Dynamic: license-file
22
+
23
+ # ear_analytics_core
24
+ A package to be used to work with EAR data.
25
+
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install -U pip
31
+ pip install build setuptools wheel
32
+ python -m build
33
+ pip install .
34
+ ```
35
+
36
+ > You can change the destination path by exporting the variable [`PYTHONUSERBASE`](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUSERBASE).
37
+ > Tool's developers may want to use `pip install -e .` to install the package in editable mode, so there is no need to reinstall every time you want to test a new feature.
@@ -0,0 +1,15 @@
1
+ # ear_analytics_core
2
+ A package to be used to work with EAR data.
3
+
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install -U pip
9
+ pip install build setuptools wheel
10
+ python -m build
11
+ pip install .
12
+ ```
13
+
14
+ > You can change the destination path by exporting the variable [`PYTHONUSERBASE`](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUSERBASE).
15
+ > Tool's developers may want to use `pip install -e .` to install the package in editable mode, so there is no need to reinstall every time you want to test a new feature.
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ear-analytics-core"
7
+ authors = [
8
+ {name = "Oriol Vidal", email = "oriol.vidal@eas4dc.com"},
9
+ {name = "Jalal Lakhlili", email = "jalal.lakhlili@eas4dc.com"}
10
+ ]
11
+ description = "Core library for EAR analytics and Energy Models."
12
+ readme = "README.md"
13
+ keywords = ["data", "hpc", "analysis", "ear"]
14
+ license = "EPL-2.0"
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ ]
18
+ version = "5.0.0"
19
+ dependencies = [
20
+ "numpy",
21
+ "pandas[performance, plot, output-formatting]",
22
+ "importlib_resources",
23
+ "rich",
24
+ "pylatex",
25
+ "returns",
26
+ ]
27
+
28
+ [tool.setuptools]
29
+ package-dir = {"" = "src"}
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
33
+
34
+ [project.optional-dependencies]
35
+ docs = [
36
+ "sphinx"
37
+ ]
38
+ tests = [
39
+ "pytest"
40
+ ]
41
+
42
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,9 @@
1
+ ######################################################################
2
+ # Copyright (c) 2024 Energy Aware Solutions, S.L
3
+ #
4
+ # This program and the accompanying materials are made
5
+ # available under the terms of the Eclipse Public License 2.0
6
+ # which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ #
8
+ # SPDX-License-Identifier: EPL-2.0
9
+ #######################################################################
@@ -0,0 +1,27 @@
1
+ ######################################################################
2
+ # Copyright (c) 2024 Energy Aware Solutions, S.L
3
+ #
4
+ # This program and the accompanying materials are made
5
+ # available under the terms of the Eclipse Public License 2.0
6
+ # which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ #
8
+ # SPDX-License-Identifier: EPL-2.0
9
+ #######################################################################
10
+
11
+
12
+
13
+ from rich.console import Console
14
+
15
+ console = Console()
16
+
17
+
18
+ def warning(*args, **kwargs):
19
+ console.print('[magenta][WARNING][/]', *args, **kwargs)
20
+
21
+
22
+ def error(*args, **kwargs):
23
+ console.print('[bright_red][ERROR][/]', *args, **kwargs)
24
+
25
+
26
+ def info(*args, **kwargs):
27
+ console.print('[cyan][INFO][/]', *args, **kwargs)
@@ -0,0 +1,252 @@
1
+ ######################################################################
2
+ # Copyright (c) 2024 Energy Aware Solutions, S.L
3
+ #
4
+ # This program and the accompanying materials are made
5
+ # available under the terms of the Eclipse Public License 2.0
6
+ # which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ #
8
+ # SPDX-License-Identifier: EPL-2.0
9
+ #######################################################################
10
+
11
+
12
+ """ This module contains functions that can be applied
13
+ to a DataFrame contained known EAR data. """
14
+
15
+ import re
16
+ import numpy as np
17
+ import pandas as pd
18
+
19
+ from returns.result import Result, Failure, Success
20
+
21
+ from .utils import join_metric_node
22
+ from .metrics import read_metrics_configuration, metric_regex
23
+ from .console import warning
24
+
25
+
26
+ def df_filter_invalid_gpu_cols(df: pd.DataFrame) -> pd.DataFrame:
27
+ """
28
+ Given a DataFrame containing EAR data, returns a copy of it without all
29
+ those invalid GPU columns.
30
+
31
+ An invalid GPU column is a column with data of a GPU x, for which EAR did
32
+ not report any GPUx_POWER_W reading.
33
+ """
34
+ # The regex is precompiled since it is searched multiple times.
35
+ gpu_colname_pattern = re.compile(r'GPU(\d)_POWER_W')
36
+
37
+ def return_gpupwr_index(gpupwr_colname: str) -> str:
38
+ """
39
+ Given a str of the form r'GPUx_POWER_W', returns the x part, if
40
+ found. Otherwise, returns None.
41
+
42
+ The regular expression pattern is taken from gpu_colname_pattern.
43
+ """
44
+ match = re.fullmatch(gpu_colname_pattern, gpupwr_colname)
45
+ if match:
46
+ try:
47
+ return match.group(1)
48
+ except IndexError:
49
+ return None
50
+ else:
51
+ return None
52
+
53
+ invalid_gpu_indices = filter(None, # Filter all elements which are false
54
+ map(return_gpupwr_index,
55
+ df_get_invalid_gpupower_cols(df))
56
+ )
57
+
58
+ indices_or = '|'.join(invalid_gpu_indices)
59
+ filter_str = fr'GPU({indices_or})_\w+'
60
+ return df.drop(columns=df.filter(regex=filter_str).columns)
61
+
62
+
63
+ def df_get_invalid_gpupower_cols(df: pd.DataFrame) -> pd.Index:
64
+ """
65
+ Given a pd.DataFrame with EAR data, returns those columns which are
66
+ actually invalid GPU Power data.
67
+
68
+ Invalid GPU power data is all those GPUx_POWER_W columns of the DataFrame
69
+ that are full of zero values.
70
+ """
71
+ return (df
72
+ .filter(regex=r'GPU\d_POWER_W')
73
+ .mask(lambda x: x != 0) # All non-zero as nan
74
+ .dropna(axis=1, how='all') # Drop nan columns
75
+ .columns
76
+ )
77
+
78
+
79
+ def df_get_valid_gpu_data(df, gpu_metrics_regex):
80
+ """
81
+ Returns a DataFrame with only valid GPU data.
82
+
83
+ Valid GPU data is all those GPU columns of the DataFrame
84
+ that are not full of zeroes values.
85
+ """
86
+ return (df
87
+ .filter(regex=gpu_metrics_regex)
88
+ .mask(lambda x: x == 0) # All 0s as nan
89
+ .dropna(axis=1, how='all') # Drop nan columns
90
+ .mask(lambda x: x.isna(), other=0)) # Return to 0s
91
+
92
+
93
+ def df_has_gpu_data(df, gpu_metrics_regex):
94
+ """
95
+ Returns whether the DataFrame df has valid GPU data.
96
+ """
97
+ return not df.pipe(df_get_valid_gpu_data, gpu_metrics_regex).empty
98
+
99
+
100
+ def filter_invalid_gpu_series(df, gpu_metrics_regex):
101
+ """
102
+ Given a DataFrame with EAR data, filters those GPU
103
+ columns that not contain some of the job's GPUs used.
104
+ """
105
+ return (df
106
+ .drop(df # Erase GPU columns
107
+ .filter(regex=gpu_metrics_regex).columns, axis=1)
108
+ .join(df # Join with valid GPU columns
109
+ .pipe(df_get_valid_gpu_data, gpu_metrics_regex),
110
+ validate='one_to_one')) # Validate the join operation
111
+
112
+
113
+ # TODO: This function is not called anywhere
114
+ def df_gpu_node_metrics(df, conf_fn):
115
+ """
116
+ Given a DataFrame `df` with EAR data and a configuration filename `conf_fn`
117
+ Returns a copy of the DataFrame with new columns showing node-level GPU
118
+ metrics.
119
+ """
120
+ metrics_conf = read_metrics_configuration(conf_fn)
121
+
122
+ gpu_pwr_regex = metric_regex('gpu_power', metrics_conf)
123
+ gpu_freq_regex = metric_regex('gpu_freq', metrics_conf)
124
+ gpu_memfreq_regex = metric_regex('gpu_memfreq', metrics_conf)
125
+ gpu_util_regex = metric_regex('gpu_util', metrics_conf)
126
+ gpu_memutil_regex = metric_regex('gpu_memutil', metrics_conf)
127
+
128
+ gr_active_regex = metric_regex('dcgmi_gr_engine_active', metrics_conf)
129
+
130
+ return (df
131
+ .assign(
132
+ tot_gpu_pwr=lambda x: (x.filter(regex=gpu_pwr_regex)
133
+ .sum(axis=1)), # Agg. GPU power
134
+
135
+ avg_gpu_pwr=lambda x: (x.filter(regex=gpu_pwr_regex)
136
+ .mean(axis=1)), # Avg. GPU power
137
+
138
+ avg_gpu_freq=lambda x: (x.filter(regex=gpu_freq_regex)
139
+ .mean(axis=1)), # Avg. GPU freq
140
+
141
+ avg_gpu_memfreq=lambda x: (x.filter(regex=gpu_memfreq_regex)
142
+ .mean(axis=1)), # Avg. GPU mem freq
143
+
144
+ avg_gpu_util=lambda x: (x.filter(regex=gpu_util_regex)
145
+ .mean(axis=1)), # Avg. % GPU util
146
+
147
+ avg_gpu_memutil=lambda x: (x.filter(regex=gpu_memutil_regex)
148
+ .mean(axis=1)), # Avg %GPU mem util
149
+ avg_gr_engine_active=lambda x: (x.filter(regex=gr_active_regex)
150
+ .mean(axis=1))
151
+ ))
152
+
153
+
154
+ def metric_agg_timeseries(df, metric):
155
+ """
156
+ TODO: Pay attention here because this function depends directly
157
+ on EAR's output.
158
+ """
159
+ return (df
160
+ .pivot_table(values=metric,
161
+ index='TIMESTAMP', columns='NODENAME')
162
+ .bfill()
163
+ .ffill()
164
+ .pipe(join_metric_node)
165
+ .agg(np.sum, axis=1)
166
+ )
167
+
168
+
169
+ def filter_batch_step(ear_df: pd.DataFrame) -> Result[pd.DataFrame, str]:
170
+ """
171
+ This function returns the DataFrame `ear_df` without any SLURM batch step
172
+ if it has some. It spects the DataFrame containing a column called
173
+ 'STEPID'. If not encountered, returns a copy of the input argument.
174
+
175
+ Parameters
176
+ ----------
177
+ ear_df: A DataFrame containing EAR signature data. It must have a column
178
+ named 'STEPID'.
179
+
180
+ Return
181
+ ------
182
+ A Result type with a Success(pd.DataFrame) with the passed DataFrame
183
+ filtered or a Failure(str) indicating that the STEPID column does not exist
184
+ in the passed argument.
185
+ """
186
+ if 'STEPID' in ear_df.columns:
187
+ return Success(ear_df.loc[ear_df['STEPID'] != 4294967291])
188
+ else:
189
+ return Failure('STEPID not in data.')
190
+
191
+
192
+ def filter_and_query(df, rules):
193
+ """
194
+ Returns the resulting DataFrame of applying filtering rules to the passed
195
+ dataframe `df`. The function first performs a pre-filtering of the
196
+ dataframe based on column labels and then uses the pd.DataFrame.query
197
+ method to query for specific row values.
198
+
199
+ Rules are configured in `rules` as a dict with the following
200
+ <key, value> pairs:
201
+ - 'filter': <A dictionary with a pd.DataFrame.filter's kwarg. This
202
+ key is optional and it is used to call the function to the passed
203
+ dataframe before querying.
204
+ - 'expr': 'A valid string to be passed to pd.DataFrame.query
205
+ function called on the filtered dataframe. This field is required
206
+ if and only if the next key is not found.
207
+ - 'criteria': 'A string with a valid query operation to be concatenated
208
+ with every column of the pre-filtered dataframe.'
209
+ - 'join': 'A string with conditional operator, e.g., and, or.'
210
+
211
+ (Optional) Pre-filtering consists of calling pd.DataFrame.filter on
212
+ the passed dataframe and using rules' 'filter' dictionary as kwarg,
213
+ i.e., df.filter(**rules['filter']).
214
+
215
+ If `rules` contains 'expr' string, pd.DataFrame.query is called
216
+ directly. Otherwise, the expression is build as:
217
+ <column..0> <criteria> [<join> <column..1> <criteria>]*
218
+ where 'join' operator is used just when more than one column is found in
219
+ (maybe pre-filtered) dataframe and it is the 'or' string if `rules` does
220
+ not provide it.
221
+ """
222
+ # If the configuration does not have the 'filter' field, we apply
223
+ # the filter which returns the identical df
224
+ prefilter = rules.get('filter', {'items': df.columns})
225
+ df_filtered = df.filter(**prefilter)
226
+
227
+ if not df_filtered.empty:
228
+ expr = create_ear_dataframe_query(df_filtered, rules)
229
+ return df_filtered.query(expr), expr
230
+ return df_filtered, None
231
+
232
+
233
+ def create_ear_dataframe_query(df, rules):
234
+ """Support function for creating the query usied by
235
+ ear_dataframe_filter_and_query"""
236
+ expr = rules.get('expr', None)
237
+ if expr is None:
238
+ try:
239
+ criteria = rules['criteria']
240
+ except KeyError as e:
241
+ warning(f'The rule has not {e} field.')
242
+ return None
243
+ # Create the query to check whether some row matches the
244
+ # alert criteria
245
+ # Format: <column> <criteria> <join> <column> <criteria>...
246
+ join = rules.get('join', 'or')
247
+ expr = (f' {join} '
248
+ .join([f'`{col}` {criteria}'
249
+ for col in df.columns])
250
+ )
251
+ return expr
252
+