|
21 | 21 | from qiita_core.util import qiita_test_checker
|
22 | 22 | import qiita_db as qdb
|
23 | 23 |
|
| 24 | +from matplotlib.figure import Figure |
| 25 | +from matplotlib.axes import Axes |
| 26 | +import matplotlib.pyplot as plt |
| 27 | + |
24 | 28 |
|
25 | 29 | @qiita_test_checker()
|
26 | 30 | class DBUtilTestsBase(TestCase):
|
@@ -1303,6 +1307,64 @@ def test_quick_mounts_purge(self):
|
1303 | 1307 | qdb.util.quick_mounts_purge()
|
1304 | 1308 |
|
1305 | 1309 |
|
| 1310 | +class ResourceAllocationPlotTests(TestCase): |
| 1311 | + def setUp(self): |
| 1312 | + |
| 1313 | + self.PATH_TO_DATA = ('./qiita_db/test/test_data/' |
| 1314 | + 'jobs_2024-02-21.tsv.gz') |
| 1315 | + self.CNAME = "Validate" |
| 1316 | + self.SNAME = "Diversity types - alpha_vector" |
| 1317 | + self.col_name = 'samples * columns' |
| 1318 | + self.df = pd.read_csv(self.PATH_TO_DATA, sep='\t', |
| 1319 | + dtype={'extra_info': str}) |
| 1320 | + |
| 1321 | + def test_plot_return(self): |
| 1322 | + # check the plot returns correct objects |
| 1323 | + fig1, axs1 = qdb.util.resource_allocation_plot( |
| 1324 | + self.PATH_TO_DATA, self.CNAME, self.SNAME, self.col_name) |
| 1325 | + self.assertIsInstance( |
| 1326 | + fig1, Figure, |
| 1327 | + "Returned object fig1 is not a Matplotlib Figure") |
| 1328 | + for ax in axs1: |
| 1329 | + self.assertIsInstance( |
| 1330 | + ax, Axes, |
| 1331 | + "Returned object axs1 is not a single Matplotlib Axes object") |
| 1332 | + |
| 1333 | + def test_minimize_const(self): |
| 1334 | + self.df = self.df[ |
| 1335 | + (self.df.cName == self.CNAME) & (self.df.sName == self.SNAME)] |
| 1336 | + self.df.dropna(subset=['samples', 'columns'], inplace=True) |
| 1337 | + self.df[self.col_name] = self.df.samples * self.df['columns'] |
| 1338 | + fig, axs = plt.subplots(ncols=2, figsize=(10, 4), sharey=False) |
| 1339 | + |
| 1340 | + bm, options = qdb.util._resource_allocation_plot_helper( |
| 1341 | + self.df, axs[0], self.CNAME, self.SNAME, 'MaxRSSRaw', |
| 1342 | + qdb.util.MODELS_MEM, self.col_name) |
| 1343 | + # check that the algorithm chooses correct model for MaxRSSRaw and |
| 1344 | + # has 0 failures |
| 1345 | + k, a, b = options.x |
| 1346 | + failures_df = qdb.util._resource_allocation_failures( |
| 1347 | + self.df, k, a, b, bm, self.col_name, 'MaxRSSRaw') |
| 1348 | + failures = failures_df.shape[0] |
| 1349 | + self.assertEqual(bm, qdb.util.mem_model4, msg="""Best memory model |
| 1350 | + doesn't match""") |
| 1351 | + self.assertEqual(failures, 0, "Number of failures must be 0") |
| 1352 | + |
| 1353 | + # check that the algorithm chooses correct model for ElapsedRaw and |
| 1354 | + # has 1 failure |
| 1355 | + bm, options = qdb.util._resource_allocation_plot_helper( |
| 1356 | + self.df, axs[1], self.CNAME, self.SNAME, 'ElapsedRaw', |
| 1357 | + qdb.util.MODELS_TIME, self.col_name) |
| 1358 | + k, a, b = options.x |
| 1359 | + failures_df = qdb.util._resource_allocation_failures( |
| 1360 | + self.df, k, a, b, bm, self.col_name, 'ElapsedRaw') |
| 1361 | + failures = failures_df.shape[0] |
| 1362 | + |
| 1363 | + self.assertEqual(bm, qdb.util.time_model1, msg="""Best time model |
| 1364 | + doesn't match""") |
| 1365 | + self.assertEqual(failures, 1, "Number of failures must be 1") |
| 1366 | + |
| 1367 | + |
1306 | 1368 | STUDY_INFO = {
|
1307 | 1369 | 'study_id': 1,
|
1308 | 1370 | 'owner': 'Dude',
|
|
0 commit comments