[973924]: / notebooks / resource-allocation / 102023.1.ipynb

Download this file

500 lines (499 with data), 19.7 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "from datetime import datetime, timedelta, date\n",
    "from humanize import naturalsize\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Qiita's resource allocation - quick update from previous version\n",
    "\n",
    "After the 2023.10 release we noticed that:\n",
    "1. `job-output-folder` `VALIDATE` command didn't have valid request because those jobs do not have sample/column values\n",
    "2. The default during a resource allocation for time is minutes and the calculations were done in seconds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Loading data\n",
    "\n",
    "First you will need to run `generate-allocation-summary.py` in Qiita as the qiita user (or whatever user runs qiita in your system). The resulting file would be: `job_[date].tsv.gz`.\n",
    "\n",
    "The generated file will have these columns: `['JobID', 'ElapsedRaw', 'MaxRSS', 'Submit', 'Start', 'MaxRSS.1', 'CPUTimeRAW', 'ReqMem', 'AllocCPUS', 'AveVMSize', 'QiitaID', 'external_id', 'sId', 'sName', 'sVersion', 'cId', 'cName', 'samples', 'columns', 'input_size', 'extra_info'],`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "m1g = 2**30\n",
    "df = pd.read_csv('jobs_2023-10-04.tsv.gz', sep='\\t', dtype={'extra_info': str})\n",
    "df['ElapsedRawTime'] = pd.to_timedelta(df.ElapsedRawTime)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'There are 101147 successful jobs since we moved to barnacle2 and the largest external_id is: 1581986'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# for reference for the next iteration of this notebook\n",
    "f'There are {df.shape[0]} successful jobs since we moved to barnacle2 and the largest external_id is: {df.external_id.max()}'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. Getting the default values for `job-output-folder` `VALIDATE`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"3\" halign=\"left\">ElapsedRawTime</th>\n",
       "      <th colspan=\"3\" halign=\"left\">MaxRSSRaw</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>min</th>\n",
       "      <th>max</th>\n",
       "      <th>count</th>\n",
       "      <th>min</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cName</th>\n",
       "      <th>sName</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"12\" valign=\"top\">Validate</th>\n",
       "      <th>BIOM type - BIOM</th>\n",
       "      <td>687</td>\n",
       "      <td>0 days 00:00:55</td>\n",
       "      <td>0 days 01:03:49</td>\n",
       "      <td>687</td>\n",
       "      <td>222.8 MB</td>\n",
       "      <td>82.0 GB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Diversity types - FeatureData</th>\n",
       "      <td>6</td>\n",
       "      <td>0 days 00:01:20</td>\n",
       "      <td>0 days 00:02:49</td>\n",
       "      <td>6</td>\n",
       "      <td>331.4 MB</td>\n",
       "      <td>384.3 MB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Diversity types - alpha_vector</th>\n",
       "      <td>123</td>\n",
       "      <td>0 days 00:01:12</td>\n",
       "      <td>3 days 04:36:54</td>\n",
       "      <td>123</td>\n",
       "      <td>289.3 MB</td>\n",
       "      <td>101.5 GB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Diversity types - distance_matrix</th>\n",
       "      <td>117</td>\n",
       "      <td>0 days 00:00:37</td>\n",
       "      <td>0 days 00:03:55</td>\n",
       "      <td>117</td>\n",
       "      <td>122.7 MB</td>\n",
       "      <td>12.5 GB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Diversity types - ordination_results</th>\n",
       "      <td>107</td>\n",
       "      <td>0 days 00:00:39</td>\n",
       "      <td>0 days 00:03:19</td>\n",
       "      <td>107</td>\n",
       "      <td>117.2 MB</td>\n",
       "      <td>2.9 GB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sequencing Data Type - Demultiplexed</th>\n",
       "      <td>43</td>\n",
       "      <td>0 days 00:00:35</td>\n",
       "      <td>0 days 00:12:23</td>\n",
       "      <td>43</td>\n",
       "      <td>83.4 MB</td>\n",
       "      <td>517.4 MB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sequencing Data Type - FASTA</th>\n",
       "      <td>2</td>\n",
       "      <td>0 days 00:00:56</td>\n",
       "      <td>0 days 00:02:23</td>\n",
       "      <td>2</td>\n",
       "      <td>79.8 MB</td>\n",
       "      <td>83.6 MB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sequencing Data Type - FASTQ</th>\n",
       "      <td>32</td>\n",
       "      <td>0 days 00:00:41</td>\n",
       "      <td>0 days 01:50:44</td>\n",
       "      <td>32</td>\n",
       "      <td>78.7 MB</td>\n",
       "      <td>84.4 MB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sequencing Data Type - SFF</th>\n",
       "      <td>1</td>\n",
       "      <td>0 days 00:01:09</td>\n",
       "      <td>0 days 00:01:09</td>\n",
       "      <td>1</td>\n",
       "      <td>79.6 MB</td>\n",
       "      <td>79.6 MB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sequencing Data Type - per_sample_FASTQ</th>\n",
       "      <td>73</td>\n",
       "      <td>0 days 00:00:36</td>\n",
       "      <td>0 days 18:13:21</td>\n",
       "      <td>73</td>\n",
       "      <td>77.6 MB</td>\n",
       "      <td>83.6 MB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Visualization types - q2_visualization</th>\n",
       "      <td>133</td>\n",
       "      <td>0 days 00:00:36</td>\n",
       "      <td>0 days 00:24:56</td>\n",
       "      <td>133</td>\n",
       "      <td>51.5 MB</td>\n",
       "      <td>67.5 MB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>qtp-job-output-folder - job-output-folder</th>\n",
       "      <td>228</td>\n",
       "      <td>0 days 00:00:31</td>\n",
       "      <td>0 days 00:04:06</td>\n",
       "      <td>228</td>\n",
       "      <td>18.3 MB</td>\n",
       "      <td>46.7 MB</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   ElapsedRawTime  \\\n",
       "                                                            count   \n",
       "cName    sName                                                      \n",
       "Validate BIOM type - BIOM                                     687   \n",
       "         Diversity types - FeatureData                          6   \n",
       "         Diversity types - alpha_vector                       123   \n",
       "         Diversity types - distance_matrix                    117   \n",
       "         Diversity types - ordination_results                 107   \n",
       "         Sequencing Data Type - Demultiplexed                  43   \n",
       "         Sequencing Data Type - FASTA                           2   \n",
       "         Sequencing Data Type - FASTQ                          32   \n",
       "         Sequencing Data Type - SFF                             1   \n",
       "         Sequencing Data Type - per_sample_FASTQ               73   \n",
       "         Visualization types - q2_visualization               133   \n",
       "         qtp-job-output-folder - job-output-folder            228   \n",
       "\n",
       "                                                                    \\\n",
       "                                                               min   \n",
       "cName    sName                                                       \n",
       "Validate BIOM type - BIOM                          0 days 00:00:55   \n",
       "         Diversity types - FeatureData             0 days 00:01:20   \n",
       "         Diversity types - alpha_vector            0 days 00:01:12   \n",
       "         Diversity types - distance_matrix         0 days 00:00:37   \n",
       "         Diversity types - ordination_results      0 days 00:00:39   \n",
       "         Sequencing Data Type - Demultiplexed      0 days 00:00:35   \n",
       "         Sequencing Data Type - FASTA              0 days 00:00:56   \n",
       "         Sequencing Data Type - FASTQ              0 days 00:00:41   \n",
       "         Sequencing Data Type - SFF                0 days 00:01:09   \n",
       "         Sequencing Data Type - per_sample_FASTQ   0 days 00:00:36   \n",
       "         Visualization types - q2_visualization    0 days 00:00:36   \n",
       "         qtp-job-output-folder - job-output-folder 0 days 00:00:31   \n",
       "\n",
       "                                                                   MaxRSSRaw  \\\n",
       "                                                               max     count   \n",
       "cName    sName                                                                 \n",
       "Validate BIOM type - BIOM                          0 days 01:03:49       687   \n",
       "         Diversity types - FeatureData             0 days 00:02:49         6   \n",
       "         Diversity types - alpha_vector            3 days 04:36:54       123   \n",
       "         Diversity types - distance_matrix         0 days 00:03:55       117   \n",
       "         Diversity types - ordination_results      0 days 00:03:19       107   \n",
       "         Sequencing Data Type - Demultiplexed      0 days 00:12:23        43   \n",
       "         Sequencing Data Type - FASTA              0 days 00:02:23         2   \n",
       "         Sequencing Data Type - FASTQ              0 days 01:50:44        32   \n",
       "         Sequencing Data Type - SFF                0 days 00:01:09         1   \n",
       "         Sequencing Data Type - per_sample_FASTQ   0 days 18:13:21        73   \n",
       "         Visualization types - q2_visualization    0 days 00:24:56       133   \n",
       "         qtp-job-output-folder - job-output-folder 0 days 00:04:06       228   \n",
       "\n",
       "                                                                        \n",
       "                                                         min       max  \n",
       "cName    sName                                                          \n",
       "Validate BIOM type - BIOM                           222.8 MB   82.0 GB  \n",
       "         Diversity types - FeatureData              331.4 MB  384.3 MB  \n",
       "         Diversity types - alpha_vector             289.3 MB  101.5 GB  \n",
       "         Diversity types - distance_matrix          122.7 MB   12.5 GB  \n",
       "         Diversity types - ordination_results       117.2 MB    2.9 GB  \n",
       "         Sequencing Data Type - Demultiplexed        83.4 MB  517.4 MB  \n",
       "         Sequencing Data Type - FASTA                79.8 MB   83.6 MB  \n",
       "         Sequencing Data Type - FASTQ                78.7 MB   84.4 MB  \n",
       "         Sequencing Data Type - SFF                  79.6 MB   79.6 MB  \n",
       "         Sequencing Data Type - per_sample_FASTQ     77.6 MB   83.6 MB  \n",
       "         Visualization types - q2_visualization      51.5 MB   67.5 MB  \n",
       "         qtp-job-output-folder - job-output-folder   18.3 MB   46.7 MB  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cname = 'Validate'\n",
    "_df = df[(df.cName == cname)].copy()\n",
    "\n",
    "summary = _df[_df['samples'].isnull() & _df['columns'].isnull()].groupby(\n",
    "    ['cName', 'sName'])[['ElapsedRawTime', 'MaxRSSRaw']].agg(['count', 'min', 'max']).copy()\n",
    "\n",
    "summary[('MaxRSSRaw', 'min')] = summary[('MaxRSSRaw', 'min')].apply(naturalsize)\n",
    "summary[('MaxRSSRaw', 'max')] = summary[('MaxRSSRaw', 'max')].apply(naturalsize)\n",
    "\n",
    "display(summary)\n",
    "\n",
    "# New allocation: -p qiita -N 1 -n 1 --mem 100mb --time 00:40:00"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. Updates for the seconds to minute confusion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "=============\n",
    "=============\n",
    "     allocation = '-p qiita -N 1 -n 1 '\n",
    "            || '--mem (2**30)+({samples}*150000) '\n",
    "            || '--time 240'\n",
    "\n",
    "UPDATE qiita.processing_job_resource_allocation set\n",
    "    allocation = '-p qiita -N 1 -n 1 '\n",
    "           || '--mem (2**30)+({samples}*150000) '\n",
    "           || '--time 4'\n",
    "    WHERE job_type = 'RESOURCE_PARAMS_COMMAND' and\n",
    "    name = 'delete_sample_or_column';\n",
    "\n",
    "=============\n",
    "=============\n",
    "     allocation = '-p qiita -N 1 -n 1 '\n",
    "            || '--mem {samples}*10000000'\n",
    "            || '--time 61200'\n",
    "\n",
    "UPDATE qiita.processing_job_resource_allocation set\n",
    "    allocation = '-p qiita -N 1 -n 1 '\n",
    "           || '--mem {samples}*10000000'\n",
    "           || '--time 1020'\n",
    "    WHERE job_type = 'RESOURCE_PARAMS_COMMAND' and\n",
    "    name = 'Sequence Processing Pipeline';\n",
    "\n",
    "=============\n",
    "=============\n",
    "     allocation = '-p qiita -N 1 -n 1 --mem 4g --time 900'\n",
    "\n",
    "UPDATE qiita.processing_job_resource_allocation set\n",
    "    allocation = '-p qiita -N 1 -n 1 --mem 4g --time 15'\n",
    "    WHERE job_type = 'RESOURCE_PARAMS_COMMAND' and\n",
    "    name = 'Filter samples from table [filter_samples]';\n",
    "\n",
    "=============\n",
    "=============\n",
    "     allocation = '-p qiita -N 1 -n 1 '\n",
    "            || '--mem (2**31)+({input_size}*6) if\n",
    "(2**31)+({input_size}*6) < 13958643712 else 13958643712 '\n",
    "            || '--time 2400'\n",
    "\n",
    "UPDATE qiita.processing_job_resource_allocation set\n",
    "    allocation = '-p qiita -N 1 -n 1 '\n",
    "           || '--mem (2**31)+({input_size}*6) if\n",
    "(2**31)+({input_size}*6) < 13958643712 else 13958643712 '\n",
    "           || '--time 40'\n",
    "    WHERE job_type = 'RESOURCE_PARAMS_COMMAND' and\n",
    "    name = 'Rarefy table [rarefy]';\n",
    "\n",
    "=============\n",
    "=============\n",
    "     allocation = '-p qiita -N 1 -n 1 '\n",
    "            || '--mem 14g'\n",
    "            || '--time 360'\n",
    "\n",
    "UPDATE qiita.processing_job_resource_allocation set\n",
    "    allocation = '-p qiita -N 1 -n 1 '\n",
    "           || '--mem 14g '\n",
    "           || '--time 6'\n",
    "    WHERE job_type = 'RESOURCE_PARAMS_COMMAND' and\n",
    "    name = 'Alpha diversity (phylogenetic) [alpha_phylogenetic]';\n",
    "\n",
    "\n",
    "=============\n",
    "=============\n",
    "     allocation = '-p qiita -N 1 -n 1 '\n",
    "            || '--mem (2**33)+(2**30)+(({samples}*{columns}*{input_size})/4500000)'\n",
    "            || '--time 1800'\n",
    "\n",
    "UPDATE qiita.processing_job_resource_allocation set\n",
    "    allocation = '-p qiita -N 1 -n 1 '\n",
    "           || '--mem\n",
    "(2**33)+(2**30)+(({samples}*{columns}*{input_size})/4500000) '\n",
    "           || '--time 30'\n",
    "    WHERE job_type = 'RESOURCE_PARAMS_COMMAND' and\n",
    "    name = 'Visualize and Interact with Principal Coordinates Analysis\n",
    "Plots [plot]';\n",
    "\n",
    "=============\n",
    "=============\n",
    "     allocation = '-p qiita -N 1 -n 1 '\n",
    "            || '--mem (2**32)+(({samples}*{columns}*{input_size}')/20000)'\n",
    "            || '--time 90000'\n",
    "\n",
    "UPDATE qiita.processing_job_resource_allocation set\n",
    "    allocation = '-p qiita -N 1 -n 1 '\n",
    "           || '--mem (2**32)+(({samples}*{columns}*{input_size})/20000) '\n",
    "           || '--time 1500'\n",
    "    WHERE job_type = 'RESOURCE_PARAMS_COMMAND' and\n",
    "    name = 'Alpha rarefaction curves [alpha_rarefaction]';\n",
    "\n",
    "=============\n",
    "=============\n",
    "     allocation = '-p qiita -N 1 -n 1 '\n",
    "            || '--mem 2*(2**30)+{input_size} if 2*(2**30)+{input_size} < 16*(2**30) else 16*(2**30)'\n",
    "            || '--time 36000'\n",
    "\n",
    "UPDATE qiita.processing_job_resource_allocation set\n",
    "    allocation = '-p qiita -N 1 -n 1 '\n",
    "           || '--mem 2*(2**30)+{input_size} if 2*(2**30)+{input_size}\n",
    "< 16*(2**30) else 16*(2**30) '\n",
    "           || '--time 600'\n",
    "    WHERE job_type = 'RESOURCE_PARAMS_COMMAND' and\n",
    "    name = 'Trimming';\n",
    "\n",
    "=============\n",
    "=============\n",
    "     allocation = '-p qiita -N 1 -n 1 '\n",
    "            || '--mem (2**30)+({samples}*{columns}*2000)'\n",
    "            || '--time 2300'\n",
    "\n",
    "UPDATE qiita.processing_job_resource_allocation set\n",
    "    allocation = '-p qiita -N 1 -n 1 '\n",
    "           || '--mem (2**30)+({samples}*{columns}*2000) '\n",
    "           || '--time 39'\n",
    "    WHERE job_type = 'RESOURCE_PARAMS_COMMAND' and\n",
    "    name = 'update_sample_template';"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}