Skip to content

Commit 8c91945

Browse files
authored
PR: Resource allocation plots in util.py (qiita-spots#3382)
* Initial commmit to resource allocation plots * Update to util.py and tests * Update test_util.py * revert 072023.ipynb * Debug test_util * testing plot based on № failures * Addressed Antonio's comments * Updates according to @charles-cowart comments * define functions as const @charles-cowart
1 parent d743a81 commit 8c91945

File tree

4 files changed

+391
-0
lines changed

4 files changed

+391
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ qiita_pet/*.conf
7272

7373
# jupyter notebooks input data
7474
notebooks/*/*.tsv.gz
75+
76+
# jupyter notebooks input data
77+
notebooks/resource-allocation/data
7.17 MB
Binary file not shown.

qiita_db/test/test_util.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
from qiita_core.util import qiita_test_checker
2222
import qiita_db as qdb
2323

24+
from matplotlib.figure import Figure
25+
from matplotlib.axes import Axes
26+
import matplotlib.pyplot as plt
27+
2428

2529
@qiita_test_checker()
2630
class DBUtilTestsBase(TestCase):
@@ -1303,6 +1307,64 @@ def test_quick_mounts_purge(self):
13031307
qdb.util.quick_mounts_purge()
13041308

13051309

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+
13061368
STUDY_INFO = {
13071369
'study_id': 1,
13081370
'owner': 'Dude',

0 commit comments

Comments
 (0)