<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Haruki Niwa</title>
    <description>The latest articles on DEV Community by Haruki Niwa (@nha6ki).</description>
    <link>https://dev.to/nha6ki</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F483140%2Fc2a1de41-3994-4570-a6b6-8478a0929646.jpeg</url>
      <title>DEV Community: Haruki Niwa</title>
      <link>https://dev.to/nha6ki</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nha6ki"/>
    <language>en</language>
    <item>
      <title>Building a Local RAG System for Lab Notes and Slides with AMD and DGX Spark</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Fri, 20 Nov 2026 00:37:22 +0000</pubDate>
      <link>https://dev.to/nha6ki/building-a-local-rag-system-for-lab-notes-and-slides-with-amd-and-dgx-spark-42a8</link>
      <guid>https://dev.to/nha6ki/building-a-local-rag-system-for-lab-notes-and-slides-with-amd-and-dgx-spark-42a8</guid>
      <description>&lt;p&gt;I built a local retrieval-augmented generation (RAG) service so researchers can ask questions about our lab’s Markdown notes and PowerPoint slides and trace each answer back to a file and line or slide number.&lt;/p&gt;

&lt;p&gt;Two models run on the AMD Ryzen AI Max+ 395. &lt;strong&gt;Gemma 4 31B&lt;/strong&gt; describes rendered slides, making details in figures available as searchable text. &lt;strong&gt;Qwen3-Embedding-4B&lt;/strong&gt; embeds both the source text and the slide descriptions. When a researcher asks a question in Open WebUI, Qwen embeds the question in the same vector space so Qdrant can rank relevant passages. DeepSeek-V4.1-Flash-1017 runs across two NVIDIA DGX Spark systems and uses the retrieved excerpts to write the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Indexing the documents and answering a question
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh8pry2f5tmtbrg0a1njo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh8pry2f5tmtbrg0a1njo.png" alt="Gemma 4 31B describes slides. Qwen3-Embedding-4B embeds document text, captions and questions for retrieval with Qdrant. For each question, AMD retrieves excerpts and sends them with the question to DeepSeek on two DGX Sparks." width="800" height="1089"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;During an index refresh&lt;/strong&gt;, the AMD service reads the files from network-attached storage (NAS). It extracts native text, keeps its source locations, and adds descriptions of rendered slides from Gemma 4 31B. Ollama serves Qwen3-Embedding-4B locally to produce 2,560-dimensional embeddings. The service stores them with the passages and their source metadata in a local Qdrant index. A scheduled job checks for updates daily at 03:00 Japan time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;At question time&lt;/strong&gt;, a researcher selects the lab-document model in Open WebUI. The single-turn service uses Qwen3-Embedding-4B to embed the latest question and queries Qdrant using cosine similarity. It sends DeepSeek the question and up to four excerpts labeled &lt;code&gt;[S1]&lt;/code&gt; through &lt;code&gt;[S4]&lt;/code&gt;. Each excerpt gets up to 1,600 characters of content, and the whole evidence block, including its source headers, has a 5,500-character budget.&lt;/p&gt;

&lt;p&gt;The service checks the citation IDs it recognizes in the answer against the IDs it supplied. It then lists &lt;strong&gt;all supplied excerpts&lt;/strong&gt; by file path and starting line or slide number, including any excerpts the answer did not cite. A valid ID lets a researcher locate a passage. To check whether that passage supports a claim, someone still has to compare the two. &lt;/p&gt;

&lt;h2&gt;
  
  
  Testing a documented path and a live measurement
&lt;/h2&gt;

&lt;p&gt;On November 18, 2026, I tested the direct route from AMD to DeepSeek. For this trial, the index contained native text from 143 files, split into 1,529 chunks. I asked two questions, each in Japanese and English. All four searches returned four excerpts. The table paraphrases the prompts and omits the private path.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;What the test checked&lt;/th&gt;
&lt;th&gt;Recorded result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Where are the CSV files from test runs and MLflow stored?&lt;/td&gt;
&lt;td&gt;Did the answer give the expected directory and cite an excerpt containing it?&lt;/td&gt;
&lt;td&gt;Both languages returned the expected path with a supporting citation.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;How many GB are free on that volume right now?&lt;/td&gt;
&lt;td&gt;Did the answer acknowledge that the excerpts could not establish the current value and avoid estimating it?&lt;/td&gt;
&lt;td&gt;Both languages withheld a numeric capacity and passed the evidence check.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In a separate retrieval check, the passage with the expected directory ranked &lt;strong&gt;first for the Japanese query and second for the English query&lt;/strong&gt;. For the answer test, DeepSeek received the selected excerpts. After generation, the checker hashed path candidates from the answer and compared them with the known path hash. It also checked that at least one citation in the answer body pointed to an excerpt containing the expected path. This last check matters because the right source can appear in the appended list even when the answer cites the wrong passage.&lt;/p&gt;

&lt;p&gt;For the free-space question, retrieval succeeded in both languages. A fallback that only handles empty search results would never have run. The checker looked for numeric capacity expressions, and a second call to the same DeepSeek model assessed whether the answer explicitly acknowledged the missing measurement. I also used that model to review grounding and citations across the trial. The four cases give me a regression test for these two behaviors. The model’s review provides no independent estimate of answer quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making a PowerPoint figure searchable
&lt;/h2&gt;

&lt;p&gt;A plot can occupy most of a slide while the native text extractor returns little more than its title. The title might help find the deck, but it gives DeepSeek little evidence about the figure. I had encountered a similar problem when testing text and figures from a PDF. &lt;a href="https://dev.to/nha6ki/evaluating-deepseek-v41-flash-1017-on-a-60-page-pdf-what-text-extraction-misses-2efo"&gt;Earlier PDF evaluation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make slides searchable, the pipeline indexes native text alongside descriptions that Gemma 4 31B generates from rendered slides. During refresh, LibreOffice renders the deck to PDF. The pipeline checks that the page count matches the slide count, then rasterizes visible slides using their original slide numbers. A Japanese prompt asks Gemma to describe the figure’s subject, layout and legible labels, preserve English abbreviations, and include small numbers or legend entries only when it can read them.&lt;/p&gt;

&lt;p&gt;When retrieval selects a slide caption, DeepSeek receives its text and slide number. The source entry labels it as an AI-generated image description. A researcher can use it to locate a figure, then open the slide to check an axis label, legend or numerical value.&lt;/p&gt;

&lt;p&gt;The caption cache uses the rendered pixels and captioning configuration, so an unchanged image can reuse its description. The service also verifies that a retrieved caption matches the stored caption record and the indexed deck. This catches a mismatched record. A caption that misreads a legend can still pass the check. For one slide I reviewed, I tied a corrected caption to the exact rendered pixels so a replacement figure would not inherit the correction.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;November 19 production refresh&lt;/strong&gt; recorded &lt;strong&gt;143 files and 1,707 indexed chunks&lt;/strong&gt;. It retained descriptions for &lt;strong&gt;160 slides&lt;/strong&gt; and omitted descriptions for &lt;strong&gt;14 slides&lt;/strong&gt;. Those counts establish that captions entered the searchable index. The bilingual questions ran the previous day on native text. To measure the contribution of captions, I would build two indexes from the same document snapshot, enable captions in one, run the same figure questions with the same retrieval and generation settings, and grade the answers against the original slides.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In the bilingual trial, DeepSeek cited the handover note for the CSV directory and acknowledged that the same note could not establish the volume’s current free space. For researchers, the source location is as useful as the answer itself. They can check a documented procedure at the cited line, or use a caption retrieved by the system to find a figure and inspect its legend on the original slide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/nha6ki/series/46418"&gt;Local LLM Inference on AMD Ryzen AI Max&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/nha6ki/series/46541"&gt;DeepSeek-V4.1-Flash-1017 on Two DGX Sparks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>rag</category>
      <category>llm</category>
      <category>selfhosted</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>How We Deliver a Bilingual Research Digest with Python, ChatGPT, and Slack</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Thu, 19 Nov 2026 04:54:28 +0000</pubDate>
      <link>https://dev.to/nha6ki/how-we-deliver-a-bilingual-research-digest-with-python-chatgpt-and-slack-3do2</link>
      <guid>https://dev.to/nha6ki/how-we-deliver-a-bilingual-research-digest-with-python-chatgpt-and-slack-3do2</guid>
      <description>&lt;p&gt;Our neuroscience lab shares papers in English and Japanese on Slack through &lt;strong&gt;Research Literature Insights&lt;/strong&gt;. From Monday through Thursday, the digest recommends up to one paper a day. On Friday, it compares papers from the week.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the pieces fit together
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn79bp97es6gqplmnivlv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn79bp97es6gqplmnivlv.png" alt="Python collects paper records from OpenAlex and Europe PMC into Google Drive. ChatGPT Work reads the candidates and writes reports to Drive. An Ubuntu service fetches each report and sends English and Japanese posts to Slack." width="800" height="567"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A scheduled Python job on Ubuntu saves candidates and search logs to &lt;code&gt;discovery/YYYY-MM-DD.json&lt;/code&gt; on Google Drive. ChatGPT Work reads the inventory alongside the lab’s research profile, recommendation history and journal club records, then writes a report with source references back to Drive. A systemd user service fetches the report with rclone, validates it and posts both language versions through a Slack incoming webhook. SQLite tracks each post separately.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Report&lt;/th&gt;
&lt;th&gt;When analysis starts (Japan time)&lt;/th&gt;
&lt;th&gt;What Work produces&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Daily Paper Spotlight&lt;/td&gt;
&lt;td&gt;Monday–Thursday, 10 a.m.&lt;/td&gt;
&lt;td&gt;Up to one paper, with its findings, limitations and a reason to read it.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Weekly Research Review&lt;/td&gt;
&lt;td&gt;Friday, 10 a.m.&lt;/td&gt;
&lt;td&gt;A comparison drawing on the daily reports and the broader Monday–Thursday candidate pool. Delivery requires at least two sources and a supported theme or comparison.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Turning six research areas into searches
&lt;/h2&gt;

&lt;p&gt;Our original four keyword queries covered fMRI decoding but had no search for aesthetic preference. For our lab, even a study based entirely on ratings of paintings could be relevant. ChatGPT proposed six search areas based on the lab’s published research plans and projects. We adopted them on November 17. The profile gives current priorities precedence over past publications and sets no quota for any area. &lt;a href="https://en.zoelabo.com/projects" rel="noopener noreferrer"&gt;Chikazoe Laboratory research projects&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Research area&lt;/th&gt;
&lt;th&gt;Keyword queries&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Emotion and cognition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;emotion cognition&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sensory and taste representations&lt;/td&gt;
&lt;td&gt;&lt;code&gt;taste perception&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Aesthetic preference and individual taste&lt;/td&gt;
&lt;td&gt;&lt;code&gt;aesthetic preference&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mental and neural representations&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;brain representation&lt;/code&gt;, &lt;code&gt;fMRI decoding&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;fMRI foundation models and connectivity methods&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;fMRI foundation model&lt;/code&gt;, &lt;code&gt;functional connectivity&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Individual traits and psychiatric or neurological conditions&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;brain individual differences&lt;/code&gt;, &lt;code&gt;psychiatric neuroimaging&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Python runs these nine queries against both OpenAlex and Europe PMC. It also searches three journals (&lt;em&gt;NeuroImage&lt;/em&gt;, &lt;em&gt;Human Brain Mapping&lt;/em&gt; and &lt;em&gt;Nature Neuroscience&lt;/em&gt;), follows related works and citations to two seed papers, and searches adjacent topics. Four longer semantic queries capture questions such as whether a person’s preferences generalize across paintings, landscapes and faces.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Python chose the 50 abstracts
&lt;/h2&gt;

&lt;p&gt;For the November 19 daily report, we ran the selection workflow on live research records with Slack delivery disabled. Python retrieved 475 records with publication dates from October 21 through November 19. Merging duplicates left 445. To qualify, a record needed an abstract and identifiers that cleared checks against lab holdings and previous recommendations and posts. The title or abstract also had to pass a term check.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Its title contained at least one configured neuroscience or research-theme term. Adding terms such as &lt;code&gt;taste&lt;/code&gt; and &lt;code&gt;preference&lt;/code&gt; let behavioral studies qualify on their titles.&lt;/li&gt;
&lt;li&gt;If the title had no match, the abstract contained at least two distinct configured neuroscience terms.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;323 records qualified.&lt;/strong&gt; Among the 122 exclusions, 80 failed only the term check, 29 lacked only an abstract, 11 failed both checks and two had already been recommended and posted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7ec5z8x7zrjn2ka9mumm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7ec5z8x7zrjn2ka9mumm.png" alt="November 19 daily report. Python collected 475 records, merged them into 445 and kept 323. It passed 50 with abstracts and logged the remaining 273. Work examined nine items closely, including material outside the 50, and recommended one." width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python ranked eligible records in bands A–D according to which neuroscience, method and topic terms appeared together. Within each band, topic terms earned 12 points in the title and two in the abstract. A title containing &lt;code&gt;fMRI&lt;/code&gt; could reach band A on that word alone because it appeared in both the neuroscience and method lists.&lt;/p&gt;

&lt;p&gt;All 50 abstracts passed to Work came from band A. Another 69 A-band records fell outside the cap. For all 273 eligible records outside the 50, the screening log kept the title, identifier, rank and reason for omission. Work could follow an identifier to the public source. Across the search as a whole, 22 queries returned fewer records than their reported hit counts. The inventory’s &lt;code&gt;complete&lt;/code&gt; flag records whether the planned searches succeeded. We don’t know what fraction of relevant papers these searches retrieved.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Work chose what the lab should read
&lt;/h2&gt;

&lt;p&gt;To recommend a paper, Work must verify at least its abstract against the original source. It judges the strength of the evidence separately from the reason to read the paper. Does the result address a lab question, offer a usable method or suggest a study worth running? A replication or negative result can qualify. If the evidence or relevance is too weak, the daily report can contain zero recommendations.&lt;/p&gt;

&lt;p&gt;Work examined nine items for the November 19 report, consulting two full texts, six abstracts and one dataset description. The aesthetic-preference dataset came from outside the 50. Its unversioned record ranked 202nd, and Work followed it to the depositor’s description. &lt;a href="https://data.mendeley.com/datasets/fvs2xxb2pd/1" rel="noopener noreferrer"&gt;Dataset on Mendeley Data&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The report recommended Wu and Turrigiano’s mouse taste-learning study&lt;/strong&gt;, which Python had ranked 16th. The authors tracked responses in the gustatory cortex as mice learned an aversion to saccharin and as that aversion faded. Our lab had distinguished basic tastes from patterns of human insular activity. Work selected the paper because it suggested tracking the &lt;em&gt;same&lt;/em&gt; taste before and after learning changes its value. &lt;a href="https://doi.org/10.7554/eLife.108988" rel="noopener noreferrer"&gt;Taste-learning study on eLife&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Delivering both languages reliably
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo1f0jp1n9goykxprdg6j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo1f0jp1n9goykxprdg6j.png" alt="For a new daily report, Work writes and reads back a draft, then signals readiness. Ubuntu checks the dated files, validates the saved JSON and tracks eligible Slack posts by language." width="800" height="628"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Work and Ubuntu run on separate schedules. To keep Ubuntu from reading a half-written daily report, Work saves &lt;code&gt;draft-YYYY-MM-DD&lt;/code&gt;, reads it back, then creates &lt;code&gt;ready-YYYY-MM-DD&lt;/code&gt;. When creating a production report, Ubuntu looks for exactly one draft and one ready marker with the expected filenames for that date. It checks the date, &lt;code&gt;status="ready"&lt;/code&gt; and &lt;code&gt;test_only=false&lt;/code&gt; in the draft, then saves the JSON to Drive and compares the downloaded bytes with the validated draft. For the weekly report, Work validates the JSON before saving and checks the exported document afterward.&lt;/p&gt;

&lt;p&gt;If English reaches Slack and the Japanese request times out, resending both messages could post English twice. SQLite tracks a separate delivery state for each language. The sender marks a post as sent after Slack returns HTTP 200 with an &lt;code&gt;ok&lt;/code&gt; body. On retry, it skips acknowledged posts. If delivery is uncertain, the operator checks the channel before retrying. The paper enters the posting history once both languages are confirmed. &lt;a href="https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks/" rel="noopener noreferrer"&gt;Slack’s incoming webhook documentation&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;AI disclosure: This article documents my own technical setup and results. An LLM was used to help draft, organize, and edit the English text. I remain responsible for its technical accuracy.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>automation</category>
      <category>ai</category>
      <category>chatgpt</category>
    </item>
    <item>
      <title>Running FSL FEAT: Configuration and Output Checks</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Mon, 16 Nov 2026 12:19:44 +0000</pubDate>
      <link>https://dev.to/nha6ki/running-fsl-feat-configuration-and-output-checks-5497</link>
      <guid>https://dev.to/nha6ki/running-fsl-feat-configuration-and-output-checks-5497</guid>
      <description>&lt;p&gt;The &lt;a href="https://dev.to/nha6ki/a-step-by-step-guide-to-fmri-registration-with-fsl-and-ants-1m17"&gt;registration article in this series&lt;/a&gt; starts with a motion-corrected BOLD time series. Here, we focus on saving a FEAT configuration, running it from a Linux terminal, and inspecting the resulting images and processing records.&lt;/p&gt;

&lt;p&gt;The initial configuration and visual checks require a graphical desktop session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scope:&lt;/strong&gt; The example runs motion correction and brain masking in native functional space, with smoothing and temporal filtering disabled. It teaches FEAT configuration and output inspection; it does not define a complete preprocessing pipeline. The commands follow official documentation but have not been tested end to end on imaging data.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Establish what the input contains
&lt;/h2&gt;

&lt;p&gt;Use a single-echo, 4D human BOLD NIfTI image with whole-brain coverage. For this example, the run should not already have undergone motion correction, spatial smoothing, or temporal filtering. Keep the original file unchanged.&lt;/p&gt;

&lt;p&gt;Before processing, establish:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The repetition time (TR) and number of stored volumes.&lt;/li&gt;
&lt;li&gt;Whether initial non-steady-state volumes are still present or were already discarded.&lt;/li&gt;
&lt;li&gt;What corrections, if any, were applied during reconstruction or earlier processing.&lt;/li&gt;
&lt;li&gt;Which acquisition metadata and fieldmap images are available for distortion correction.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use the acquisition records and accompanying metadata to resolve these questions. A filename such as &lt;code&gt;bold.nii.gz&lt;/code&gt; does not describe the processing history.&lt;/p&gt;

&lt;p&gt;FSL must already be installed and configured in the terminal. See &lt;a href="https://dev.to/nha6ki/installing-fsl-and-fix-on-linux-legacy-rmatlab-setup-and-modern-python-fix-381j"&gt;Installing FSL and FIX on Linux&lt;/a&gt; for setup. FIX and ANTs are not required for this article.&lt;/p&gt;

&lt;p&gt;Create a fresh working directory for this trial and replace the example input path. The &lt;code&gt;mktemp&lt;/code&gt; command creates a uniquely named directory under &lt;code&gt;fsl-feat-tutorial&lt;/code&gt;; keep it with your processing records. Run the following blocks in the &lt;strong&gt;same Bash session&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p &lt;span class="s2"&gt;"$HOME/fsl-feat-tutorial"&lt;/span&gt;
&lt;span class="nv"&gt;WORK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$(mktemp -d "&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;/fsl-feat-tutorial/run01_trial_XXXXXX&lt;span class="s2"&gt;")"&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"$WORK"&lt;/span&gt;

&lt;span class="nv"&gt;WORK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$(pwd -P)"&lt;/span&gt;
&lt;span class="nv"&gt;BOLD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/absolute/path/to/sub-001_task-rest_bold.nii.gz"&lt;/span&gt;
&lt;span class="nv"&gt;OUT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$WORK/preproc.feat"&lt;/span&gt;

&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;FSLOUTPUTTYPE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;NIFTI_GZ

&lt;span class="k"&gt;for&lt;/span&gt; cmd &lt;span class="k"&gt;in&lt;/span&gt; feat Feat fslinfo fslhd fslval fslmaths fsleyes&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nb"&gt;command&lt;/span&gt; -v &lt;span class="s2"&gt;"$cmd"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Missing command: %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$cmd"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;span class="nb"&gt;test&lt;/span&gt; -r &lt;span class="s2"&gt;"$BOLD"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'ERROR: Cannot read %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$BOLD"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
cat &lt;span class="s2"&gt;"$FSLDIR/etc/fslversion"&lt;/span&gt;

fslinfo &lt;span class="s2"&gt;"$BOLD"&lt;/span&gt;
fslhd &lt;span class="s2"&gt;"$BOLD"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"$WORK/input_header.txt"&lt;/span&gt;
cat &lt;span class="s2"&gt;"$FSLDIR/etc/fslversion"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"$WORK/fsl_version.txt"&lt;/span&gt;

&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Input: %s\nOutput: %s\nSave setup as: %s\n'&lt;/span&gt; \
  &lt;span class="s2"&gt;"$BOLD"&lt;/span&gt; &lt;span class="s2"&gt;"$OUT"&lt;/span&gt; &lt;span class="s2"&gt;"$WORK/design.fsf"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see &lt;code&gt;Missing command&lt;/code&gt; or &lt;code&gt;ERROR&lt;/code&gt;, resolve the problem before continuing. These interactive blocks report problems but do not automatically stop the shell.&lt;/p&gt;

&lt;p&gt;Inspect the header and compare the volume count and TR with the acquisition metadata. Check the temporal units when interpreting &lt;code&gt;pixdim4&lt;/code&gt;; FEAT's TR field uses seconds. Investigate discrepancies rather than editing the header simply to make values agree. The &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/utilities/fslutils.html" rel="noopener noreferrer"&gt;FSL utilities documentation&lt;/a&gt; describes the inspection tools used here.&lt;/p&gt;

&lt;p&gt;Also inspect the input images before processing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fsleyes &lt;span class="s2"&gt;"$BOLD"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check brain coverage, orientation labels, and obvious artifacts across time. This gives you a baseline for comparison with the processed images. The example assumes that the default reference—the middle volume of the retained run—is usable. If it is severely corrupted, review the reference choice before running FEAT; the &lt;a href="https://fsl.fmrib.ox.ac.uk/fslcourse/graduate/lectures/practicals/feat0/" rel="noopener noreferrer"&gt;FSL FEAT practical&lt;/a&gt; explains the alternative reference option.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Save a complete FEAT configuration
&lt;/h2&gt;

&lt;p&gt;Start the FEAT GUI on a Linux desktop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Feat &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Select &lt;strong&gt;First-level analysis&lt;/strong&gt; and &lt;strong&gt;Preprocessing&lt;/strong&gt;. In this mode, registration can still run, so its settings must also be reviewed.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Data&lt;/strong&gt; tab, select one 4D input and use the full input and output paths printed above. Paste the actual paths into the GUI, not the shell variable names &lt;code&gt;$BOLD&lt;/code&gt; and &lt;code&gt;$OUT&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Check &lt;strong&gt;Total volumes&lt;/strong&gt; and &lt;strong&gt;TR&lt;/strong&gt;. Set &lt;strong&gt;Delete volumes&lt;/strong&gt; to the number of initial volumes that still need removal. Use &lt;code&gt;0&lt;/code&gt; if the intended initial volumes were already discarded. There is no universal number to delete. If you later fit a task model, its event times must refer to the retained time series.&lt;/p&gt;

&lt;h3&gt;
  
  
  Settings for this example
&lt;/h3&gt;

&lt;p&gt;Use the following settings for the configuration exercise. For research data, choose acquisition-specific corrections and downstream processing as part of the study's analysis plan before running the pipeline.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;Setting&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Pre-stats: motion correction&lt;/td&gt;
&lt;td&gt;MCFLIRT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alternative reference image&lt;/td&gt;
&lt;td&gt;Off; use the default middle-volume reference&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BET brain extraction&lt;/td&gt;
&lt;td&gt;On&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Spatial smoothing FWHM&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;0&lt;/code&gt; mm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Intensity normalization&lt;/td&gt;
&lt;td&gt;Off&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Temporal filtering&lt;/td&gt;
&lt;td&gt;Highpass off; Lowpass off if exposed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Perfusion subtraction&lt;/td&gt;
&lt;td&gt;Off&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MELODIC ICA&lt;/td&gt;
&lt;td&gt;Off&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B0 unwarping&lt;/td&gt;
&lt;td&gt;Off for this limited example; see below&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Slice timing correction&lt;/td&gt;
&lt;td&gt;None for this example; see below&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Registration&lt;/td&gt;
&lt;td&gt;Disable initial high-resolution, main structural, and standard-space registration&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;FEAT's BET option creates a functional brain mask. It does not replace extracting the T1w brain for the registration article. MCFLIRT estimates rigid-body motion between volumes; see its &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/registration/mcflirt.html" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;Intensity normalization&lt;/strong&gt; off, FEAT still applies one common intensity-scaling factor to the entire 4D run. This differs from normalizing each volume separately, as explained in the &lt;a href="https://fsl.fmrib.ox.ac.uk/fslcourse/graduate/lectures/practicals/feat0/" rel="noopener noreferrer"&gt;FSL FEAT practical&lt;/a&gt;. Consequently, output intensities should not be expected to equal input intensities.&lt;/p&gt;

&lt;p&gt;Three choices need particular care:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Distortion correction:&lt;/strong&gt; Plan any required susceptibility-distortion correction before running the study pipeline. This example leaves EPI distortion uncorrected. Enabling FEAT's fieldmap-based B0 unwarping also changes the required inputs and registration settings, so revise the configuration accordingly. See &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/registration/fugue.html" rel="noopener noreferrer"&gt;FUGUE&lt;/a&gt; and the &lt;a href="https://fsl.fmrib.ox.ac.uk/fslcourse/graduate/lectures/practicals/registration/" rel="noopener noreferrer"&gt;registration practical&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Slice timing:&lt;/strong&gt; Do not infer acquisition order from the number of slices. Decide whether to apply correction using the sequence metadata and planned analysis. The setting above records its omission; it does not establish that correction is unnecessary.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smoothing and temporal filtering:&lt;/strong&gt; Select these together with the denoising and statistical analysis plan. Both are disabled in this example.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In &lt;strong&gt;Misc&lt;/strong&gt;, optionally disable the progress watcher if you prefer to open the report yourself. Use &lt;strong&gt;Save&lt;/strong&gt; to write the complete configuration to the printed &lt;code&gt;design.fsf&lt;/code&gt; path, then close the GUI without pressing &lt;strong&gt;Go&lt;/strong&gt;. The next step runs the saved configuration from the terminal.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/task_fmri/feat/user_guide.html" rel="noopener noreferrer"&gt;FEAT user guide&lt;/a&gt; documents these controls and the saved setup format. If reusing a setup from an older FSL version, load it into the current GUI, review it, and save it again, as advised in the &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/task_fmri/feat/faq.html" rel="noopener noreferrer"&gt;FEAT FAQ&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Run the saved setup from the terminal
&lt;/h2&gt;

&lt;p&gt;Confirm that the output path in &lt;code&gt;design.fsf&lt;/code&gt; matches &lt;code&gt;$OUT&lt;/code&gt;. The file, rather than the shell variable, determines where FEAT writes its results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;less &lt;span class="s2"&gt;"$WORK/design.fsf"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then launch the job:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; ! -s &lt;span class="s2"&gt;"$WORK/design.fsf"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'ERROR: Save the FEAT setup first.\n'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -e &lt;span class="s2"&gt;"$OUT"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'ERROR: %s already exists; use a fresh working directory and save a new FEAT setup.\n'&lt;/span&gt; &lt;span class="s2"&gt;"$OUT"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
&lt;span class="k"&gt;else&lt;/span&gt;
  feat &lt;span class="s2"&gt;"$WORK/design.fsf"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"$WORK/feat_launch.log"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For each new trial, repeat the working-directory setup in Section 1 and save the FEAT configuration with the corresponding paths. A separate working directory keeps each trial's configuration, launch log, metadata, and QC images together. FEAT can append &lt;code&gt;+&lt;/code&gt; to an existing output directory name; the guard above helps avoid checking an older run by mistake.&lt;/p&gt;

&lt;p&gt;Read &lt;code&gt;feat_launch.log&lt;/code&gt; if the launch fails. During processing, use the FEAT report and its linked logs to follow progress. On a system using a job scheduler, a returned shell prompt may only indicate submission; wait for the processing jobs to finish before inspecting final outputs.&lt;/p&gt;

&lt;p&gt;On a desktop, open the report once it exists:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;xdg-open &lt;span class="s2"&gt;"$OUT/report.html"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a remote server without a desktop, view the report and images on a graphical machine. Keep the report's associated files together.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Check files and dimensions
&lt;/h2&gt;

&lt;p&gt;After processing finishes, inspect these outputs. The image names below assume the &lt;code&gt;NIFTI_GZ&lt;/code&gt; output setting used above.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;th&gt;What to inspect&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;filtered_func_data.nii.gz&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Processed 4D BOLD run&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mask.nii.gz&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Functional brain mask&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;example_func.nii.gz&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Reference image used by FEAT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mc/prefiltered_func_data_mcf.par&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Motion estimates, one row per retained volume&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;design.fsf&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Configuration recorded inside the output directory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;report.html&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Processing report and links to logs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The name &lt;code&gt;filtered_func_data&lt;/code&gt; does not prove that a particular filter was enabled. Interpret it alongside &lt;code&gt;design.fsf&lt;/code&gt; and the processing report. See the &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/task_fmri/feat/feat_output.html" rel="noopener noreferrer"&gt;FEAT output reference&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fslinfo &lt;span class="s2"&gt;"$OUT/filtered_func_data.nii.gz"&lt;/span&gt;

&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Input volumes: '&lt;/span&gt;
fslval &lt;span class="s2"&gt;"$BOLD"&lt;/span&gt; dim4
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Output volumes: '&lt;/span&gt;
fslval &lt;span class="s2"&gt;"$OUT/filtered_func_data.nii.gz"&lt;/span&gt; dim4
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Motion-parameter rows: '&lt;/span&gt;
awk &lt;span class="s1"&gt;'END { print NR }'&lt;/span&gt; &lt;span class="s2"&gt;"$OUT/mc/prefiltered_func_data_mcf.par"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the input contains &lt;code&gt;N&lt;/code&gt; volumes and you requested deletion of &lt;code&gt;D&lt;/code&gt;, expect &lt;code&gt;N - D&lt;/code&gt; output volumes and the same number of motion-parameter rows. A mismatch needs investigation before any downstream work.&lt;/p&gt;

&lt;p&gt;Check that the report reflects the intended settings and that its logs contain no unresolved failures. File presence and a plausible volume count are necessary checks, but they do not establish acceptable image quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Inspect the images and motion estimates
&lt;/h2&gt;

&lt;p&gt;Create a temporal mean for inspection. Check the brain mask against FEAT's reference image, which retains tissue outside the mask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p &lt;span class="s2"&gt;"$WORK/qc"&lt;/span&gt;
fslmaths &lt;span class="s2"&gt;"$OUT/filtered_func_data.nii.gz"&lt;/span&gt; -Tmean &lt;span class="s2"&gt;"$WORK/qc/mean_bold.nii.gz"&lt;/span&gt;

fsleyes &lt;span class="s2"&gt;"$OUT/example_func.nii.gz"&lt;/span&gt; &lt;span class="s2"&gt;"$OUT/mask.nii.gz"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In FSLeyes, display the mask as a colored overlay and adjust its opacity. Inspect axial, coronal, and sagittal views. Look for missing cortex or cerebellum and substantial inclusion of non-brain tissue.&lt;/p&gt;

&lt;p&gt;Open &lt;code&gt;qc/mean_bold.nii.gz&lt;/code&gt; to assess signal within the retained mask. Check apparent signal loss against the original BOLD data, the reference image, and the mask; zeros introduced by masking do not by themselves demonstrate acquisition-related dropout.&lt;/p&gt;

&lt;p&gt;Then inspect the time series itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fsleyes &lt;span class="s2"&gt;"$OUT/filtered_func_data.nii.gz"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Move through time or use movie playback. Look for abrupt shifts, disappearing coverage, slice artifacts, or isolated corrupted volumes. A temporal mean can hide problems confined to a few frames.&lt;/p&gt;

&lt;p&gt;Review the motion plots in the FEAT report. In the MCFLIRT parameter file, the first three columns are rotations in radians and the final three are translations in millimeters in FSL's coordinate convention. These six parameters are not framewise displacement.&lt;/p&gt;

&lt;p&gt;Motion correction cannot remove every motion-related signal artifact. Large movements and signal outliers may require additional handling or exclusion under a study's predefined QC criteria. FSL's &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/registration/motion_outliers.html" rel="noopener noreferrer"&gt;motion outliers documentation&lt;/a&gt; explains why realignment alone is insufficient. No universal pass/fail threshold is assumed here.&lt;/p&gt;

&lt;p&gt;Record the QC decision and its reason for each run, including any rerun with revised settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Connect the output to the next stage
&lt;/h2&gt;

&lt;p&gt;The output remains in functional space. It does not automatically meet the input requirements of the &lt;a href="https://dev.to/nha6ki/a-step-by-step-guide-to-fmri-registration-with-fsl-and-ants-1m17"&gt;FSL and ANTs registration tutorial&lt;/a&gt;. Verify those requirements, including whether any required distortion correction has been performed, before using &lt;code&gt;filtered_func_data.nii.gz&lt;/code&gt; as that article's &lt;code&gt;bold_preproc.nii.gz&lt;/code&gt;. Create the registration reference from the same BOLD time series to which you will apply the transforms.&lt;/p&gt;

&lt;p&gt;For ICA denoising, retain the full FEAT directory and its processing history. This example has ICA and registration disabled, so it does &lt;strong&gt;not&lt;/strong&gt; create a complete FIX input. The &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/resting_state/fix.html" rel="noopener noreferrer"&gt;FIX documentation&lt;/a&gt; requires additional ICA and registration outputs, including structural-image information. Adding an ICA decomposition alone does not satisfy that requirement.&lt;/p&gt;

&lt;p&gt;Before processing more participants, resolve the remaining acquisition-specific choices and inspect a representative run. Keep the input identity, FSL version, saved configuration, report, and QC notes together so that the processing can be reviewed and repeated.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;AI disclosure: An LLM was used to help draft, organize, and edit the English text and command examples. I remain responsible for the article's technical accuracy.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>neuroimaging</category>
      <category>neuroscience</category>
      <category>linux</category>
      <category>fsl</category>
    </item>
    <item>
      <title>A Step-by-Step Guide to fMRI Registration with FSL and ANTs</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Mon, 16 Nov 2026 10:10:26 +0000</pubDate>
      <link>https://dev.to/nha6ki/a-step-by-step-guide-to-fmri-registration-with-fsl-and-ants-1m17</link>
      <guid>https://dev.to/nha6ki/a-step-by-step-guide-to-fmri-registration-with-fsl-and-ants-1m17</guid>
      <description>&lt;p&gt;This tutorial explains how to register functional MRI data to a participant's T1-weighted anatomical image and then to an MNI template. Each step introduces the required inputs, the command to run, its outputs, and how to inspect the result.&lt;/p&gt;

&lt;p&gt;We use FSL's boundary-based EPI registration and ANTs' nonlinear anatomical registration. This tutorial presents one workflow combining the two tools. Processing runs from a Linux terminal; visual inspection uses FSLeyes in a graphical desktop session.&lt;/p&gt;

&lt;p&gt;My earlier article, &lt;a href="https://dev.to/nha6ki/installing-fsl-and-fix-on-linux-legacy-rmatlab-setup-and-modern-python-fix-381j"&gt;Installing FSL and FIX on Linux&lt;/a&gt;, covers the FSL setup. ANTs must also be installed and available on your &lt;code&gt;PATH&lt;/code&gt;; see the &lt;a href="https://github.com/ANTsX/ANTs/wiki/Installing-ANTs-release-binaries" rel="noopener noreferrer"&gt;ANTs installation guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scope:&lt;/strong&gt; The examples follow the linked official documentation and use generic filenames. These exact commands have not been validated end to end on an imaging dataset. This tutorial starts with prepared inputs; it does not cover a complete fMRI preprocessing pipeline.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvwldt6x8vgjnho7yha4q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvwldt6x8vgjnho7yha4q.png" alt="Flat illustration representing EPI, individual T1w, and MNI template spaces." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Understand the three spaces
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Space&lt;/th&gt;
&lt;th&gt;Image used here&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Functional EPI space&lt;/td&gt;
&lt;td&gt;Mean of a motion-corrected BOLD run&lt;/td&gt;
&lt;td&gt;Reference for the functional data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Individual anatomical space&lt;/td&gt;
&lt;td&gt;The same participant's T1w image&lt;/td&gt;
&lt;td&gt;Anatomical reference for EPI registration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Standard space&lt;/td&gt;
&lt;td&gt;FSL's MNI152 T1 2 mm template&lt;/td&gt;
&lt;td&gt;Destination for spatial normalization&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;There are two separate tasks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Estimate a transformation:&lt;/strong&gt; determine the spatial relationship between images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apply a transformation:&lt;/strong&gt; resample an image using that relationship and a chosen output grid.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We estimate EPI-to-T1w registration with FSL and T1w-to-MNI registration with ANTs. We then apply the transformations to the BOLD time series in two stages.&lt;/p&gt;

&lt;p&gt;The two-stage example makes each transformation explicit, at the cost of an additional resampling step. For a production workflow, compatible transformations can be composed to resample the BOLD data once. Intermediate registration checks can still use 3D reference images; they do not require resampling the full time series twice.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Prepare the inputs
&lt;/h2&gt;

&lt;p&gt;Use a separate working directory containing these files:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File&lt;/th&gt;
&lt;th&gt;Required contents&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;bold_preproc.nii.gz&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A 4D BOLD run, motion-corrected to a common EPI reference, still in functional space, and retaining anatomical contrast in its temporal mean&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;T1w.nii.gz&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The participant's whole-head T1w image&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Any susceptibility-distortion correction required by your acquisition should already be applied consistently to the BOLD data used here. This article does not cover motion correction, distortion correction, or ICA denoising. Registration does not replace these steps.&lt;/p&gt;

&lt;p&gt;Use an anatomical image with adequate tissue contrast, and address substantial intensity bias before registration. The next subsection creates and checks the brain-extracted T1w image needed for registration.&lt;/p&gt;

&lt;p&gt;Run the following blocks in the same Bash session, from that working directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;FSLOUTPUTTYPE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;NIFTI_GZ

mkdir -p registration

&lt;span class="nv"&gt;MNI_BRAIN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$FSLDIR/data/standard/MNI152_T1_2mm_brain.nii.gz"&lt;/span&gt;
&lt;span class="nv"&gt;MNI_HEAD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$FSLDIR/data/standard/MNI152_T1_2mm.nii.gz"&lt;/span&gt;

check_registration_inputs&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;local&lt;/span&gt; image
  &lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="nv"&gt;missing&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0
  &lt;span class="k"&gt;for&lt;/span&gt; image &lt;span class="k"&gt;in&lt;/span&gt; bold_preproc.nii.gz T1w.nii.gz \
               &lt;span class="s2"&gt;"$MNI_BRAIN"&lt;/span&gt; &lt;span class="s2"&gt;"$MNI_HEAD"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; ! -r &lt;span class="s2"&gt;"$image"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
      &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'ERROR: Cannot read %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$image"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
      &lt;span class="nv"&gt;missing&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
    &lt;span class="k"&gt;fi&lt;/span&gt;
  &lt;span class="k"&gt;done&lt;/span&gt;
  &lt;span class="nb"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"$missing"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

check_registration_inputs

cat &lt;span class="s2"&gt;"$FSLDIR/etc/fslversion"&lt;/span&gt;
antsRegistration --version

fslhd bold_preproc.nii.gz
fslhd T1w.nii.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If an &lt;code&gt;ERROR&lt;/code&gt; message appears, resolve it before proceeding; subsequent commands do not stop automatically. Also resolve any missing commands. Record the software versions and the exact template used. “MNI space” alone is not a sufficiently specific template description for reproducible work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Extract the T1w brain with BET
&lt;/h3&gt;

&lt;p&gt;If you already have a suitable brain-extracted T1w image that has been visually inspected, use it and skip the BET command below. The subsequent commands refer to this image as &lt;code&gt;T1w_brain.nii.gz&lt;/code&gt;; adjust the path if your existing file has a different name.&lt;/p&gt;

&lt;p&gt;Otherwise, create a brain-extracted image from the whole-head T1w image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bet T1w.nii.gz T1w_brain.nii.gz -m

fsleyes T1w.nii.gz T1w_brain.nii.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;BET writes &lt;code&gt;T1w_brain.nii.gz&lt;/code&gt;; &lt;code&gt;-m&lt;/code&gt; additionally writes the binary mask &lt;code&gt;T1w_brain_mask.nii.gz&lt;/code&gt;. The mask is available for inspection but is not an input to the commands below.&lt;/p&gt;

&lt;p&gt;Adjust overlay opacity and inspect all three planes. Check that cortex and cerebellum are retained and that non-brain tissue around the skull and orbits is excluded. The brain-extracted image must retain the voxel grid and spatial mapping of &lt;code&gt;T1w.nii.gz&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This example uses BET's default fractional intensity threshold (&lt;code&gt;-f 0.5&lt;/code&gt;). If brain tissue is excluded, a lower &lt;code&gt;-f&lt;/code&gt; value may help; if too much non-brain tissue remains, a higher value may help. Inspect the result before changing the threshold, and check the extraction after each adjustment. No single threshold is appropriate for all images. See the &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/structural/bet.html" rel="noopener noreferrer"&gt;BET documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Continue only after BET completes successfully and the extraction is acceptable. Brain extraction removes non-brain tissue; it does not estimate the EPI-to-T1w registration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create the EPI reference
&lt;/h3&gt;

&lt;p&gt;Create an EPI reference from a BOLD run whose temporal mean retains anatomical contrast. Do not use voxelwise demeaned, temporally standardized, or residual data with a near-zero mean for this step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fslmaths bold_preproc.nii.gz -Tmean registration/epi_ref.nii.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A temporal mean of the transformed BOLD series is also used for the final visual check.&lt;/p&gt;

&lt;p&gt;Using the mean keeps the reference tied to the time series being transformed. A suitable SBRef is another option, but it must correspond spatially to the processed BOLD run; sharing a participant identifier is not enough.&lt;/p&gt;

&lt;p&gt;The header and arithmetic utilities used here are documented in the &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/utilities/fslutils.html" rel="noopener noreferrer"&gt;FSL utilities guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Register EPI to T1w
&lt;/h2&gt;

&lt;p&gt;FSL's &lt;code&gt;epi_reg&lt;/code&gt; uses the white-matter boundary of the anatomical image to help align EPI with T1w. It requires sufficient tissue contrast in the EPI image and a T1w image from which a usable white-matter boundary can be obtained. The script can generate the required white-matter segmentation; a separately prepared segmentation is not mandatory. See the &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/registration/epi_reg.html" rel="noopener noreferrer"&gt;official epi_reg documentation&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;epi_reg \
  --epi=registration/epi_ref.nii.gz \
  --t1=T1w.nii.gz \
  --t1brain=T1w_brain.nii.gz \
  --out=registration/epi_to_T1w
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--out&lt;/code&gt; is a basename, without &lt;code&gt;.nii.gz&lt;/code&gt;. The main outputs used below are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;registration/epi_to_T1w.nii.gz&lt;/code&gt;: the EPI reference resampled into T1w space.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;registration/epi_to_T1w.mat&lt;/code&gt;: the FSL transformation matrix.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This example does not supply fieldmaps to &lt;code&gt;epi_reg&lt;/code&gt;; it does not perform fieldmap-based distortion correction.&lt;/p&gt;

&lt;p&gt;Inspect the result before applying the matrix to the full run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fsleyes T1w.nii.gz registration/epi_to_T1w.nii.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adjust the overlay opacity and inspect axial, coronal, and sagittal slices. Look for consistent alignment of the brain outline and internal structures. Consider EPI coverage and signal dropout when interpreting differences; a dark region is not automatically a registration error.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Register T1w to the MNI template
&lt;/h2&gt;

&lt;p&gt;Use the brain-extracted T1w image as the moving image and the brain-extracted template as the fixed image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;antsRegistrationSyNQuick.sh \
  -d 3 \
  -f &lt;span class="s2"&gt;"$MNI_BRAIN"&lt;/span&gt; \
  -m T1w_brain.nii.gz \
  -o registration/T1w_to_MNI_ \
  -t s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://github.com/ANTsX/ANTs/blob/main/Scripts/antsRegistrationSyNQuick.sh" rel="noopener noreferrer"&gt;ANTs script&lt;/a&gt; defines &lt;code&gt;-t s&lt;/code&gt; as rigid, affine, and deformable SyN stages. Here, &lt;code&gt;-d 3&lt;/code&gt; specifies a three-dimensional registration.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Role in this workflow&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;-f&lt;/code&gt; in &lt;code&gt;antsRegistrationSyNQuick.sh&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Fixed image: the MNI template&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;-m&lt;/code&gt; in &lt;code&gt;antsRegistrationSyNQuick.sh&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Moving image: the participant's T1w brain&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;-r&lt;/code&gt; in &lt;code&gt;antsApplyTransforms&lt;/code&gt; (Section 5)&lt;/td&gt;
&lt;td&gt;Reference image defining the output grid&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These option meanings are command-specific: BET's &lt;code&gt;-m&lt;/code&gt;, for example, requests a mask.&lt;/p&gt;

&lt;p&gt;The relevant outputs are:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;T1w_to_MNI_0GenericAffine.mat&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Combined linear transformation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;T1w_to_MNI_1Warp.nii.gz&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Forward nonlinear displacement field&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;T1w_to_MNI_Warped.nii.gz&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Moving T1w brain image resampled into template space&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These files are under &lt;code&gt;registration/&lt;/code&gt;. Check the warped anatomy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fsleyes &lt;span class="s2"&gt;"$MNI_BRAIN"&lt;/span&gt; registration/T1w_to_MNI_Warped.nii.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inspect the cortex, ventricles, and cerebellum across multiple slices. Treat this configuration as a starting point and assess registration quality for your dataset.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Apply the transformations to the BOLD time series
&lt;/h2&gt;

&lt;p&gt;Apply the estimated transformations in the following order.&lt;/p&gt;

&lt;h3&gt;
  
  
  EPI space to T1w space
&lt;/h3&gt;

&lt;p&gt;Apply the same EPI-to-T1w matrix to every volume:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;applyxfm4D \
  bold_preproc.nii.gz \
  T1w.nii.gz \
  registration/bold_in_T1w.nii.gz \
  registration/epi_to_T1w.mat \
  -singlematrix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-singlematrix&lt;/code&gt; selects one matrix for the entire run. This assumes the volumes have already been motion-corrected into the reference space; it does not estimate or correct motion between volumes. The argument order is input, reference, output, matrix, then options (&lt;a href="https://pages.fmrib.ox.ac.uk/fsl/fslpy/_modules/fsl/wrappers/flirt.html" rel="noopener noreferrer"&gt;FSL wrapper source&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;T1w.nii.gz&lt;/code&gt; sets the intermediate output grid. This can create a large file when the anatomical resolution is finer than the functional resolution. Resampling to a finer grid does not increase the spatial detail acquired in the original BOLD data.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://fsl.fmrib.ox.ac.uk/fsl/docs/registration/flirt/user_guide.html" rel="noopener noreferrer"&gt;FLIRT user guide&lt;/a&gt; documents &lt;code&gt;applyxfm4D&lt;/code&gt; and its default sinc interpolation. Check your installed command's help before changing interpolation options.&lt;/p&gt;

&lt;h3&gt;
  
  
  T1w space to MNI space
&lt;/h3&gt;

&lt;p&gt;Apply the ANTs transformations to that intermediate time series:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;antsApplyTransforms \
  -d 3 \
  -e 3 \
  -i registration/bold_in_T1w.nii.gz \
  -r &lt;span class="s2"&gt;"$MNI_HEAD"&lt;/span&gt; \
  -o registration/bold_in_MNI.nii.gz \
  -n Linear \
  -t registration/T1w_to_MNI_1Warp.nii.gz \
  -t registration/T1w_to_MNI_0GenericAffine.mat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-d 3&lt;/code&gt; describes the spatial transformation, while &lt;code&gt;-e 3&lt;/code&gt; identifies the input as a time series. A 4D BOLD file does not require a four-dimensional spatial registration. The reference is a 3D image defining the output grid (&lt;a href="https://github.com/ANTsX/ANTs/wiki/Dimensionality-or-ImageDimension-option-in-ANTs" rel="noopener noreferrer"&gt;ANTs dimensionality guide&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;For this forward image transformation, list the nonlinear warp before the affine. ANTs uses a transform stack: the last-listed transform acts first. See the &lt;a href="https://github.com/ANTsX/ANTs/wiki/Forward-and-inverse-warps-for-warping-images%2C-pointsets-and-Jacobians" rel="noopener noreferrer"&gt;ANTs transform guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The full-head template supplies the output grid here; registration was estimated using the corresponding brain-extracted template. This relies on the two templates having matching geometry.&lt;/p&gt;

&lt;p&gt;The FSL matrix is used only by FSL in the first step. Do not pass &lt;code&gt;epi_to_T1w.mat&lt;/code&gt; directly to ANTs: FSL and ANTs transform representations are not interchangeable merely because both files end in &lt;code&gt;.mat&lt;/code&gt;. Combining the stages requires an explicit, validated conversion with the correct source and reference images.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Check the final output
&lt;/h2&gt;

&lt;p&gt;First compare the volume count and temporal spacing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fslval bold_preproc.nii.gz dim4
fslval registration/bold_in_MNI.nii.gz dim4

fslval bold_preproc.nii.gz pixdim4
fslval registration/bold_in_MNI.nii.gz pixdim4

fslhd registration/bold_in_MNI.nii.gz
fslhd &lt;span class="s2"&gt;"$MNI_HEAD"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the header output to check the following fields:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Fields&lt;/th&gt;
&lt;th&gt;What to check&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;dim1&lt;/code&gt;–&lt;code&gt;dim3&lt;/code&gt;, &lt;code&gt;pixdim1&lt;/code&gt;–&lt;code&gt;pixdim3&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Spatial dimensions and voxel sizes agree with the chosen output reference&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;qform/sform codes and matrices (&lt;code&gt;qto_xyz&lt;/code&gt; / &lt;code&gt;sto_xyz&lt;/code&gt; in &lt;code&gt;fslhd&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;The voxel-to-world mapping is consistent with the intended reference; investigate conflicting valid mappings&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;dim4&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The output retains the input number of time points&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;pixdim4&lt;/code&gt;, &lt;code&gt;time_units&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;The TR and its units are preserved&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Matching array dimensions alone does not establish that the output occupies the correct space. Header checks also do not replace visual inspection.&lt;/p&gt;

&lt;p&gt;Then inspect the temporal mean in standard space:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fslmaths registration/bold_in_MNI.nii.gz \
  -Tmean registration/mean_bold_in_MNI.nii.gz

fsleyes &lt;span class="s2"&gt;"$MNI_HEAD"&lt;/span&gt; registration/mean_bold_in_MNI.nii.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnzsll7dlb6t6gujeiidg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnzsll7dlb6t6gujeiidg.png" alt="Flat illustration of a monitor and magnifying glass representing visual inspection of image alignment." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before using the result downstream, confirm that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EPI aligns with the participant's T1w image.&lt;/li&gt;
&lt;li&gt;The warped T1w image aligns with the chosen template.&lt;/li&gt;
&lt;li&gt;Final BOLD coverage is plausible and no unexpected clipping or gross displacement appears.&lt;/li&gt;
&lt;li&gt;The time axis is preserved.&lt;/li&gt;
&lt;li&gt;The exact input files, software versions, commands, and template are recorded.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the final overlay looks wrong, return to the two intermediate overlays. A good T1w-to-MNI result cannot compensate for an incorrect EPI-to-T1w registration. Likewise, a correct spatial grid does not prove anatomical alignment.&lt;/p&gt;

&lt;p&gt;This workflow leaves both transformations and intermediate images available for inspection. That makes each stage understandable and gives you a clear place to investigate when the final result does not look right.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;AI disclosure: An LLM was used to help draft, organize, and edit the English text and command examples. I remain responsible for the article's technical accuracy.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>neuroimaging</category>
      <category>neuroscience</category>
      <category>linux</category>
      <category>fsl</category>
    </item>
    <item>
      <title>How I Used ChatGPT Dots to Build a Music-Pattern Catalogue</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Mon, 16 Nov 2026 08:29:56 +0000</pubDate>
      <link>https://dev.to/nha6ki/how-i-used-chatgpt-dots-to-build-a-music-pattern-catalogue-240f</link>
      <guid>https://dev.to/nha6ki/how-i-used-chatgpt-dots-to-build-a-music-pattern-catalogue-240f</guid>
      <description>&lt;p&gt;I wanted to build a site where someone could look up a musical pattern, hear a short example, and check what the source supports. I used ChatGPT Dots to research sources, prepare changes, run checks, and verify what reached the public site. I set the selection criteria, tested playback, and decided what to publish.&lt;/p&gt;

&lt;h2&gt;
  
  
  The original plan was smaller and slower
&lt;/h2&gt;

&lt;p&gt;On November 14, 2026, Dots proposed a small site with eight searchable examples and an initial target of three playable clips. The plan called for deciding whether to publish on November 27. I asked Dots to start the later steps immediately, then expanded the scope.&lt;/p&gt;

&lt;p&gt;The first Japanese listening site went live on November 14. We published &lt;a href="https://github.com/nha6ki/notable-musical-patterns/releases/tag/v1.0.0" rel="noopener noreferrer"&gt;v1.0.0&lt;/a&gt; on November 15, and I considered the project complete on November 16 after further refinements. By then, &lt;a href="https://nha6ki.github.io/notable-musical-patterns/en/" rel="noopener noreferrer"&gt;Notable Musical Patterns&lt;/a&gt; was a Japanese and English catalogue with &lt;strong&gt;16 source collections, 6,729 searchable records, and 2,983 catalogue entries with on-site audio&lt;/strong&gt;. The record count is not a count of distinct compositions. All dates are in Japan time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F81qomj5qd0ky4usvqcn2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F81qomj5qd0ky4usvqcn2.png" alt="English Notable Musical Patterns homepage showing the Alberti bass listening example and its four-note diagram" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The English homepage during development, showing a listening example and the Alberti bass pattern.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;What changed was both the pace and the deliverable. November 27 was the proposed publication decision date for the small site, not a deadline for the larger catalogue or the result of a separate run without my involvement.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I could delegate
&lt;/h2&gt;

&lt;p&gt;Early on, Dots spent too much time comparing individual scores and MIDI files while I was still looking for a broad range of candidates. I changed the order: define the musical feature, find public datasets, check the terms for commercial use, modification, and redistribution, then link likely examples to the feature. I reserved detailed checks of specific editions, recordings, and passages for decisions about what to present as a supported example or host as audio.&lt;/p&gt;

&lt;p&gt;That rule produced different outcomes. For Mutopia, the site hosts synthesized excerpts from passages checked against the relevant scores and MIDI files. These are not recordings of performances. For O’Neill’s 1903 collection, the site provides bibliographic and original-source references rather than hosting synthesized audio. The &lt;a href="https://github.com/nha6ki/notable-musical-patterns/blob/main/METHODOLOGY.md" rel="noopener noreferrer"&gt;collection and selection methodology&lt;/a&gt; describes those decisions.&lt;/p&gt;

&lt;p&gt;The site uses static HTML, CSS, and JavaScript on GitHub Pages. The &lt;a href="https://github.com/nha6ki/notable-musical-patterns/blob/main/docs/catalogue-search.js" rel="noopener noreferrer"&gt;browser-side search&lt;/a&gt; matches catalogue entries to clip metadata and feature records by stable ID. The &lt;a href="https://github.com/nha6ki/notable-musical-patterns/blob/main/tools/check_release.py" rel="noopener noreferrer"&gt;Python release checker&lt;/a&gt; checks record counts, local links, and whether audio files and credits match the catalogue. It does not test playback or establish that the music supports a label or that the audio is cleared for reuse. Checking the site in a browser was a separate step. It was how I noticed that the playback controls behaved differently across pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where I still had to steer
&lt;/h2&gt;

&lt;p&gt;Dots could carry out individual rounds of source research, but I repeatedly had to tell it to move on to the next round. I had already asked it to continue routine work without waiting for me. Early updates about brief pauses and restarts also made it hard to tell whether work was running or merely scheduled. I asked for updates only when there was a meaningful result, a blocker, or a decision I needed to make.&lt;/p&gt;

&lt;p&gt;From the point I handed this work to Dots on November 13 through the completion decision on November 16, the project chat contained &lt;strong&gt;898 messages: 325 from me and 573 from the assistant&lt;/strong&gt;. That includes progress updates but excludes automated runs, tool activity, and other chats. The count documents the conversation; it does not measure time saved.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nha6ki.github.io/notable-musical-patterns/en/" rel="noopener noreferrer"&gt;Try the catalogue&lt;/a&gt; · &lt;a href="https://github.com/nha6ki/notable-musical-patterns" rel="noopener noreferrer"&gt;Browse the source code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;AI was used to draft and revise this article.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>music</category>
      <category>chatgpt</category>
      <category>ai</category>
      <category>aiagents</category>
    </item>
    <item>
      <title>Detecting Missing HTCondor Nodes and Stale GPU Metrics with Prometheus and Slack</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Sat, 14 Nov 2026 00:36:24 +0000</pubDate>
      <link>https://dev.to/nha6ki/detecting-missing-htcondor-nodes-and-stale-gpu-metrics-with-prometheus-and-slack-402m</link>
      <guid>https://dev.to/nha6ki/detecting-missing-htcondor-nodes-and-stale-gpu-metrics-with-prometheus-and-slack-402m</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 6 of 6 in Building and Operating an HTCondor Pool for Research Computing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An HTCondor worker can disappear from the pool. A GPU worker can stay online while its VRAM collector stops writing. In the second case, Node Exporter may keep serving the same value on every scrape. Our lab guide routes both alerts to one Slack channel and identifies the worker and the failed check in each message.&lt;/p&gt;

&lt;p&gt;This walkthrough starts with the pool from Part 1 and the GPU textfile writer from Part 5. On the monitoring host, the example queries HTCondor and Prometheus once per poll. A local exercise reproduces the alert and recovery decisions without contacting the pool or Slack.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose what to monitor
&lt;/h2&gt;

&lt;p&gt;Keep two inventories on the monitoring host. Populate them from the machines you expect to serve and keep them across polls.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Inventory&lt;/th&gt;
&lt;th&gt;Identifier&lt;/th&gt;
&lt;th&gt;What one entry covers&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Execute nodes&lt;/td&gt;
&lt;td&gt;Exact HTCondor &lt;code&gt;Machine&lt;/code&gt; name, such as &lt;code&gt;worker.example.org&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;All visible slot ads for that machine. One remaining ad is enough for the presence check.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GPU workers&lt;/td&gt;
&lt;td&gt;Exact Prometheus &lt;code&gt;instance&lt;/code&gt; label, such as &lt;code&gt;192.0.2.10:9100&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;The worker’s &lt;code&gt;gpu_vram.prom&lt;/code&gt; file. The file can hold readings for several GPU UUIDs.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The lab guide adds newly observed targets every ten minutes. A worker that has never reported needs a manual entry. When retiring a target, stop its advertisement or scrape registration first so discovery cannot add it back. The example below uses two manually maintained files. Using only the latest query result as the inventory would silently drop the worker you want to detect.&lt;/p&gt;

&lt;h3&gt;
  
  
  Execute nodes
&lt;/h3&gt;

&lt;p&gt;Run &lt;code&gt;condor_status -af Machine | sort -u&lt;/code&gt; on the monitoring host. If a successful query omits an expected name, start counting at &lt;strong&gt;the first poll that observes the absence&lt;/strong&gt;. Collector ads can outlive a lost connection. An alert can therefore arrive more than 15 minutes after the workstation lost power. A nonzero exit or timeout makes the observation unknown. &lt;a href="https://htcondor.readthedocs.io/en/25.0/admin-manual/configuration-macros.html#CLASSAD_LIFETIME" rel="noopener noreferrer"&gt;HTCondor ClassAd lifetime&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The lab implementation has an extra step. A one-minute writer exports &lt;code&gt;htcondor_execute_node_up&lt;/code&gt; and retains the last good textfile if &lt;code&gt;condor_status&lt;/code&gt; fails. The lab notifier reads that file without checking its age. A retained zero can prolong an apparent outage, and a retained one can hide one. To diagnose that version, compare the file’s mtime and contents with the command’s current output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;status_file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/var/lib/node_exporter/textfile_collector/htcondor_execute_nodes.prom
stat -c &lt;span class="s1"&gt;'%y %n'&lt;/span&gt; &lt;span class="s2"&gt;"$status_file"&lt;/span&gt;
cat &lt;span class="s2"&gt;"$status_file"&lt;/span&gt;
condor_status -af Machine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example queries &lt;code&gt;condor_status&lt;/code&gt; directly. It needs neither this execute-node textfile nor the HTCondor exporter on port 9888.&lt;/p&gt;

&lt;h3&gt;
  
  
  GPU file updates
&lt;/h3&gt;

&lt;p&gt;On the GPU worker, Part 5’s writer refreshes &lt;code&gt;gpu_vram.prom&lt;/code&gt;. Node Exporter exposes the modification time of a successfully read file as &lt;code&gt;node_textfile_mtime_seconds&lt;/code&gt;. In Prometheus, run this instant query. Use the &lt;code&gt;job&lt;/code&gt; label from your scrape configuration in both selectors and in the script below. &lt;a href="https://github.com/prometheus/node_exporter#textfile-collector" rel="noopener noreferrer"&gt;Node Exporter textfile collector&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_textfile_mtime_seconds{job="node", file=~"(.*/)?gpu_vram[.]prom"}
and on (job, instance) (up{job="node"} == 1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the sample &lt;strong&gt;value&lt;/strong&gt; as the file mtime. In the HTTP API’s &lt;code&gt;[timestamp, "value"]&lt;/code&gt; pair, using the first element would make a newly queried old file appear fresh. Use one matching file per target. &lt;a href="https://prometheus.io/docs/prometheus/latest/querying/api/#instant-vectors" rel="noopener noreferrer"&gt;Prometheus instant-query results&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What the monitor receives&lt;/th&gt;
&lt;th&gt;How it treats that observation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A timestamp at least 900 seconds old&lt;/td&gt;
&lt;td&gt;The file already meets the alert threshold on this poll.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A successful vector with no row for an expected worker&lt;/td&gt;
&lt;td&gt;Start or continue the absence interval. A failed scrape, a removed target, or an unreadable file can all produce this result.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A failed API request, a warning, or an invalid result structure&lt;/td&gt;
&lt;td&gt;Mark the GPU query unknown for this poll. The execute-node check still has its own result.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Duplicate rows or an invalid timestamp for an identifiable instance&lt;/td&gt;
&lt;td&gt;Mark only that worker unknown and log the problem. Other valid rows can still be evaluated.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A zero-byte free-VRAM reading is valid. The check follows the &lt;strong&gt;file’s update time&lt;/strong&gt;. A current file can omit a card, so use the UUIDs from Part 5 to investigate an individual GPU.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decide when to alert and when to recover
&lt;/h2&gt;

&lt;p&gt;The lab guide uses 15 minutes for failure and 10 minutes for recovery. Its GPU check treats any file younger than 15 minutes as healthy. A writer could update once at 14:00, stop immediately, and still satisfy that test at 14:10. The example adds a tighter freshness requirement and checks for another write.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Transition&lt;/th&gt;
&lt;th&gt;Rule in the example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Execute node absent, or GPU file timestamp missing&lt;/td&gt;
&lt;td&gt;Alert after 15 minutes of observed absence. Minute 0 is the first omission in a successful query.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GPU file present but stale&lt;/td&gt;
&lt;td&gt;Alert on the first valid observation with file age ≥ 15 minutes. For example, a 14:00 mtime qualifies at 14:16 even if 14:16 is the first poll.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Execute node present again&lt;/td&gt;
&lt;td&gt;Recover after 10 minutes of valid polls that see the expected machine name.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GPU file updating again&lt;/td&gt;
&lt;td&gt;Recover after 10 minutes during which every observed file age is 0–120 seconds and the final mtime is later than the first.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For either check, an unknown observation, a backward step in the poll clock, or a gap &lt;strong&gt;greater than three minutes&lt;/strong&gt; breaks the pending time window. An open incident stays open. A single fresh write can start the recovery window. If the file ages past two minutes, that window resets. Keep the monitoring host, Prometheus host, and worker clocks synchronized. The example treats future-dated files as unknown.&lt;/p&gt;

&lt;p&gt;The display and notification thresholds serve different purposes. Part 5 hides VRAM at &lt;strong&gt;90 seconds&lt;/strong&gt;. At 100 seconds, the graph can already show a gap while the file still qualifies for this recovery check. &lt;strong&gt;15 minutes&lt;/strong&gt; controls when a stale file warrants a Slack alert.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up the monitoring host
&lt;/h2&gt;

&lt;p&gt;The example uses Python 3’s standard library on Linux. For both checks, use an account that can query the intended HTCondor pool and reach the Prometheus API. By default the program uses &lt;code&gt;http://127.0.0.1:9090&lt;/code&gt;; change the endpoint in the script if Prometheus is elsewhere. Grafana is optional. Run these checks under the same account that will own the timer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;set&lt;/span&gt; -o pipefail
condor_status -af Machine &lt;span class="o"&gt;|&lt;/span&gt; sort -u
curl -fsSG http://127.0.0.1:9090/api/v1/query \
  --data-urlencode &lt;span class="s1"&gt;'query=node_textfile_mtime_seconds{job="node",file=~"(.*/)?gpu_vram[.]prom"} and on(job,instance) (up{job="node"} == 1)'&lt;/span&gt;
mkdir -p ~/.local/bin ~/.config/systemd/user
install -d -m 700 ~/.config/htcondor-watch
touch ~/.config/htcondor-watch/&lt;span class="o"&gt;{&lt;/span&gt;expected_nodes,gpu_instances&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;expected_nodes&lt;/code&gt;, enter one HTCondor machine name per line. In &lt;code&gt;gpu_instances&lt;/code&gt;, enter one Prometheus instance per line. Use the exact names in your inventory, keeping the port on GPU instances. An empty file disables that check. Both files must exist. Blank lines and lines beginning with &lt;code&gt;#&lt;/code&gt; are ignored.&lt;/p&gt;

&lt;p&gt;For delivery, enable &lt;strong&gt;Incoming Webhooks&lt;/strong&gt; on your Slack app, choose &lt;strong&gt;Add New Webhook to Workspace&lt;/strong&gt;, and authorize the intended channel. Save the URL as the only line of the file below. The URL contains a secret. &lt;a href="https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks/" rel="noopener noreferrer"&gt;Slack incoming webhooks&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;umask&lt;/span&gt; 077 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; touch ~/.config/htcondor-watch/slack_webhook&lt;span class="o"&gt;)&lt;/span&gt;
chmod 600 ~/.config/htcondor-watch/slack_webhook
nano ~/.config/htcondor-watch/slack_webhook
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;/p&gt;
  Monitoring script · save as ~/.local/bin/watch_pool.py
  &lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;fcntl&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timezone&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;HTTPException&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;

&lt;span class="no"&gt;CONFIG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;home&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="s2"&gt;".config/htcondor-watch"&lt;/span&gt;
&lt;span class="no"&gt;DATA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;home&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="s2"&gt;".local/state/htcondor-watch"&lt;/span&gt;
&lt;span class="no"&gt;FAIL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;RECOVER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;MAX_GAP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;FRESH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;900&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;  &lt;span class="c1"&gt;# seconds&lt;/span&gt;
&lt;span class="no"&gt;QUERY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'node_textfile_mtime_seconds{job="node",file=~"(.*/)?gpu_vram[.]prom"} '&lt;/span&gt;
         &lt;span class="s1"&gt;'and on (job, instance) (up{job="node"} == 1)'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CONFIG&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splitlines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lstrip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;machines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"condor_status"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-af"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Machine"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kt"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;gpu_times&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"http://127.0.0.1:9090/api/v1/query?"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlencode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;QUERY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;reply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"success"&lt;/span&gt;
            &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"warnings"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Prometheus returned an error or warning"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"resultType"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"vector"&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"expected a Prometheus instant vector"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;times&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"metric"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"instance"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"missing instance label"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;sample&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;times&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
                &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;times&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;times&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;OverflowError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;times&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;times&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_source&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OSError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HTTPException&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;KeyError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SubprocessError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{fetch.__name__}: {exc}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;gpu_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;times&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;times&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"unknown"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;times&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"missing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="n"&gt;stamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;times&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isfinite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stamp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{name}: ambiguous or invalid VRAM file timestamp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"unknown"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;FAIL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"stale"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"fresh"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="no"&gt;FRESH&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="s2"&gt;"aging"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;previous&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"last"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"last"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"unknown"&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;previous&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;previous&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="no"&gt;MAX_GAP&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bad&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;good&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_stamp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"unknown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"missing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"stale"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;good&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_stamp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"bad"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"bad"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"alerted"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"stale"&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"bad"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;FAIL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"alerted"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"alert"&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;

    &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"bad"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"alerted"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"aging"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;good&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_stamp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"good"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;good&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_stamp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;stamp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"good"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;RECOVER&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stamp&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"first_stamp"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;rec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;alerted&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;good&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_stamp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"recover"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;tmp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DATA&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="s2"&gt;"state.tmp"&lt;/span&gt;
    &lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;allow_nan&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DATA&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="s2"&gt;"state.json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;secret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CONFIG&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="s2"&gt;"slack_webhook"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;req&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="s2"&gt;"ok"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"unexpected Slack acknowledgment"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deliver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;pending&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;pending&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"retry_after"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="n"&gt;batch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pending&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;batch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HTTPError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Retry-After"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isascii&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isdigit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;
            &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"retry_after"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt;
            &lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;SystemExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Slack HTTP {exc.code}; pending events retained"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OSError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HTTPException&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;SystemExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Slack delivery unconfirmed ({type(exc).__name__})"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;del&lt;/span&gt; &lt;span class="n"&gt;pending&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;batch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"retry_after"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;poll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DATA&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="s2"&gt;"state.json"&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"targets"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;records&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"targets"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;pending&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setdefault&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;nodes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gpus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"expected_nodes"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"gpu_instances"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;observations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;nodes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;visible&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;read_source&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;machines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;nodes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"unknown"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;visible&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"present"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;visible&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="s2"&gt;"missing"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;observations&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"node:"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;gpus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;times&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;read_source&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gpu_times&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;gpus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;gpu_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;times&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;observations&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"gpu:"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;retired&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;records&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;observations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;del&lt;/span&gt; &lt;span class="n"&gt;records&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;retired&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;observed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;observations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;records&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setdefault&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;observed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;utc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromtimestamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;observed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"%Y-%m-%d %H:%M:%SZ"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;pending&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{utc}  {action.upper()}  {key}  ({status})"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;deliver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;umask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mo"&gt;0o077&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="no"&gt;DATA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mo"&gt;0o700&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exist_ok&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DATA&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="s2"&gt;"monitor.lock"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fcntl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fcntl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;LOCK_EX&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;poll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What happens when Slack is unavailable?
&lt;/h3&gt;

&lt;p&gt;Each poll stores the incident state and any newly detected transitions together in &lt;code&gt;~/.local/state/htcondor-watch/state.json&lt;/code&gt; before it tries the webhook. Each message line carries the &lt;strong&gt;UTC detection time&lt;/strong&gt;. If an alert and a recovery both occur during a delivery outage, the monitor retains both in order. It sends up to ten events per poll and removes that batch only after an HTTP 200 response with the body &lt;code&gt;ok&lt;/code&gt;. HTTP 429 defers the next send according to &lt;code&gt;Retry-After&lt;/code&gt;; polling continues in the meantime. &lt;a href="https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks/#handling_errors" rel="noopener noreferrer"&gt;Slack webhook responses&lt;/a&gt; · &lt;a href="https://docs.slack.dev/apis/web-api/rate-limits/#responding-to-rate-limiting-conditions" rel="noopener noreferrer"&gt;Slack rate limits&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The file lock serializes overlapping invocations. A timeout after Slack accepted a message, or a crash before the local acknowledgment is saved, can still cause a duplicate. Deleting the state file discards open incidents and unsent messages. Removing a target from the inventory retires it on the next poll. Any transitions already waiting for delivery retain their original timestamps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run the local exercise
&lt;/h3&gt;

&lt;p&gt;Save this as &lt;code&gt;exercise.py&lt;/code&gt; beside &lt;code&gt;watch_pool.py&lt;/code&gt;, then run &lt;code&gt;python3 ~/.local/bin/exercise.py&lt;/code&gt;. It calls the same transition code with one simulated poll per minute, using an in-memory record and no webhook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;watch_pool&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;gpu_status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transition&lt;/span&gt;

&lt;span class="n"&gt;t0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1_700_000_000&lt;/span&gt;
&lt;span class="n"&gt;worker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"worker:9100"&lt;/span&gt;
&lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;minute&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file_minute&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;minute&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;
    &lt;span class="n"&gt;readings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;file_minute&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;t0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;file_minute&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;gpu_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;readings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stamp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{minute:2d} min  {action}  {status}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;# No file timestamp from minute 0 through minute 15.&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;         &lt;span class="c1"&gt;# A single write at minute 16.&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;38&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;# A new write at every poll from minute 27 onward.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The local exercise produces two lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;15 min  alert  missing
37 min  recover  fresh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy5uqgdnp5i1zclol6mbj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy5uqgdnp5i1zclol6mbj.png" alt="The monitor alerts at minute 15. A single GPU file update at minute 16 leaves the incident open. Updates resume every minute at minute 27, and the monitor records recovery at minute 37." width="799" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With these same synthetic observations, the evaluation function from the lab guide qualified for recovery at minute 26 after the single write at minute 16. In this example that write is already three minutes old by minute 19, so the recovery window resets. Minute 27 starts a new window. At minute 37 it is ten minutes long and the mtime has advanced.&lt;/p&gt;

&lt;h3&gt;
  
  
  Schedule one poll per minute
&lt;/h3&gt;

&lt;p&gt;Save these units under &lt;code&gt;~/.config/systemd/user/&lt;/code&gt; on the monitoring host.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;htcondor-watch.service&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[Unit]&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Check&lt;/span&gt; &lt;span class="nc"&gt;HTCondor&lt;/span&gt; &lt;span class="n"&gt;advertisements&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="no"&gt;GPU&lt;/span&gt; &lt;span class="n"&gt;metrics&lt;/span&gt;

&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;oneshot&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;python3&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;watch_pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;htcondor-watch.timer&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[Unit]&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Poll&lt;/span&gt; &lt;span class="nc"&gt;HTCondor&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="no"&gt;GPU&lt;/span&gt; &lt;span class="n"&gt;monitoring&lt;/span&gt; &lt;span class="n"&gt;every&lt;/span&gt; &lt;span class="n"&gt;minute&lt;/span&gt;

&lt;span class="k"&gt;[Timer]&lt;/span&gt;
&lt;span class="na"&gt;OnStartupSec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30s&lt;/span&gt;
&lt;span class="na"&gt;OnUnitActiveSec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1min&lt;/span&gt;
&lt;span class="na"&gt;AccuracySec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1s&lt;/span&gt;

&lt;span class="k"&gt;[Install]&lt;/span&gt;
&lt;span class="na"&gt;WantedBy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl --user daemon-reload
systemctl --user start htcondor-watch.service
systemctl --user &lt;span class="nb"&gt;enable&lt;/span&gt; --now htcondor-watch.timer
systemctl --user list-timers htcondor-watch.timer
journalctl --user -u htcondor-watch.service -n 30 --no-pager
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The user service inherits its manager’s environment. If a shell query succeeds but the timer logs errors, check the account’s HTCondor configuration, credentials, and &lt;code&gt;PATH&lt;/code&gt;. To run from boot and after logout, enable lingering for the service account with &lt;code&gt;loginctl enable-linger "$USER"&lt;/code&gt;, obtaining administrator authorization if required. If the monitoring host stops, it cannot report its own outage to Slack. &lt;a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.timer.html" rel="noopener noreferrer"&gt;systemd timers&lt;/a&gt; · &lt;a href="https://www.freedesktop.org/software/systemd/man/latest/loginctl.html" rel="noopener noreferrer"&gt;User lingering&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a delivery test, use a test-channel webhook and a separate test inventory and state (a dedicated test account is sufficient). Add &lt;code&gt;htcondor-alert-test.invalid&lt;/code&gt; to its execute-node list. After 15 minutes of successful polls that omit it, expect one alert event. Removing that name retires the target. Use the local exercise above to check the recovery path without interrupting a real workstation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Follow up on a notification
&lt;/h2&gt;

&lt;p&gt;For an execute-node alert, repeat &lt;code&gt;condor_status -af Machine | sort -u&lt;/code&gt; on the monitoring host. Check the exact advertised name, then pool selection, connectivity, and the worker’s &lt;code&gt;condor_startd&lt;/code&gt;. The alert establishes that the name was missing from the monitored view.&lt;/p&gt;

&lt;p&gt;For a message ending in &lt;code&gt;ALERT  gpu:192.0.2.10:9100  (missing)&lt;/code&gt;, look up that target on Prometheus’s &lt;strong&gt;Targets&lt;/strong&gt; page. Then check the GPU worker locally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvidia-smi --query-gpu=uuid,memory.free --format=csv
systemctl status gpu-vram-export.timer --no-pager
journalctl -u gpu-vram-export.service -n 20 --no-pager
curl -fsS http://localhost:9100/metrics &lt;span class="o"&gt;|&lt;/span&gt;
  grep -E &lt;span class="s1"&gt;'^gpu_vram_free_bytes|^node_textfile_mtime_seconds.*gpu_vram[.]prom|^node_textfile_scrape_error'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the driver responds but the file mtime is old, inspect the writer and timer. If local readings are fresh but the series is absent in Prometheus, compare the scrape error and the &lt;code&gt;job&lt;/code&gt;, &lt;code&gt;instance&lt;/code&gt;, and &lt;code&gt;file&lt;/code&gt; labels with the query and inventory. A GPU recovery message establishes that this worker’s file resumed updating. Check the per-UUID rows to see which cards contributed readings.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;AI assistance was used in drafting and editing this article.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>prometheus</category>
      <category>monitoring</category>
      <category>devops</category>
    </item>
    <item>
      <title>Monitoring HTCondor Jobs and GPU Memory with Prometheus and Grafana</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Sat, 14 Nov 2026 00:35:59 +0000</pubDate>
      <link>https://dev.to/nha6ki/monitoring-htcondor-jobs-and-gpu-memory-with-prometheus-and-grafana-2c5f</link>
      <guid>https://dev.to/nha6ki/monitoring-htcondor-jobs-and-gpu-memory-with-prometheus-and-grafana-2c5f</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 5 of 6 in Building and Operating an HTCondor Pool for Research Computing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One RTX 3060 on our lab dashboard showed &lt;strong&gt;4.18 GiB of free VRAM&lt;/strong&gt;. On the same worker, the unclaimed HTCondor slot advertised &lt;strong&gt;0 GPUs&lt;/strong&gt;. A job requesting one GPU could not match that slot at the time of the snapshot. To investigate an idle job, I check its scheduler first, then the resources the worker advertises, and finally the physical card.&lt;/p&gt;

&lt;h2&gt;
  
  
  What each measurement covers
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;th&gt;Scope&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Is the job idle, running, or held?&lt;/td&gt;
&lt;td&gt;Job ads from the queried HTCondor schedulers (&lt;code&gt;schedd&lt;/code&gt; daemons)&lt;/td&gt;
&lt;td&gt;One visible job process per ad in the queue&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;How much CPU or RAM has HTCondor allocated?&lt;/td&gt;
&lt;td&gt;Partitionable parent slot ads from the collector&lt;/td&gt;
&lt;td&gt;Resources offered to HTCondor on the worker&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;How busy is the host, and how much RAM is available?&lt;/td&gt;
&lt;td&gt;Linux metrics from Node Exporter&lt;/td&gt;
&lt;td&gt;The whole host, including other workloads&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;How much VRAM is free?&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;nvidia-smi&lt;/code&gt; on the worker, published through Node Exporter’s textfile collector&lt;/td&gt;
&lt;td&gt;One physical GPU, identified by UUID, on the non-MIG machines described here&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Our lab configuration scrapes two kinds of endpoints every 15 seconds. A custom exporter serves &lt;code&gt;htcondor_*&lt;/code&gt; metrics on port 9888. Node Exporter serves host metrics and our custom &lt;code&gt;gpu_vram_*&lt;/code&gt; readings on port 9100. The lab exporter waits 15 seconds &lt;strong&gt;after&lt;/strong&gt; each collection pass, and the GPU writer is scheduled on a 30-second timer. Consecutive scrapes can repeat the same reading.&lt;/p&gt;

&lt;p&gt;The screenshots below are excerpts from our dashboard. The smaller collectors at the end of the article are examples for reproducing the queue-count, CPU-allocation, and VRAM queries. The lab dashboard also uses slot and job-detail metrics from its full exporter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Connect Prometheus and Grafana
&lt;/h3&gt;

&lt;p&gt;Start with a working pool, Prometheus, Grafana, and Node Exporter on a Linux worker. The monitoring account needs permission to run &lt;code&gt;condor_q&lt;/code&gt; and &lt;code&gt;condor_status&lt;/code&gt; against the pool. For GPU readings, the worker also needs a working NVIDIA driver and the textfile writer. If you do not already export the custom metrics, set up the relevant collector below before testing the panels.&lt;/p&gt;

&lt;p&gt;Add these two entries under your existing &lt;code&gt;scrape_configs&lt;/code&gt; key in &lt;code&gt;prometheus.yml&lt;/code&gt;. Replace the example worker address here and in the queries. In this example Prometheus and the HTCondor exporter run directly on the same host.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;scrape_configs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;job_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;htcondor&lt;/span&gt;
    &lt;span class="na"&gt;scrape_interval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;15s&lt;/span&gt;
    &lt;span class="na"&gt;scrape_timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;12s&lt;/span&gt;
    &lt;span class="na"&gt;static_configs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;targets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'127.0.0.1:9888'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;job_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node&lt;/span&gt;
    &lt;span class="na"&gt;scrape_interval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;15s&lt;/span&gt;
    &lt;span class="na"&gt;static_configs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;targets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'192.0.2.10:9100'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Validate and reload the configuration. This command assumes a systemd unit named &lt;code&gt;prometheus.service&lt;/code&gt;. &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/" rel="noopener noreferrer"&gt;Prometheus configuration and reload&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;promtool check config /etc/prometheus/prometheus.yml &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    sudo systemctl &lt;span class="nb"&gt;kill&lt;/span&gt; --kill-whom=main --signal=HUP prometheus.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Grafana, add a Prometheus data source with a URL reachable &lt;strong&gt;from the Grafana server&lt;/strong&gt;. Use &lt;code&gt;http://127.0.0.1:9090&lt;/code&gt; if both services run directly on the same host. Choose &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt;, then run &lt;code&gt;up{job=~"htcondor|node"}&lt;/code&gt; in Explore. Expect one series with value &lt;code&gt;1&lt;/code&gt; per configured target. An absent target and a listed target returning &lt;code&gt;0&lt;/code&gt; are different conditions. Check Prometheus’s &lt;strong&gt;Targets&lt;/strong&gt; page for the discovered endpoints and their last scrape errors. To save any query below as a panel, add a visualization to a dashboard, select this data source, paste the expression in &lt;strong&gt;Code&lt;/strong&gt; mode, and save the dashboard. &lt;a href="https://grafana.com/docs/grafana/latest/datasources/prometheus/configure/" rel="noopener noreferrer"&gt;Grafana Prometheus data source&lt;/a&gt; · &lt;a href="https://prometheus.io/docs/concepts/jobs_instances/" rel="noopener noreferrer"&gt;Prometheus target health&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Count jobs on the schedulers you intend to monitor
&lt;/h2&gt;

&lt;p&gt;Our original &lt;code&gt;htcondor_jobs_running&lt;/code&gt; gauge counts running jobs visible to the service account’s &lt;code&gt;condor_q -json&lt;/code&gt; on its default schedd. The default is the caller’s jobs, with exceptions for queue superusers and site configuration. If that query fails, the lab code resets both the running count and &lt;code&gt;htcondor_schedd_up&lt;/code&gt; to zero.&lt;/p&gt;

&lt;p&gt;For a pool view, the lab exporter separately calls &lt;code&gt;condor_q -global -allusers -json&lt;/code&gt;, parses its output as one JSON document, and groups the ads by schedd, owner, and job status. A command or JSON parsing error clears those series. The example exporter below queries an &lt;strong&gt;explicit list of schedds&lt;/strong&gt;. If one query fails it omits the whole queue snapshot, so a partial count cannot appear as a pool total. Both approaches count visible jobs currently in the queue. Short jobs can enter and leave between observations. &lt;a href="https://htcondor.readthedocs.io/en/25.0/man-pages/condor_q.html" rel="noopener noreferrer"&gt;HTCondor 25.0 condor_q&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a &lt;strong&gt;Jobs in queue by status&lt;/strong&gt; time-series panel, use one exporter for the pool. Two exporters observing the same jobs would double the sum.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sum by (job_status) (
  htcondor_allusers_jobs_by_owner_status{job="htcondor"}
  and on (job, instance) (htcondor_schedd_allusers_up{job="htcondor"} == 1)
  and on (job, instance) (up{job="htcondor"} == 1)
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Show &lt;code&gt;htcondor_schedd_allusers_up{job="htcondor"}&lt;/code&gt; and &lt;code&gt;up{job="htcondor"}&lt;/code&gt; alongside the count. Read them as queue-query health and scrape health, respectively. A valid empty snapshot has no count series. A valid snapshot with no held jobs has no &lt;code&gt;held&lt;/code&gt; series. If a health check fails, the filtered count also disappears. Leave gaps visible in Grafana (&lt;strong&gt;Connect null values → Never&lt;/strong&gt;). A stalled loop in the original exporter can leave both the counts and query health at their last values. The direct queue check below helps diagnose that case.&lt;/p&gt;

&lt;p&gt;If you want a single &lt;strong&gt;Held jobs&lt;/strong&gt; Stat to show a real zero, supply a zero for an exporter with no held series, then apply both health checks. With one healthy exporter and an empty queue this returns &lt;code&gt;0&lt;/code&gt;. A failed query or scrape leaves the Stat empty.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sum(
  (
    htcondor_allusers_jobs_by_owner_status{job="htcondor", job_status="held"}
    or on (job, instance) (0 * up{job="htcondor"})
  )
  and on (job, instance) (htcondor_schedd_allusers_up{job="htcondor"} == 1)
  and on (job, instance) (up{job="htcondor"} == 1)
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the monitoring host, run these commands as the exporter account. Add &lt;code&gt;schedd="schedd.example.org"&lt;/code&gt; to the &lt;strong&gt;count metric’s&lt;/strong&gt; selector in the panel query, using the same advertised name as in the command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_status -schedd -af Name
&lt;span class="nv"&gt;schedd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'schedd.example.org'&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -o pipefail
condor_q -name &lt;span class="s2"&gt;"$schedd"&lt;/span&gt; -allusers -nobatch -af JobStatus &lt;span class="o"&gt;|&lt;/span&gt; sort &lt;span class="o"&gt;|&lt;/span&gt; uniq -c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The left column is the count and the right column is the status code, including &lt;code&gt;1&lt;/code&gt; for idle, &lt;code&gt;2&lt;/code&gt; for running, and &lt;code&gt;5&lt;/code&gt; for held. Counts can change between the command and the scrape. A successful global query alone does not prove every expected schedd contributed. In Part 4’s A → B workflow, B has no job ad until DAGMan submits it. The DAGMan management job does have an ad, so it can contribute to &lt;code&gt;running&lt;/code&gt; while A is idle. Use &lt;code&gt;htcondor dag status &amp;lt;dagman-cluster-id&amp;gt;&lt;/code&gt; to inspect that particular workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare HTCondor CPU allocation with host activity
&lt;/h2&gt;

&lt;p&gt;For a partitionable parent slot, &lt;code&gt;TotalSlotCpus&lt;/code&gt; is its reported CPU capacity and &lt;code&gt;Cpus&lt;/code&gt; is the amount left in the parent. For one worker, sum the parent capacities and remaining CPUs separately, then calculate &lt;code&gt;100 × (capacity − remaining) / capacity&lt;/code&gt;. Dynamic children have already drawn from these parents. Counting the children again would inflate the totals. The same calculation for RAM uses &lt;code&gt;TotalSlotMemory&lt;/code&gt; and &lt;code&gt;Memory&lt;/code&gt; in MiB. The denominator is capacity advertised to HTCondor. &lt;a href="https://htcondor.readthedocs.io/en/25.0/classad-attributes/machine-classad-attributes.html" rel="noopener noreferrer"&gt;HTCondor machine ClassAd attributes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our exporter, &lt;code&gt;ip&lt;/code&gt; comes from the worker’s &lt;code&gt;StartdIpAddr&lt;/code&gt;, while &lt;code&gt;instance&lt;/code&gt; on that series identifies the &lt;strong&gt;exporter&lt;/strong&gt; on port 9888. On Node Exporter series, &lt;code&gt;instance&lt;/code&gt; identifies the &lt;strong&gt;worker&lt;/strong&gt; on port 9100. Confirm the address mapping before comparing panels, especially if you scrape by DNS name. The examples assume one worker per advertised IPv4 address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CPU allocated by HTCondor&lt;/strong&gt; · Use a Bar gauge or Time series, with &lt;strong&gt;Percent (0–100)&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100 * (
  htcondor_machine_cpu_allocation_ratio{job="htcondor", ip="192.0.2.10"}
  and on (job, instance) (htcondor_pool_up{job="htcondor"} == 1)
  and on (job, instance) (up{job="htcondor"} == 1)
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Host CPU time outside idle&lt;/strong&gt; · Use a Time series with the same unit. Compute a rate per logical CPU before averaging, and keep samples only while the worker’s scrape is healthy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100 * (1 - avg by (job, instance) (
  rate(node_cpu_seconds_total{job="node", instance="192.0.2.10:9100", mode="idle"}[5m])
))
and on (job, instance) (up{job="node"} == 1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first value is an allocation snapshot. The second is a five-minute average of non-idle host time, which includes Linux I/O wait. For example, allocating 12 of the 16 CPUs offered to HTCondor gives 75%. On a host with 32 logical CPUs, 12 continuously busy threads would account for 37.5% if the other CPUs remained idle. For host RAM, Node Exporter’s &lt;code&gt;node_memory_MemAvailable_bytes&lt;/code&gt; measures the kernel’s estimate of available memory. &lt;a href="https://prometheus.io/docs/prometheus/latest/querying/functions/#rate" rel="noopener noreferrer"&gt;Prometheus rate function&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuwaz8sji8x9j9pba4u6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuwaz8sji8x9j9pba4u6h.png" alt="Pool CPU allocation is 25.8%. Worker F’s allocation is 0%, and its red host CPU trace ends near 37%." width="800" height="464"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Worker F’s allocation bar reads 0%. At the right edge of the 24-hour plot, its host CPU trace is near 37%. The panels use different time windows and cannot identify which process accounts for the activity.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If a machine is absent or its allocation looks unexpected, inspect the source ads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_status -constraint &lt;span class="s1"&gt;'PartitionableSlot =?= True'&lt;/span&gt; \
  -af Machine Name StartdIpAddr TotalSlotCpus Cpus TotalSlotMemory Memory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A worker with only static slots, or with no supported IPv4 address in its parent ads, has no per-machine series in these collectors. The original lab code substitutes zero for missing numeric attributes. Check the raw values and a positive denominator before interpreting a surprising percentage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare slot availability with physical GPU memory
&lt;/h2&gt;

&lt;p&gt;On the worker, query each physical card. The three numeric columns are &lt;strong&gt;total, free, used&lt;/strong&gt;, in MiB.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvidia-smi --query-gpu=uuid,name,memory.total,memory.free,memory.used \
  --format=csv,noheader,nounits
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our writer multiplies the values by 1,048,576 and writes byte gauges to &lt;code&gt;gpu_vram.prom&lt;/code&gt;. Set Grafana’s unit to &lt;strong&gt;bytes (IEC)&lt;/strong&gt; and the legend to &lt;code&gt;{{machine}} · {{gpu_uuid}}&lt;/code&gt;. In the Part 2 sharing setup, two advertised GPU resources can point to the same card. To find the card a PyTorch job used, match the worker and physical UUID from that run. A model name alone can identify more than one card. Use the driver’s reported free value directly. NVIDIA can reserve part of the framebuffer for its own use. &lt;a href="https://docs.nvidia.com/deploy/nvidia-smi/index.html#fb-memory-usage" rel="noopener noreferrer"&gt;NVIDIA framebuffer memory fields&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fed7dbc0lfd2zzobb9ocw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fed7dbc0lfd2zzobb9ocw.png" alt="An unclaimed slot advertises zero GPUs, two busy slots advertise one GPU each, and the same worker’s RTX 3060 reports 4.18 GiB free." width="800" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The unclaimed slot offers 16 CPUs and 93.5 GiB of RAM, but has no GPU share left to match. The 4.18 GiB reading covers the card as a whole. These panels show the advertisements and driver reading captured by the dashboard. They do not identify which process used the VRAM.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For an actual idle job, run &lt;code&gt;condor_q -better-analyze 123.0&lt;/code&gt; on the submit host, substituting its job ID. That checks the job’s requests and match requirements. VRAM observed in Grafana can change before a job starts.&lt;/p&gt;

&lt;p&gt;To inspect the advertised slot inventory directly, set the constraint to the worker’s actual HTCondor machine name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_status -constraint &lt;span class="s1"&gt;'Machine == "worker.example.org"'&lt;/span&gt; -af Name State Activity Cpus Memory GPUs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Show the age of the GPU reading
&lt;/h3&gt;

&lt;p&gt;Stopping the GPU timer leaves Node Exporter able to serve the old file. Prometheus can keep reporting &lt;code&gt;up = 1&lt;/code&gt; and attach a new scrape timestamp to the same byte value. Node Exporter exposes the last modification time of a successfully read textfile &lt;strong&gt;as a metric value&lt;/strong&gt;. Graph the file age in seconds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;time() - node_textfile_mtime_seconds{job="node", file=~"(.*/)?gpu_vram[.]prom"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For &lt;strong&gt;Free VRAM by GPU&lt;/strong&gt;, use the following expression. It admits real zero-byte readings and drops a worker’s values when the target is down, the timestamp is missing, or the file is 90 seconds old. The lower bound also rejects future-dated files. Keep host clocks synchronized and use one matching file per scrape target.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gpu_vram_free_bytes{job="node"}
and on (job, instance) (up{job="node"} == 1)
and on (job, instance) (
  ((time() - node_textfile_mtime_seconds{job="node", file=~"(.*/)?gpu_vram[.]prom"}) &amp;gt;= 0) &amp;lt; 90
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both comparisons omit &lt;code&gt;bool&lt;/code&gt;, so they &lt;strong&gt;remove&lt;/strong&gt; samples that fail the test. The &lt;code&gt;and&lt;/code&gt; then keeps each card’s byte value only if its worker passes. For a current Stat panel, choose &lt;strong&gt;Instant&lt;/strong&gt; and end the dashboard time range at &lt;strong&gt;now&lt;/strong&gt;. For a history panel, choose &lt;strong&gt;Range&lt;/strong&gt; and leave gaps visible. &lt;a href="https://prometheus.io/docs/prometheus/latest/querying/operators/" rel="noopener noreferrer"&gt;PromQL operators&lt;/a&gt; · &lt;a href="https://grafana.com/docs/grafana/latest/datasources/prometheus/query-editor/" rel="noopener noreferrer"&gt;Grafana query types&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The 90-second display threshold is an example for the 30-second timer below, which sets &lt;code&gt;AccuracySec=1s&lt;/code&gt;. The lab guide’s timer omits that setting. systemd’s default accuracy window is one minute, so check observed intervals before adopting the same threshold on an existing worker. Part 6 uses a separate 15-minute alert threshold and an inventory of expected &lt;strong&gt;workers&lt;/strong&gt;. A current file can still omit one GPU on a multi-card worker. &lt;a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.timer.html#AccuracySec=" rel="noopener noreferrer"&gt;systemd timer accuracy&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Trace a missing reading
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -fsS http://localhost:9100/metrics &lt;span class="o"&gt;|&lt;/span&gt;
  grep -E &lt;span class="s1"&gt;'^(gpu_vram_free_bytes|node_textfile_mtime_seconds|node_textfile_scrape_error)'&lt;/span&gt;
systemctl status gpu-vram-export.timer --no-pager
journalctl -u gpu-vram-export.service -n 20 --no-pager
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Observation&lt;/th&gt;
&lt;th&gt;Next check&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Target listed, &lt;code&gt;up = 0&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Read the scrape error in Prometheus. Check connectivity from the Prometheus host.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Target up, file age increasing&lt;/td&gt;
&lt;td&gt;Check the timer’s last trigger and the writer’s exit status.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Target up, no matching mtime&lt;/td&gt;
&lt;td&gt;Check the configured textfile directory, file name, read permissions, and &lt;code&gt;node_textfile_scrape_error&lt;/code&gt;. This error gauge covers &lt;strong&gt;all&lt;/strong&gt; textfiles on the target.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fresh file, expected UUID missing&lt;/td&gt;
&lt;td&gt;Compare the driver’s UUID list and the exported rows with your inventory. In the original lab script, &lt;code&gt;gpu_vram_collector_success 1&lt;/code&gt; is written before the driver rows are read. It can appear even if no GPU produced a row.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Example collectors for the panel queries
&lt;/h2&gt;

&lt;p&gt;Use these listings if your installation lacks the custom metrics. Keep a single producer for each endpoint or output file. The first collector runs on the monitoring host, the second on each GPU worker.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;
  Monitoring host · job counts and CPU allocation
  &lt;p&gt;Save the following as &lt;code&gt;pool_metrics.py&lt;/code&gt;. It needs Python 3 and the HTCondor command-line tools. Each scrape reads each named schedd once and builds counts in memory before serving the result. If a schedd query fails, it omits &lt;strong&gt;all&lt;/strong&gt; queue counts for that scrape and serves &lt;code&gt;htcondor_schedd_allusers_up 0&lt;/code&gt;. The parent-slot query has its own health gauge. It queries the schedds and then the collector sequentially, with a three-second timeout per command. For two schedds the command time budget is nine seconds, plus overhead. For more schedds, allow more than &lt;code&gt;3 × (number of schedds + 1)&lt;/code&gt; seconds inside the scrape timeout and increase the scrape interval as needed. Prometheus requires the timeout to fit within the interval.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;collections&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ipaddress&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;wsgiref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;simple_server&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;make_server&lt;/span&gt;

&lt;span class="no"&gt;STATUS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"unexpanded"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"idle"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"running"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"removed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"completed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"held"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"transferring_output"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"suspended"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\t"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splitlines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\\"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"\\\\"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'"'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'\\"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"\\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;queue_samples&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;counts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;schedd&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;schedulers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"condor_q"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;schedd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-allusers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-nobatch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-af:t"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                  &lt;span class="s2"&gt;"Owner"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"JobStatus"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;schedd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;STATUS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"unknown"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'htcondor_allusers_jobs_by_owner_status{{schedd="{label(s)}",'&lt;/span&gt;
            &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'owner="{label(o)}",job_status="{k}"}} {n}'&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cpu_samples&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;capacity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defaultdict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;addr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;remaining&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"condor_status"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-constraint"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"PartitionableSlot =?= True"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                       &lt;span class="s2"&gt;"-af:t"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"StartdIpAddr"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"TotalSlotCpus"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Cpus"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;([0-9.]+):"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;addr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;remaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remaining&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isfinite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;remaining&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"invalid CPU capacity for {addr}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;ip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ipaddress&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IPv4Address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;pair&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="n"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;
            &lt;span class="n"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;remaining&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'htcondor_machine_cpu_allocation_ratio{{ip="{ip}"}} {(total-left)/total}'&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start_response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"PATH_INFO"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"/metrics"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;start_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"404 Not Found"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text/plain"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;queries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"htcondor_allusers_jobs_by_owner_status"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"htcondor_schedd_allusers_up"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;queue_samples&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"htcondor_machine_cpu_allocation_ratio"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"htcondor_pool_up"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cpu_samples&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;health&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;collect&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;queries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;samples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OSError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SubprocessError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{health}: {exc}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"# TYPE {metric} gauge"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"# TYPE {health} gauge"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{health} {ok}"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;start_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"200 OK"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text/plain; version=0.0.4; charset=utf-8"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;schedulers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromkeys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;schedulers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"usage: python3 pool_metrics.py SCHEDD_NAME [SCHEDD_NAME ...]"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;make_server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9888&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serve_forever&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the monitoring host, run the exporter in the foreground under the account that can query the pool. Replace the example name with a name from &lt;code&gt;condor_status -schedd -af Name&lt;/code&gt; and add other expected schedds as separate arguments. The exporter binds to loopback.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 pool_metrics.py schedd.example.org
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a second terminal on that host, run &lt;code&gt;curl -fsS http://127.0.0.1:9888/metrics&lt;/code&gt;. Look for both health gauges set to &lt;code&gt;1&lt;/code&gt;. A visible running or idle job produces a count. If the queue is empty, the job health gauge can still read &lt;code&gt;1&lt;/code&gt;. A partitionable slot with a supported address supplies a CPU series. Leave the exporter running while trying the panels.&lt;/p&gt;



&lt;br&gt;
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;
  GPU worker · update the textfile after a successful driver query
  &lt;p&gt;Save the following as &lt;code&gt;gpu_metrics.py&lt;/code&gt;. It checks the driver’s exit status and validates the rows it receives before replacing the file. It cannot detect an omitted card unless you compare its output with an expected UUID inventory. A failed call exits nonzero and leaves the last good file in place, so its age increases until a later success. A temporary file in the output directory keeps the rename atomic. Node Exporter reads only completed &lt;code&gt;*.prom&lt;/code&gt; files here. &lt;a href="https://github.com/prometheus/node_exporter#textfile-collector" rel="noopener noreferrer"&gt;Node Exporter textfile collector&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;tempfile&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\\"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"\\\\"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'"'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'\\"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"\\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;write_snapshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"uuid,name,memory.total,memory.free,memory.used"&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"nvidia-smi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"--query-gpu="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="s2"&gt;"--format=csv,noheader,nounits"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;machine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getfqdn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;kinds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"free"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"used"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;samples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;kind&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;kinds&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splitlines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;skipinitialspace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GPU-"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"invalid or duplicate GPU row: {row}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'machine="{machine}",gpu_uuid="{label(uuid)}",gpu_name="{label(name)}"'&lt;/span&gt;
        &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;free&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;used&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;free&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;used&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"invalid memory reading for {uuid}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mib&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kinds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;free&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;used&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'gpu_vram_{kind}_bytes{{{labels}}} {mib * 1024**2}\n'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nvidia-smi returned no GPUs"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;tempfile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NamedTemporaryFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"w"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"utf-8"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                     &lt;span class="n"&gt;delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"# TYPE gpu_vram_{kind}_bytes gauge\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writelines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fchmod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fileno&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mo"&gt;0o644&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unlink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;write_snapshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start Node Exporter with &lt;code&gt;--collector.textfile.directory=/var/lib/node_exporter/textfile_collector&lt;/code&gt; added to its existing arguments. Restart its service if you changed the arguments. On the worker, test one collection before scheduling it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo install -d -m 0755 /var/lib/node_exporter/textfile_collector
sudo install -m 0755 gpu_metrics.py /usr/local/bin/gpu_metrics.py
sudo python3 /usr/local/bin/gpu_metrics.py /var/lib/node_exporter/textfile_collector/gpu_vram.prom
curl -fsS http://localhost:9100/metrics &lt;span class="o"&gt;|&lt;/span&gt; grep &lt;span class="s1"&gt;'^gpu_vram_free_bytes'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expect one free-memory sample per UUID reported by the driver. Compare the UUIDs with the worker’s expected inventory. For an existing collection timer, update its service to use the &lt;code&gt;ExecStart&lt;/code&gt; below, then run &lt;code&gt;sudo systemctl daemon-reload&lt;/code&gt;. For a new installation, save these two units under &lt;code&gt;/etc/systemd/system/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;gpu-vram-export.service&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[Unit]&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Collect&lt;/span&gt; &lt;span class="no"&gt;NVIDIA&lt;/span&gt; &lt;span class="no"&gt;GPU&lt;/span&gt; &lt;span class="n"&gt;memory&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="nc"&gt;Exporter&lt;/span&gt;

&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;oneshot&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;python3&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;gpu_metrics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;node_exporter&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;textfile_collector&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;gpu_vram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prom&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;gpu-vram-export.timer&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[Unit]&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Refresh&lt;/span&gt; &lt;span class="no"&gt;NVIDIA&lt;/span&gt; &lt;span class="no"&gt;GPU&lt;/span&gt; &lt;span class="n"&gt;memory&lt;/span&gt; &lt;span class="n"&gt;measurements&lt;/span&gt;

&lt;span class="k"&gt;[Timer]&lt;/span&gt;
&lt;span class="na"&gt;OnBootSec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10s&lt;/span&gt;
&lt;span class="na"&gt;OnUnitActiveSec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30s&lt;/span&gt;
&lt;span class="na"&gt;AccuracySec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1s&lt;/span&gt;

&lt;span class="k"&gt;[Install]&lt;/span&gt;
&lt;span class="na"&gt;WantedBy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo systemctl daemon-reload
sudo systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; --now gpu-vram-export.timer
systemctl list-timers gpu-vram-export.timer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;br&gt;
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;AI assistance was used in drafting and editing this article.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>prometheus</category>
      <category>grafana</category>
      <category>devops</category>
    </item>
    <item>
      <title>Writing HTCondor DAG Files: Job Dependencies, Variables, and Concurrency Limits</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Sat, 14 Nov 2026 00:35:46 +0000</pubDate>
      <link>https://dev.to/nha6ki/writing-htcondor-dag-files-job-dependencies-variables-and-concurrency-limits-4mf5</link>
      <guid>https://dev.to/nha6ki/writing-htcondor-dag-files-job-dependencies-variables-and-concurrency-limits-4mf5</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 4 of 6 in Building and Operating an HTCondor Pool for Research Computing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our lab’s GPU tutorial defines three PyTorch runs with different training parameters. They share one submit file, and DAGMan admits one of the three nodes to the queue at a time. In a participant analysis, the final job also needs every participant’s result, even when those results come from different workers.&lt;/p&gt;

&lt;p&gt;This walkthrough starts with two Linux jobs and one line of data you can follow from worker to worker. It then applies the same file-transfer rules to the MAT-files from Part 3. The commands target HTCondor 25.0 LTS on the Ubuntu access point from Part 1. The outputs described below are what to check in your own run.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Pass a result from A to B
&lt;/h2&gt;

&lt;p&gt;A DAG is a directed graph with no cycles. Each &lt;code&gt;JOB&lt;/code&gt; line names a node and gives its HTCondor submit file. A &lt;code&gt;PARENT … CHILD …&lt;/code&gt; line makes the child eligible for submission after all its parents succeed. The submit files specify what each job runs and which files it receives.&lt;/p&gt;

&lt;p&gt;Create a fresh working directory on the access point and save the three files below in it. Keep the absolute path in &lt;code&gt;project&lt;/code&gt; for the later exercises. The workers need &lt;code&gt;/bin/echo&lt;/code&gt; and &lt;code&gt;/bin/cat&lt;/code&gt; at the paths shown.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir project &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; project
&lt;span class="nv"&gt;project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;my.dag&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JOB A A.submit
JOB B B.submit
PARENT A CHILD B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;A.submit&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;universe = vanilla
executable = /bin/echo
transfer_executable = False
arguments = sample-001
should_transfer_files = YES
when_to_transfer_output = ON_EXIT
output = A.out
error = A.err
log = A.log
queue 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;B.submit&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;universe = vanilla
executable = /bin/cat
transfer_executable = False
arguments = A.out
should_transfer_files = YES
transfer_input_files = A.out
when_to_transfer_output = ON_EXIT
output = B.out
error = B.err
log = B.log
queue 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A writes &lt;code&gt;sample-001&lt;/code&gt; to stdout. HTCondor returns stdout to &lt;code&gt;A.out&lt;/code&gt; on the access point. After A succeeds, DAGMan submits B, and HTCondor stages &lt;code&gt;A.out&lt;/code&gt; in B’s scratch directory. The dependency controls &lt;em&gt;when&lt;/em&gt; B can be submitted. The &lt;code&gt;transfer_input_files&lt;/code&gt; line gives B the data, so the workers can use separate filesystems. &lt;a href="https://htcondor.readthedocs.io/en/25.0/users-manual/file-transfer.html" rel="noopener noreferrer"&gt;HTCondor file transfer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Submit the &lt;strong&gt;DAG&lt;/strong&gt; once. The cluster number printed here belongs to the DAGMan management job. DAGMan will submit A and B itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_submit_dag my.dag
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While it is running, use the cluster number from that submission in place of &lt;code&gt;123&lt;/code&gt;. The first command reports workflow progress. The second lists only the currently queued node jobs for this DAG. A node waiting on a parent has no queued job yet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;dag_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;123
htcondor dag status &lt;span class="s2"&gt;"$dag_id"&lt;/span&gt;
condor_q -constraint &lt;span class="s2"&gt;"DAGManJobId == $dag_id"&lt;/span&gt; -af DAGNodeName ClusterId ProcId JobStatus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To verify the run, wait on the management job’s event log (&lt;code&gt;.dagman.log&lt;/code&gt;). A zero return from &lt;code&gt;condor_wait&lt;/code&gt; can also mean removal. Check the final status in the diagnostic log (&lt;code&gt;.dagman.out&lt;/code&gt;) and compare both outputs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; condor_wait -wait 300 my.dag.dagman.log &lt;span class="s2"&gt;"$dag_id.0"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    tail -n 1 my.dag.dagman.out
    &lt;span class="k"&gt;if&lt;/span&gt; tail -n 1 my.dag.dagman.out &lt;span class="o"&gt;|&lt;/span&gt; grep -Eq &lt;span class="s1"&gt;'EXITING WITH STATUS 0[[:space:]]*$'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
       &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; sample-001 &lt;span class="o"&gt;|&lt;/span&gt; cmp - A.out &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
       cmp A.out B.out&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
        &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Workflow and output verified'&lt;/span&gt;
    &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the wait times out, repeat the status query with the same ID. For a held node (&lt;code&gt;JobStatus&lt;/code&gt; 5), use its &lt;em&gt;own&lt;/em&gt; cluster and process ID to read &lt;code&gt;HoldReason&lt;/code&gt;, for example &lt;code&gt;condor_q 456.0 -af HoldReason&lt;/code&gt;. After a short DAG has already left the queue, its diagnostic log and output files remain available. &lt;a href="https://htcondor.readthedocs.io/en/25.0/automated-workflows/dagman-reference.html" rel="noopener noreferrer"&gt;DAGMan logs and job attributes&lt;/a&gt; · &lt;a href="https://htcondor.readthedocs.io/en/25.0/man-pages/condor_wait.html" rel="noopener noreferrer"&gt;condor_wait&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Choose the unit of work
&lt;/h2&gt;

&lt;p&gt;Give each node a unique name within the DAG. Several nodes can refer to the same submit file. An external node submit file has one &lt;code&gt;queue&lt;/code&gt; statement. With &lt;code&gt;queue 1&lt;/code&gt;, the node submits one job. With &lt;code&gt;queue 10&lt;/code&gt;, it submits one cluster of ten jobs under the default configuration. If one of those jobs fails, DAGMan normally treats the group as failed and removes the remaining jobs in that node. A POST script can affect the final node outcome, as shown in Section 5.&lt;/p&gt;

&lt;p&gt;A DAG line such as &lt;code&gt;RETRY Train 2&lt;/code&gt; allows up to two additional attempts for a node named &lt;code&gt;Train&lt;/code&gt;. Each attempt repeats the whole node, including its PRE script, jobs, and POST script if defined. Give each participant a separate node if you want to retry participants independently. &lt;a href="https://htcondor.readthedocs.io/en/25.0/automated-workflows/dagman-introduction.html" rel="noopener noreferrer"&gt;Node submit files&lt;/a&gt; · &lt;a href="https://htcondor.readthedocs.io/en/25.0/automated-workflows/dagman-completion.html" rel="noopener noreferrer"&gt;Node success and retries&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a preprocessing step A, parallel analyses B and C, and an aggregation step D, declare four &lt;code&gt;JOB&lt;/code&gt; lines and add these dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PARENT A CHILD B C
PARENT B C CHILD D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After A succeeds, B and C can be submitted independently. Available resources and submission limits determine whether they overlap. D waits for &lt;strong&gt;both&lt;/strong&gt; parents. If B fails and C succeeds, D stays blocked.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Pass per-node arguments with &lt;code&gt;VARS&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Two nodes can share one submit file. Create a separate directory for this exercise and save the following three files there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir &lt;span class="s2"&gt;"$project/vars"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"$project/vars"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;runs.dag&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JOB RUN1 run_job.submit
JOB RUN2 run_job.submit
VARS RUN1 idx="1" alpha="0.1"
VARS RUN2 idx="2" alpha="0.5"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;run_job.submit&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;universe = vanilla
executable = /usr/bin/python3
transfer_executable = False
arguments = train.py --idx $(idx) --alpha $(alpha)
should_transfer_files = YES
transfer_input_files = train.py
when_to_transfer_output = ON_EXIT
log = logs/run_$(idx).$(ClusterId).log
output = logs/run_$(idx).$(ClusterId).$(ProcId).out
error = logs/run_$(idx).$(ClusterId).$(ProcId).err
queue 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;train.py&lt;/code&gt;&lt;/strong&gt; prints its arguments so you can check the expansion without installing a training package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;

&lt;span class="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ArgumentParser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"--idx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"--alpha"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_args&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"idx={args.idx} alpha={args.alpha}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p logs
condor_submit_dag runs.dag
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;DAGMan supplies &lt;code&gt;idx&lt;/code&gt; and &lt;code&gt;alpha&lt;/code&gt; as submit macros. HTCondor transfers the Python script, and the worker supplies &lt;code&gt;/usr/bin/python3&lt;/code&gt;. After this DAG succeeds, &lt;code&gt;logs/run_1.*.out&lt;/code&gt; should contain &lt;code&gt;idx=1 alpha=0.1&lt;/code&gt;, and &lt;code&gt;logs/run_2.*.out&lt;/code&gt; should contain &lt;code&gt;idx=2 alpha=0.5&lt;/code&gt;. The index identifies the parameter set, and the cluster and process IDs identify the submitted job. &lt;a href="https://htcondor.readthedocs.io/en/25.0/automated-workflows/dagman-advance-functionality.html" rel="noopener noreferrer"&gt;DAGMan VARS&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Limit submitted GPU nodes with &lt;code&gt;CATEGORY&lt;/code&gt; and &lt;code&gt;MAXJOBS&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Our lab guide gives three GPU jobs different batch sizes through &lt;code&gt;VARS&lt;/code&gt;. Its GPU submit file queues one process per node. The following shortened template uses the same scheduling rule. Supply your GPU submit file, request the required GPU resources there, and use &lt;code&gt;$(batch_size)&lt;/code&gt; in the training arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JOB G1 gpu_job.submit
JOB G2 gpu_job.submit
JOB G3 gpu_job.submit
VARS G1 batch_size="1024"
VARS G2 batch_size="512"
VARS G3 batch_size="256"

CATEGORY G1 GPUJOB
CATEGORY G2 GPUJOB
CATEGORY G3 GPUJOB
MAXJOBS GPUJOB 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;MAXJOBS GPUJOB 1&lt;/code&gt; allows &lt;strong&gt;one submitted node cluster in this category in this DAG&lt;/strong&gt;. An idle or held job can keep its cluster in the queue and delay the next node. Consider two versions of the same submit file:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;In each GPU node’s submit file&lt;/th&gt;
&lt;th&gt;What one category slot allows&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;queue 1&lt;/code&gt; and &lt;code&gt;request_gpus = 1&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;One job from these three nodes can be queued at a time.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;queue 4&lt;/code&gt; and &lt;code&gt;request_gpus = 1&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;The admitted cluster contains four jobs. All four can run if the pool can satisfy their requests.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Other DAGs can submit GPU jobs at the same time. In Part 2’s pool, one advertised GPU resource can be a share of a physical card. This category limit therefore provides no guarantee of exclusive access to a physical GPU. &lt;a href="https://htcondor.readthedocs.io/en/25.0/automated-workflows/dagman-interaction.html#throttling-nodes-by-category" rel="noopener noreferrer"&gt;DAGMan category throttling&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Check a parent’s output with a POST script
&lt;/h2&gt;

&lt;p&gt;Suppose A exits zero but writes an empty file. B’s &lt;code&gt;cat&lt;/code&gt; can also exit zero on that file. Run a check on the access point after A’s job finishes and before B becomes eligible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir &lt;span class="s2"&gt;"$project/checks"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    cp &lt;span class="s2"&gt;"$project"&lt;/span&gt;/&lt;span class="o"&gt;{&lt;/span&gt;my.dag,A.submit,B.submit&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="s2"&gt;"$project/checks/"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"$project/checks"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Append these lines to this copy of &lt;code&gt;my.dag&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SCRIPT DEBUG verify.log STDERR POST A ./verify_a.sh $NODE $RETURN
SCRIPT PRE B /usr/bin/test -r A.out
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the POST script as &lt;code&gt;verify_a.sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/sh&lt;/span&gt;
&lt;span class="nv"&gt;node&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;
&lt;span class="nv"&gt;job_status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$job_status"&lt;/span&gt; != &lt;span class="s2"&gt;"0"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s: job returned %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$node"&lt;/span&gt; &lt;span class="s2"&gt;"$job_status"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
    &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; ! &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; sample-001 &lt;span class="o"&gt;|&lt;/span&gt; cmp -s - A.out&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s: A.out is missing or contains the wrong sample ID\n'&lt;/span&gt; &lt;span class="s2"&gt;"$node"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
    &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;chmod +x verify_a.sh
condor_submit_dag my.dag
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both scripts run on the access point. When a POST script runs, &lt;strong&gt;its exit status determines whether the node succeeds&lt;/strong&gt;. A cleanup command that exits zero can mask a failed job. This script checks &lt;code&gt;$RETURN&lt;/code&gt; first, so it also rejects a job killed by a signal. Only then does it check the bytes in &lt;code&gt;A.out&lt;/code&gt;. The &lt;code&gt;DEBUG&lt;/code&gt; clause captures the script’s stderr in &lt;code&gt;verify.log&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;B’s PRE script checks that the returned file is still readable immediately before submission. Under the default settings, a failed PRE script marks B failed and skips its jobs and POST script. &lt;a href="https://htcondor.readthedocs.io/en/25.0/automated-workflows/dagman-introduction.html" rel="noopener noreferrer"&gt;DAGMan scripts and return values&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Pause a workflow or resume after a failure
&lt;/h2&gt;

&lt;p&gt;To pause a running workflow, use the cluster number of the &lt;strong&gt;active DAGMan job&lt;/strong&gt; as &lt;code&gt;dag_id&lt;/code&gt;. A hold and a halt have different effects on work in progress. &lt;a href="https://htcondor.readthedocs.io/en/25.0/automated-workflows/dagman-interaction.html" rel="noopener noreferrer"&gt;Managing a running DAG&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;th&gt;How to continue&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;condor_hold "$dag_id"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Already queued node jobs continue. Running PRE and POST scripts are killed. DAGMan submits no new jobs while held.&lt;/td&gt;
&lt;td&gt;Inspect any partial files those scripts were writing, then use &lt;code&gt;condor_release "$dag_id"&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;htcondor dag halt "$dag_id"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;New PRE scripts and node submissions stop. Already submitted jobs continue, and POST scripts can still run. Once work drains, DAGMan writes a Rescue DAG and exits.&lt;/td&gt;
&lt;td&gt;Use &lt;code&gt;htcondor dag resume "$dag_id"&lt;/code&gt; while DAGMan is still running. After it exits, resubmit the original DAG from its run directory.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Fail B, repair it, and check that only B reruns
&lt;/h3&gt;

&lt;p&gt;Start with fresh copies of the definitions from Section 1. This time B will receive &lt;code&gt;A.out&lt;/code&gt; but ask &lt;code&gt;cat&lt;/code&gt; to open a different file. That makes the failure occur &lt;strong&gt;inside B&lt;/strong&gt;, after its inputs have arrived.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir &lt;span class="s2"&gt;"$project/rescue-demo"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    cp &lt;span class="s2"&gt;"$project"&lt;/span&gt;/&lt;span class="o"&gt;{&lt;/span&gt;my.dag,A.submit,B.submit&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="s2"&gt;"$project/rescue-demo/"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"$project/rescue-demo"&lt;/span&gt;
sed -i &lt;span class="s1"&gt;'s/^arguments = A\.out$/arguments = missing.txt/'&lt;/span&gt; B.submit
condor_submit_dag my.dag
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;234&lt;/code&gt; with this submission’s DAGMan cluster number. Wait for it to finish, then inspect the failure before repairing anything.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;failed_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;234
&lt;span class="k"&gt;if&lt;/span&gt; condor_wait -wait 300 my.dag.dagman.log &lt;span class="s2"&gt;"$failed_id.0"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    tail -n 1 my.dag.dagman.out
    cat B.err
    grep -E &lt;span class="s1"&gt;'^DONE[[:space:]]+A([[:space:]]|$)'&lt;/span&gt; my.dag.rescue001
    &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; sample-001 &lt;span class="o"&gt;|&lt;/span&gt; cmp - A.out &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'A.out is ready to reuse'&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this new directory, expect a nonzero final DAGMan status, an error naming &lt;code&gt;missing.txt&lt;/code&gt;, and a &lt;code&gt;DONE A&lt;/code&gt; entry in &lt;code&gt;my.dag.rescue001&lt;/code&gt;. That entry tells DAGMan to skip A. It does not establish that A’s output is still usable, which is why the last command checks the file itself. If the wait times out, inspect the active jobs before proceeding.&lt;/p&gt;

&lt;p&gt;Once you have confirmed those results, restore B’s working definition and resubmit the &lt;strong&gt;original DAG&lt;/strong&gt; in the &lt;strong&gt;same directory&lt;/strong&gt;. By default, DAGMan reads it together with the highest-numbered applicable Rescue DAG.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cp &lt;span class="s2"&gt;"$project/B.submit"&lt;/span&gt; B.submit
condor_submit_dag my.dag
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;345&lt;/code&gt; with the new DAGMan cluster number. The history query selects only node jobs belonging to this second submission.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;rescue_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;345
&lt;span class="k"&gt;if&lt;/span&gt; condor_wait -wait 300 my.dag.dagman.log &lt;span class="s2"&gt;"$rescue_id.0"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    tail -n 1 my.dag.dagman.out
    condor_history -constraint &lt;span class="s2"&gt;"DAGManJobId == $rescue_id"&lt;/span&gt; -af DAGNodeName ExitBySignal ExitCode
    &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; sample-001 &lt;span class="o"&gt;|&lt;/span&gt; cmp - A.out &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; cmp A.out B.out &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Output verified'&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expect &lt;code&gt;EXITING WITH STATUS 0&lt;/code&gt;, a single history row (&lt;code&gt;B false 0&lt;/code&gt;), and &lt;code&gt;Output verified&lt;/code&gt;. A’s original data reached B even though the second DAGMan job never submitted A.&lt;/p&gt;

&lt;p&gt;A rescue can reset the retry count for unfinished nodes. With HTCondor 25.0’s default &lt;code&gt;DAGMAN_RESET_RETRIES_UPON_RESCUE = True&lt;/code&gt;, an unfinished node gets its configured retry allowance again on rescue. A site that sets it to &lt;code&gt;False&lt;/code&gt; deducts retries already used. This exercise defines no &lt;code&gt;RETRY&lt;/code&gt; lines. If completed parents’ inputs or code change, use a fresh run directory with fresh result paths so their outputs are regenerated. &lt;a href="https://htcondor.readthedocs.io/en/25.0/automated-workflows/dagman-completion.html" rel="noopener noreferrer"&gt;Rescue DAGs&lt;/a&gt; · &lt;a href="https://htcondor.readthedocs.io/en/25.0/admin-manual/configuration-macros.html#DAGMAN_RESET_RETRIES_UPON_RESCUE" rel="noopener noreferrer"&gt;Retry configuration&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Hand four MAT-files to one merge job
&lt;/h2&gt;

&lt;p&gt;Part 3’s compiled application accepts a matrix size and writes &lt;code&gt;result.mat&lt;/code&gt;. To check the handoff, run four copies with predictable output names. The &lt;code&gt;MERGE&lt;/code&gt; node below uses &lt;code&gt;sha256sum&lt;/code&gt; to read each returned file. This verifies that all four files reached the child. Part 3 shows how to verify their numerical contents in MATLAB.&lt;/p&gt;

&lt;p&gt;In a fresh directory on the access point, copy Part 3’s &lt;code&gt;window_overlap&lt;/code&gt;, &lt;code&gt;run_window_overlap.sh&lt;/code&gt;, &lt;code&gt;run_job.sh&lt;/code&gt;, and &lt;code&gt;matlab.sub&lt;/code&gt;. Copy &lt;code&gt;matlab.sub&lt;/code&gt; to &lt;code&gt;run.submit&lt;/code&gt; and keep the worker requirement and &lt;code&gt;arguments = 64&lt;/code&gt; from your successful Part 3 run. Keep &lt;code&gt;when_to_transfer_output = ON_SUCCESS&lt;/code&gt;, &lt;code&gt;success_exit_code = 0&lt;/code&gt;, and &lt;code&gt;transfer_output_files = result.mat&lt;/code&gt;. Change the output remap in &lt;code&gt;run.submit&lt;/code&gt; to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;transfer_output_remaps = "result.mat=results/$(subject).mat"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the DAG as &lt;code&gt;participants.dag&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JOB RUN1 run.submit
JOB RUN2 run.submit
JOB RUN3 run.submit
JOB RUN4 run.submit
VARS RUN1 subject="sub-001"
VARS RUN2 subject="sub-002"
VARS RUN3 subject="sub-003"
VARS RUN4 subject="sub-004"

JOB MERGE merge.submit
PARENT RUN1 RUN2 RUN3 RUN4 CHILD MERGE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each parent writes &lt;code&gt;result.mat&lt;/code&gt; in its own worker scratch directory. The remap places the files under four distinct names on the access point. The merge job can therefore declare its inputs before any parent runs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frq5gz4hfpbiwzb1edy9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frq5gz4hfpbiwzb1edy9g.png" alt="Four parent jobs return sub-001.mat through sub-004.mat to the access point. MERGE receives all four files after the parents succeed." width="799" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Save the following as &lt;code&gt;merge.submit&lt;/code&gt;. Its worker needs &lt;code&gt;/usr/bin/sha256sum&lt;/code&gt;. The input list uses paths on the access point. The command arguments use the &lt;strong&gt;basenames&lt;/strong&gt; that HTCondor stages in the child’s working directory by default. &lt;a href="https://htcondor.readthedocs.io/en/25.0/users-manual/file-transfer.html" rel="noopener noreferrer"&gt;HTCondor input sandbox layout&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;universe = vanilla
executable = /usr/bin/sha256sum
transfer_executable = False
should_transfer_files = YES
transfer_input_files = results/sub-001.mat, results/sub-002.mat, results/sub-003.mat, results/sub-004.mat
arguments = sub-001.mat sub-002.mat sub-003.mat sub-004.mat
when_to_transfer_output = ON_EXIT
output = results/manifest.sha256
error = log/merge.err
log = log/merge.log
queue 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p log results
chmod u+x run_job.sh
condor_submit_dag participants.dag
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this DAG exits with status zero, compare the child’s checksums against the four files on the access point:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; results &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; sha256sum --check manifest.sha256&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expect one &lt;code&gt;OK&lt;/code&gt; for each filename from &lt;code&gt;sub-001.mat&lt;/code&gt; through &lt;code&gt;sub-004.mat&lt;/code&gt;. Each digest compares the child’s copy with the corresponding file on the access point. A file with incorrect matrix values could still pass this check. All four parents used the same matrix size. For a participant analysis, pass each parent its own input data and replace the checksum command with your aggregation program. If preprocessing produces those inputs, add a &lt;code&gt;PREP&lt;/code&gt; job and the dependency &lt;code&gt;PARENT PREP CHILD RUN1 RUN2 RUN3 RUN4&lt;/code&gt;. Reuse the run directory for a rescue and start each independent study run in a new one.&lt;/p&gt;

&lt;p&gt;When a result is missing, follow one filename from the parent’s scratch directory to the access point and then to the child. If the job has yet to start, Part 5 shows how to inspect the pool’s queues and allocations in Grafana.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;AI assistance was used in translating, organizing, and editing this article.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>htcondor</category>
      <category>hpc</category>
      <category>linux</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Running Compiled MATLAB Jobs with HTCondor and MATLAB Runtime</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Fri, 13 Nov 2026 23:48:08 +0000</pubDate>
      <link>https://dev.to/nha6ki/running-compiled-matlab-jobs-with-htcondor-and-matlab-runtime-25oe</link>
      <guid>https://dev.to/nha6ki/running-compiled-matlab-jobs-with-htcondor-and-matlab-runtime-25oe</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 3 of 6 in Building and Operating an HTCondor Pool for Research Computing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our lab guide describes building a standalone application with MATLAB Compiler on Linux and running it on an HTCondor worker that reads MATLAB Runtime from our NAS. Its build command uses R2021b, and its Runtime installer is R2021b Update 7. Its example times a product of two random matrices.&lt;/p&gt;

&lt;p&gt;Here we’ll use a smaller matrix whose answer we can check exactly. Once the remote shell job from Part 1 succeeds, you’ll build a CPU application, submit it to one worker, and verify the MAT-file it returns. The walkthrough uses Ubuntu 24.04 LTS and R2025b as a supported example. The outputs below are expectations for the exercise. &lt;a href="https://www.mathworks.com/content/dam/mathworks/mathworks-dot-com/support/sysreq/files/system-requirements-release-2025b-linux.pdf" rel="noopener noreferrer"&gt;R2025b Linux system requirements&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Put the build, Runtime, and results in the right places
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Location&lt;/th&gt;
&lt;th&gt;What you need there&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Linux x86-64 build machine&lt;/td&gt;
&lt;td&gt;MATLAB, MATLAB Compiler, and the source file. This machine needs the build licenses and can also serve as the access point.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HTCondor access point (submit host)&lt;/td&gt;
&lt;td&gt;The compiled executable, its generated Linux launcher, the job wrapper, and the submit file. The logs and returned MAT-file go here.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shared storage&lt;/td&gt;
&lt;td&gt;An installed Linux x86-64 MATLAB Runtime, mounted at the same path on each eligible worker.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Worker&lt;/td&gt;
&lt;td&gt;A supported Linux environment, permission to load the shared libraries, and writable job scratch space. The worker can run the executable with MATLAB Runtime alone.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Match the MATLAB release used to build the application. Within that release, use a Runtime at the &lt;strong&gt;same or a later update&lt;/strong&gt;. For example, an R2025b Update 2 build needs R2025b Update 2 or later in the R2025b line. Record the build update and the Runtime installer version separately. &lt;a href="https://www.mathworks.com/help/compiler/about-the-matlab-runtime.html" rel="noopener noreferrer"&gt;MathWorks Runtime compatibility&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you need to install the Runtime, unpack the matching Linux Runtime installer on a host with write access to the share. Run &lt;code&gt;./install&lt;/code&gt; and choose the shared destination. On the worker, locate the directory that &lt;strong&gt;contains&lt;/strong&gt; &lt;code&gt;runtime/glnxa64&lt;/code&gt;. For example, if the libraries are under &lt;code&gt;/shared/MATLAB_Runtime/R2025b/runtime/glnxa64&lt;/code&gt;, the launcher takes &lt;code&gt;/shared/MATLAB_Runtime/R2025b&lt;/code&gt;. The R2021b lab guide calls this directory &lt;code&gt;v911&lt;/code&gt;. &lt;a href="https://www.mathworks.com/products/compiler/matlab-runtime.html" rel="noopener noreferrer"&gt;Runtime downloads&lt;/a&gt; · &lt;a href="https://www.mathworks.com/help/compiler_sdk/ml_code/install-the-matlab-runtime.html" rel="noopener noreferrer"&gt;Installation instructions&lt;/a&gt; · &lt;a href="https://www.mathworks.com/help/compiler/deploying-a-standalone-application-on-a-network-drive-windows-only.html" rel="noopener noreferrer"&gt;Network installations&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Build a calculation you can check by hand
&lt;/h2&gt;

&lt;p&gt;Row 3 of a lower triangular matrix of ones begins with three ones. Row 7 begins with seven. Their dot product is 3. In general, if &lt;code&gt;W = tril(ones(n))&lt;/code&gt;, entry &lt;code&gt;(i,j)&lt;/code&gt; of &lt;code&gt;W * W.'&lt;/code&gt; equals &lt;code&gt;min(i,j)&lt;/code&gt;. That gives us a way to verify the worker’s entire result without repeating the multiplication.&lt;/p&gt;

&lt;p&gt;Save this function as &lt;code&gt;window_overlap.m&lt;/code&gt; in a new directory on the build machine. The standalone application receives its command-line argument as text, so the function converts it before allocating the matrix. &lt;a href="https://www.mathworks.com/help/compiler/working-with-standalone-applications-and-arguments.html" rel="noopener noreferrer"&gt;Standalone application arguments&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight matlab"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;window_overlap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;str2double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;validateattributes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'double'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'real'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'finite'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'scalar'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'integer'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'&amp;gt;='&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;='&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;windows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;tril&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ones&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;overlap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;windows&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;windows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;';
    assert(overlap(3,7) == 3 &amp;amp;&amp;amp; isequal(overlap(end,:), 1:n));

    save('&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mat&lt;/span&gt;&lt;span class="s1"&gt;', '&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="s1"&gt;', '&lt;/span&gt;&lt;span class="n"&gt;overlap&lt;/span&gt;&lt;span class="s1"&gt;');
    fprintf('&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=%&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;  &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="o"&gt;=%&lt;/span&gt;&lt;span class="n"&gt;dx&lt;/span&gt;&lt;span class="c1"&gt;%d  overlap(3,7)=%g  overlap(n,n)=%g\n', ...&lt;/span&gt;
        &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;overlap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;overlap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;overlap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;overlap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From that directory, run the function and build it with the intended MATLAB release. If several releases are installed, invoke that release’s &lt;code&gt;bin/matlab&lt;/code&gt; explicitly. The command prints the release and update before the source test. The source test writes &lt;code&gt;result.mat&lt;/code&gt; in the current directory. Leave that file there. Only the executable and launcher in &lt;code&gt;build/&lt;/code&gt; are needed for the job.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p build
matlab -batch &lt;span class="s2"&gt;"disp(matlabRelease); window_overlap('64'); mcc -m -R -singleCompThread -d build window_overlap.m"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    ls -l build/window_overlap build/run_window_overlap.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default build embeds the deployable archive in the executable. The generated launcher takes the Runtime root as its first argument and sets the library paths. The &lt;code&gt;-R -singleCompThread&lt;/code&gt; build option limits MATLAB’s computational threads to one, matching the CPU request below. &lt;a href="https://www.mathworks.com/help/compiler/mcc.html" rel="noopener noreferrer"&gt;MATLAB Compiler options&lt;/a&gt; · &lt;a href="https://www.mathworks.com/help/compiler/mcr-path-settings-for-run-time-deployment.html" rel="noopener noreferrer"&gt;Linux launcher and library paths&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare the job on the access point
&lt;/h2&gt;

&lt;p&gt;In a fresh job directory on the access point, place &lt;code&gt;window_overlap&lt;/code&gt; and &lt;code&gt;run_window_overlap.sh&lt;/code&gt; from the same build. Save the following wrapper as &lt;code&gt;run_job.sh&lt;/code&gt;. Replace &lt;code&gt;runtime_root&lt;/code&gt; with the path &lt;strong&gt;as the worker sees it&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -euo pipefail

&lt;span class="nv"&gt;runtime_root&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/shared/MATLAB_Runtime/R2025b
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Worker: %s\nRuntime: %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$(hostname)"&lt;/span&gt; &lt;span class="s2"&gt;"$runtime_root"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; ! -d &lt;span class="s2"&gt;"$runtime_root/runtime/glnxa64"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; ! -x &lt;span class="s2"&gt;"$runtime_root/runtime/glnxa64"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Cannot access Linux Runtime under %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$runtime_root"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
    &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;MCR_CACHE_ROOT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"${_CONDOR_SCRATCH_DIR:?Missing HTCondor job scratch directory}/mcr-cache"&lt;/span&gt;
mkdir -p &lt;span class="s2"&gt;"$MCR_CACHE_ROOT"&lt;/span&gt;
chmod u+x ./window_overlap ./run_window_overlap.sh
&lt;span class="nb"&gt;exec&lt;/span&gt; ./run_window_overlap.sh &lt;span class="s2"&gt;"$runtime_root"&lt;/span&gt; &lt;span class="s2"&gt;"$@"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lab guide sets the library path in its wrapper and uses a cache under &lt;code&gt;/var/tmp/mcr&lt;/code&gt; for each execution account. Here the generated launcher sets the library path, and each job extracts its archive into a fresh cache. With file transfer enabled, HTCondor starts the job in &lt;code&gt;_CONDOR_SCRATCH_DIR&lt;/code&gt;. The application writes &lt;code&gt;result.mat&lt;/code&gt; there, alongside the cache directory. &lt;a href="https://htcondor.readthedocs.io/en/25.0/users-manual/env-of-job.html" rel="noopener noreferrer"&gt;HTCondor job environment&lt;/a&gt; · &lt;a href="https://www.mathworks.com/help/compiler/matlab-runtime-component-cache-and-deployable-archive-embedding.html" rel="noopener noreferrer"&gt;MATLAB Runtime component cache&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Submit one CPU job
&lt;/h2&gt;

&lt;p&gt;Run &lt;code&gt;condor_status -af Machine OpSys Arch&lt;/code&gt; on the access point. Choose a worker with the matching Runtime mounted and copy its advertised &lt;code&gt;Machine&lt;/code&gt; name. Save this file as &lt;code&gt;matlab.sub&lt;/code&gt; in the job directory and replace &lt;code&gt;worker.example.org&lt;/code&gt;. The OS and architecture attributes alone cannot tell you whether a worker can load the shared installation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;universe                = vanilla
executable              = run_job.sh
arguments               = 64
should_transfer_files   = YES
transfer_input_files    = window_overlap, run_window_overlap.sh
when_to_transfer_output = ON_SUCCESS
success_exit_code       = 0
transfer_output_files   = result.mat
transfer_output_remaps  = "result.mat=results/result.$(ClusterId).$(ProcId).mat"

requirements   = (TARGET.OpSys == "LINUX") &amp;amp;&amp;amp; (TARGET.Arch == "X86_64") &amp;amp;&amp;amp; (TARGET.Machine == "worker.example.org")
request_cpus   = 1
request_memory = 8 GB
request_disk   = 2 GB

output        = log/matlab.$(ClusterId).$(ProcId).out
error         = log/matlab.$(ClusterId).$(ProcId).err
stream_output = True
stream_error  = True
log           = log/matlab.$(ClusterId).log
queue 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HTCondor transfers the wrapper and its two input files. On exit code zero, it returns &lt;code&gt;result.mat&lt;/code&gt; under the name in &lt;code&gt;transfer_output_remaps&lt;/code&gt;. If the application exits nonzero, HTCondor skips the MAT-file transfer. If it exits zero and the named file is missing, the job goes on hold. Streaming stdout and stderr keeps the short diagnostics available in either case. The RAM and scratch disk requests are starting values for this exercise. &lt;a href="https://htcondor.readthedocs.io/en/25.0/man-pages/condor_submit.html#when_to_transfer_output" rel="noopener noreferrer"&gt;HTCondor output transfer and streaming&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p log results
chmod u+x run_job.sh
condor_submit matlab.sub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Verify the returned matrix
&lt;/h2&gt;

&lt;p&gt;From the job directory, replace &lt;code&gt;123&lt;/code&gt; with the cluster number printed by &lt;code&gt;condor_submit&lt;/code&gt;. The single process in this example has process ID &lt;code&gt;0&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;cluster&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;123
&lt;span class="nv"&gt;job&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$cluster.0"&lt;/span&gt;
&lt;span class="nv"&gt;event_log&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"log/matlab.$cluster.log"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; condor_wait -wait 180 &lt;span class="s2"&gt;"$event_log"&lt;/span&gt; &lt;span class="s2"&gt;"$job"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    condor_history &lt;span class="s2"&gt;"$job"&lt;/span&gt; -af JobStatus ExitBySignal ExitCode
&lt;span class="k"&gt;else&lt;/span&gt;
    condor_q &lt;span class="s2"&gt;"$job"&lt;/span&gt; -af JobStatus HoldReason
    tail -n 20 &lt;span class="s2"&gt;"$event_log"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A zero return from &lt;code&gt;condor_wait&lt;/code&gt; can also mean the job was removed. Check the history row for &lt;strong&gt;this job&lt;/strong&gt;. A successful run should show &lt;code&gt;4 false 0&lt;/code&gt; (completed, normal exit, code zero). Run &lt;code&gt;cat "log/matlab.$job.out"&lt;/code&gt; and look for the wrapper’s hostname and this expected line. &lt;a href="https://htcondor.readthedocs.io/en/25.0/man-pages/condor_wait.html" rel="noopener noreferrer"&gt;HTCondor wait status&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;n=64  size=64x64  overlap(3,7)=3  overlap(n,n)=64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the access point has MATLAB, run the check below in the same shell. Otherwise, copy that job’s returned file to the build machine and set &lt;code&gt;RESULT_MAT&lt;/code&gt; to its path there. The check compares all 4,096 entries with the formula derived above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;RESULT_MAT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$PWD/results/result.$job.mat"&lt;/span&gt;  &lt;span class="c"&gt;# Adjust if you copied the file.&lt;/span&gt;
matlab -batch &lt;span class="s2"&gt;"
    r = load(getenv('RESULT_MAT'), 'n', 'overlap');
    k = 1:64;
    expected = min(k.', k);
    assert(isequal(r.n, 64) &amp;amp;&amp;amp; isequal(r.overlap, expected));
    disp('Verified all 4096 entries')"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before using this job in a DAG, test the failure path once. Submit the same build with an argument below the minimum of 7.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_submit -append &lt;span class="s1"&gt;'arguments = 6'&lt;/span&gt; matlab.sub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Repeat the wait and history check with the &lt;strong&gt;new&lt;/strong&gt; cluster number. For this input, expect a MATLAB validation error in the streamed logs, a normal exit with a nonzero code, and no returned MAT-file for that job ID. If MATLAB reports an error and the job is held for a missing output, inspect the event log and the generated launcher. The wrapper’s &lt;code&gt;exec&lt;/code&gt; preserves the launcher’s status, so the launcher must propagate the application’s failure.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;First check&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Still Idle after the wait&lt;/td&gt;
&lt;td&gt;Run &lt;code&gt;condor_q -better-analyze "$job"&lt;/code&gt;. Check the exact worker name and the available CPU, memory, and disk.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Still Running after the wait&lt;/td&gt;
&lt;td&gt;Repeat the wait with the same ID. Initial archive extraction can take time.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Held&lt;/td&gt;
&lt;td&gt;Run &lt;code&gt;condor_q "$job" -af HoldReason&lt;/code&gt;. For an output transfer error, check the worker-side filename and the destination under &lt;code&gt;results/&lt;/code&gt; on the access point.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Runtime or cache error&lt;/td&gt;
&lt;td&gt;Inspect &lt;code&gt;log/matlab.$job.err&lt;/code&gt;. If the wrapper cannot reach the Runtime, check the mount and permissions on the named worker. For a loader error, check the named library, OS dependencies, and Runtime version. For a cache error, check scratch space and write permissions.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To qualify another worker, replace the &lt;code&gt;Machine&lt;/code&gt; name and repeat the successful file check before expanding the pool of eligible workers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use the result in Part 4
&lt;/h2&gt;

&lt;p&gt;The cluster and process IDs identify a submitted job. An evicted job can start again with the same ID. A fresh submission gets a new cluster ID. For the DAG in Part 4, each parent instead returns its result under a participant label in the workflow’s own run directory.&lt;/p&gt;

&lt;p&gt;For example, assign the parent a label with &lt;code&gt;VARS RUN1 subject="sub-001"&lt;/code&gt; in the DAG file. In the parent submit file, &lt;strong&gt;replace only the remap&lt;/strong&gt; with the line below. Keep &lt;code&gt;arguments = 64&lt;/code&gt; for this matrix test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;transfer_output_remaps = "result.mat=results/$(subject).mat"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HTCondor returns RUN1’s file to the access point as &lt;code&gt;results/sub-001.mat&lt;/code&gt;. The merge job lists that path in &lt;code&gt;transfer_input_files&lt;/code&gt; and, with the default transfer layout, opens &lt;code&gt;sub-001.mat&lt;/code&gt; in its own working directory. The DAG dependency tells the merge job when it may run. In this exercise the participant labels identify files from identical calculations. A participant analysis would also need distinct input data for each parent. &lt;a href="https://dev.to/nha6ki/writing-htcondor-dag-files-job-dependencies-variables-and-concurrency-limits-15ng"&gt;DAGMan dependencies and VARS&lt;/a&gt; · &lt;a href="https://htcondor.readthedocs.io/en/25.0/users-manual/file-transfer.html" rel="noopener noreferrer"&gt;HTCondor file transfer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;AI assistance was used in drafting and editing this article.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>htcondor</category>
      <category>matlab</category>
      <category>hpc</category>
      <category>linux</category>
    </item>
    <item>
      <title>Running PyTorch Jobs on Shared GPUs with HTCondor</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Fri, 13 Nov 2026 23:33:32 +0000</pubDate>
      <link>https://dev.to/nha6ki/running-pytorch-jobs-on-shared-gpus-with-htcondor-p96</link>
      <guid>https://dev.to/nha6ki/running-pytorch-jobs-on-shared-gpus-with-htcondor-p96</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 2 of 6 in Building and Operating an HTCondor Pool for Research Computing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our November 2026 inventory included a GTX 1080 with 8 GiB of memory and a TITAN RTX with 24 GiB. With our sharing configuration, HTCondor can assign two jobs to the same physical GPU. We’ll submit one PyTorch job, inspect which GPU it sees, and check the result of a small matrix multiplication.&lt;/p&gt;

&lt;p&gt;Start with a pool that can return the hostname from a remote shell job, as in Part 1. The machine you submit from can have a different Python installation from the worker. The wrapper below records which worker HTCondor selected, and the Python script records which interpreter that worker started.&lt;/p&gt;

&lt;h2&gt;
  
  
  What one GPU request means in our pool
&lt;/h2&gt;

&lt;p&gt;Our lab’s setup instructions enable GPU sharing on NVIDIA workers with the two settings below. If you followed the optional GPU setup in Part 1, you can go straight to checking what the worker advertises.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="n"&gt;feature&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;GPUs&lt;/span&gt;
&lt;span class="na"&gt;GPU_DISCOVERY_EXTRA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;properties&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;divide&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;-divide 2&lt;/code&gt;, HTCondor lists each detected GPU ID twice and halves its advertised &lt;code&gt;GlobalMemoryMb&lt;/code&gt; for matching. For example, a device that discovery reports as 24,576 MiB would advertise 12,288 MiB per share. Two jobs assigned the same card draw from the same VRAM. This setting alone does not enforce a per-job memory limit.&lt;/p&gt;

&lt;p&gt;On the access point, run &lt;code&gt;condor_status -gpus -compact&lt;/code&gt; to see the advertised model names. On a worker, use the following command to see the physical devices and their full UUIDs. Keep the output with the worker’s hostname so you can look up the driver version for the machine that runs your test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvidia-smi --query-gpu=index,uuid,name,driver_version --format=csv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Choose a PyTorch build for the workers
&lt;/h2&gt;

&lt;p&gt;Our lab’s training tutorial uses PyTorch 2.4.1 with CUDA 12.1 and runs a transferred script with Python on shared storage. This article uses the same shared-interpreter setup for a smaller test that exits if CUDA is unavailable.&lt;/p&gt;

&lt;p&gt;The GTX 1080 is a Pascal GPU with compute capability 6.1. The TITAN RTX is a Turing GPU with compute capability 7.5. For Linux x86-64, the official PyTorch 2.8.0 CUDA 12.6 wheel includes support for both architectures. The CUDA 12.8 wheel from the same release dropped Pascal support. The 12.6 wheel is therefore a candidate to test on both cards. Each worker still needs a compatible NVIDIA driver. &lt;a href="https://dev-discuss.pytorch.org/t/cuda-toolkit-version-and-architecture-support-update-maxwell-and-pascal-architecture-support-removed-in-cuda-12-8-and-12-9-builds/3128" rel="noopener noreferrer"&gt;PyTorch 2.8 architecture support&lt;/a&gt; · &lt;a href="https://pytorch.org/get-started/previous-versions/" rel="noopener noreferrer"&gt;Official wheel installation commands&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before submitting, prepare a dedicated Python environment that every eligible worker can run at the same absolute path. The example uses &lt;code&gt;/shared/envs/pytorch/bin/python&lt;/code&gt;. Substitute your environment’s path in both the install command and the job wrapper. If you already have a suitable PyTorch build in that environment, skip the installation step.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/shared/envs/pytorch/bin/python -m pip install &lt;span class="nv"&gt;torch&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;2.8.0 --index-url https://download.pytorch.org/whl/cu126
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run a small job that requires CUDA
&lt;/h2&gt;

&lt;p&gt;On the access point, save this as &lt;code&gt;check_gpu.py&lt;/code&gt; in your job directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Interpreter:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;executable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CUDA_VISIBLE_DEVICES:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CUDA_VISIBLE_DEVICES"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;unset&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PyTorch:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__version__&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CUDA version used to build PyTorch:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cuda&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cuda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_available&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;SystemExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CUDA is unavailable to this PyTorch process"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Device: cuda:0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cuda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_device_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Compute capability:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cuda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_device_capability&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ones&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cuda:0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; @ &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Matrix product [0, 0]:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mf"&gt;128.0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;SystemExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Expected 128.0, got {result}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save this wrapper as &lt;code&gt;run_gpu.sh&lt;/code&gt;. Replace the example path with the absolute path to your environment’s Python on the worker.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/sh&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Execution host: %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$(hostname)"&lt;/span&gt;
&lt;span class="nb"&gt;exec&lt;/span&gt; /shared/envs/pytorch/bin/python check_gpu.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save &lt;code&gt;gpu.submit&lt;/code&gt; in the same directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;universe                = vanilla
executable              = run_gpu.sh
should_transfer_files   = YES
when_to_transfer_output = ON_EXIT
transfer_input_files    = check_gpu.py

request_cpus   = 1
request_memory = 2 GB
request_gpus   = 1

output = log/gpu.$(ClusterId).$(ProcId).out
error  = log/gpu.$(ClusterId).$(ProcId).err
log    = log/gpu.$(ClusterId).log
queue 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HTCondor transfers the wrapper and &lt;code&gt;check_gpu.py&lt;/code&gt;. The wrapper starts the Python interpreter already available to the worker. Here &lt;code&gt;request_memory&lt;/code&gt; requests host RAM, and &lt;code&gt;request_gpus = 1&lt;/code&gt; requests one advertised GPU resource.&lt;/p&gt;

&lt;p&gt;To test a specific card model, copy its advertised name from &lt;code&gt;condor_status -gpus -compact&lt;/code&gt; and add a &lt;code&gt;require_gpus&lt;/code&gt; line &lt;strong&gt;before&lt;/strong&gt; &lt;code&gt;queue 1&lt;/code&gt;. For example, if the worker advertises the name shown here, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require_gpus = (DeviceName == "NVIDIA GeForce GTX 1080")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A capability test alone would also allow the lab’s TITAN X (Pascal), which has the same compute capability as the GTX 1080. Submit once for the GTX 1080, then replace the name with the TITAN RTX’s advertised name and submit again. Keep the cluster ID for each run and check the model PyTorch prints before recording a pass for that card. For routine jobs, &lt;code&gt;gpus_minimum_capability&lt;/code&gt; sets a lower bound if all eligible models are supported by your build. &lt;a href="https://htcondor.readthedocs.io/en/25.0/man-pages/condor_submit.html#require_gpus" rel="noopener noreferrer"&gt;HTCondor GPU submit options&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p log
chmod +x run_gpu.sh
condor_submit gpu.submit
condor_q -nobatch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Verify the CUDA calculation
&lt;/h2&gt;

&lt;p&gt;From the submission directory on the access point, replace &lt;code&gt;123&lt;/code&gt; with the cluster ID for the run you want to check. The submit file queues one process, so its job ID ends in &lt;code&gt;.0&lt;/code&gt;. Wait up to three minutes for a completion or removal event.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;cluster&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;123
&lt;span class="nv"&gt;job&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$cluster.0"&lt;/span&gt;
&lt;span class="nv"&gt;event_log&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"log/gpu.$cluster.log"&lt;/span&gt;
condor_wait -wait 180 &lt;span class="s2"&gt;"$event_log"&lt;/span&gt; &lt;span class="s2"&gt;"$job"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the wait times out or reports an error, use the troubleshooting table below. A zero exit status from &lt;code&gt;condor_wait&lt;/code&gt; can also mean the job was removed. Check the job’s own exit status and read its output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_history &lt;span class="s2"&gt;"$job"&lt;/span&gt; -af JobStatus ExitBySignal ExitCode
cat &lt;span class="s2"&gt;"log/gpu.$job.out"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a successful run, look for &lt;strong&gt;both&lt;/strong&gt; of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The history shows &lt;code&gt;4 false 0&lt;/code&gt;. The job completed, exited normally, and returned exit code zero.&lt;/li&gt;
&lt;li&gt;Stdout shows &lt;code&gt;Matrix product [0, 0]: 128.0&lt;/code&gt;. Each element sums 128 products of ones. Calling &lt;code&gt;.item()&lt;/code&gt; reads the selected element back from the GPU as a Python number.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To identify the card, start with &lt;code&gt;Execution host&lt;/code&gt; and &lt;code&gt;CUDA_VISIBLE_DEVICES&lt;/code&gt; in stdout. HTCondor sets the latter from the job’s assignment. Inside the process, CUDA numbers visible devices starting at zero, so &lt;code&gt;cuda:0&lt;/code&gt; refers to the first device visible to this job. If HTCondor supplied a full GPU UUID or a unique prefix, match it against the UUIDs from &lt;code&gt;nvidia-smi&lt;/code&gt; on that worker. A numeric value alone does not give you a physical UUID. &lt;a href="https://htcondor.readthedocs.io/en/25.0/users-manual/env-of-job.html" rel="noopener noreferrer"&gt;HTCondor job environment&lt;/a&gt; · &lt;a href="https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/environment-variables.html" rel="noopener noreferrer"&gt;CUDA device enumeration&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Record the worker’s driver version alongside the PyTorch version, build CUDA version, model and compute capability for each successful run. The &lt;code&gt;128.0&lt;/code&gt; result verifies this calculation for one job. Demonstrating simultaneous assignment would require two jobs on the same worker with the same physical GPU UUID and overlapping execution times.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;What to check&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;The wait times out or reports an error&lt;/td&gt;
&lt;td&gt;Run &lt;code&gt;condor_q "$job" -af JobStatus HoldReason&lt;/code&gt; and read recent events with &lt;code&gt;tail -n 20 "$event_log"&lt;/code&gt;. For an Idle job, run &lt;code&gt;condor_q -better-analyze "$job"&lt;/code&gt; and check the GPU conditions. For a Running job, repeat the wait. For a Held job, read the hold reason. If the queue query returns no row, check the history. If the log is missing, check the cluster ID and working directory.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The wrapper prints a hostname, then Python fails to start&lt;/td&gt;
&lt;td&gt;Read &lt;code&gt;log/gpu.$job.err&lt;/code&gt;. On the named worker, check the interpreter path and execute permissions. If Python starts but importing PyTorch fails, stderr should identify the missing package or library.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The script reports that CUDA is unavailable&lt;/td&gt;
&lt;td&gt;Check &lt;code&gt;CUDA version used to build PyTorch&lt;/code&gt; and &lt;code&gt;CUDA_VISIBLE_DEVICES&lt;/code&gt; in stdout. For this NVIDIA setup, a build value of &lt;code&gt;None&lt;/code&gt; means PyTorch lacks CUDA support. With a CUDA build, check device visibility and the driver on the named worker.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The model is printed but a GPU operation fails&lt;/td&gt;
&lt;td&gt;Read &lt;code&gt;log/gpu.$job.err&lt;/code&gt;. For a kernel-image error, compare the model’s compute capability with the wheel’s supported architectures. For an out-of-memory error, check other processes and free VRAM on the physical card.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Part 3 runs a compiled MATLAB application on a CPU worker. To investigate GPU contention in Part 5, use the worker name and the full GPU UUID once you’ve matched it to the worker’s inventory. The VRAM time series shows free memory across the card at each sample, including the effects of other processes. With the example’s 30-second collection interval, a short job can start and finish between samples.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://htcondor.readthedocs.io/en/25.0/man-pages/condor_gpu_discovery.html" rel="noopener noreferrer"&gt;HTCondor GPU discovery options&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.nvidia.com/cuda/gpus" rel="noopener noreferrer"&gt;NVIDIA compute capabilities for current and legacy GPUs&lt;/a&gt; · &lt;a href="https://developer.nvidia.com/cuda/gpus/legacy" rel="noopener noreferrer"&gt;Legacy GPU table&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://htcondor.readthedocs.io/en/25.0/classad-attributes/job-classad-attributes.html" rel="noopener noreferrer"&gt;HTCondor job ClassAd attributes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;AI assistance was used in drafting and editing this article.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>python</category>
      <category>pytorch</category>
      <category>devops</category>
    </item>
    <item>
      <title>Build an HTCondor Pool on Ubuntu and Run Your First Remote Job</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Fri, 13 Nov 2026 23:26:49 +0000</pubDate>
      <link>https://dev.to/nha6ki/build-an-htcondor-pool-on-ubuntu-and-run-your-first-remote-job-58b7</link>
      <guid>https://dev.to/nha6ki/build-an-htcondor-pool-on-ubuntu-and-run-your-first-remote-job-58b7</guid>
      <description>&lt;p&gt;&lt;em&gt;Part 1 of 6 in Building and Operating an HTCondor Pool for Research Computing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Suppose you have one training run per participant in a study and several workstations that could run them. With HTCondor, you can submit each run as a &lt;em&gt;job&lt;/em&gt; and specify the CPU, memory, and GPU it needs. The workstations advertise what they can offer. HTCondor keeps each job in a queue until it can match it to a suitable machine. The machines that cooperate this way form a &lt;em&gt;pool&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I administer the central manager for our lab’s pool. Our November 2026 inventory lists twelve machines. The workstation that hosts the central manager also accepts submissions and runs jobs. Some of the other workstations only run jobs, while others also accept submissions.&lt;/p&gt;

&lt;p&gt;For this walkthrough, we’ll put each role on a separate Ubuntu 24.04 VM. You’ll submit a shell script and a text file from the access point (the submit node). The script will run on the worker and print its hostname and a line from the file. You’ll read both lines back on the access point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give each machine a role
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Example hostname&lt;/th&gt;
&lt;th&gt;HTCondor role&lt;/th&gt;
&lt;th&gt;What happens there&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;manager.example.org&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Central manager&lt;/td&gt;
&lt;td&gt;The &lt;em&gt;collector&lt;/em&gt; receives descriptions of available resources. The &lt;em&gt;negotiator&lt;/em&gt; matches queued work to those resources.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;submit.example.org&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Access point (submit node)&lt;/td&gt;
&lt;td&gt;You log in here. The &lt;em&gt;schedd&lt;/em&gt; keeps your job in its queue and arranges the transfer of input and output.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;worker.example.org&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Execution point (execute node)&lt;/td&gt;
&lt;td&gt;The &lt;em&gt;startd&lt;/em&gt; advertises resources as &lt;em&gt;slots&lt;/em&gt;. A slot is a portion of the machine’s resources available for a job. The worker runs your program.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvkvd2g6x84k1fxnnrti7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvkvd2g6x84k1fxnnrti7.png" alt="The worker advertises its slots to the central manager. The access point sends probe.sh and marker.txt directly to the worker, which returns stdout and stderr to the access point." width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Start with three fresh VMs on a private network. Each needs Bash, &lt;code&gt;curl&lt;/code&gt;, &lt;code&gt;sudo&lt;/code&gt;, and access to the Ubuntu and HTCondor package repositories. Run &lt;code&gt;uname -m&lt;/code&gt; on the &lt;strong&gt;access point and worker&lt;/strong&gt; and check that the results match. The submit file below uses HTCondor’s default architecture requirement, which matches the architecture of the access point even when the executable is a shell script.&lt;/p&gt;

&lt;p&gt;Allow TCP port 9618 between pool members. Before installing, check name resolution on each host. Substitute your own hostnames below and confirm that each resolves to its intended private address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;getent hosts manager.example.org submit.example.org worker.example.org
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install HTCondor on the three hosts
&lt;/h2&gt;

&lt;p&gt;Start on the manager, then install the access point, then the worker. Enter the same pool password on all three. On each host, the installer uses that shared secret to generate a daemon token. The daemons use these tokens to authenticate to one another with HTCondor’s &lt;code&gt;IDTOKENS&lt;/code&gt; method. Researchers submit jobs from their own local accounts on the access point.&lt;/p&gt;

&lt;p&gt;On &lt;strong&gt;each host&lt;/strong&gt;, download the installer into your home directory. Set &lt;code&gt;manager&lt;/code&gt; to the same real manager name everywhere. In a Bash shell on each host, first run the &lt;strong&gt;one assignment&lt;/strong&gt; from its row, then run the common commands below. The installer takes the manager’s name even on the worker.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Host you are logged into&lt;/th&gt;
&lt;th&gt;Set this variable&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Manager&lt;/td&gt;
&lt;td&gt;&lt;code&gt;role=--central-manager&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Access point&lt;/td&gt;
&lt;td&gt;&lt;code&gt;role=--submit&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Worker&lt;/td&gt;
&lt;td&gt;&lt;code&gt;role=--execute&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~
curl -fsSL https://get.htcondor.org -o get-htcondor.sh
&lt;span class="nv"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;manager.example.org
bash ./get-htcondor.sh --dry-run --channel 25.0 \
  &lt;span class="s2"&gt;"${role:?Set role using the table above}"&lt;/span&gt; &lt;span class="s2"&gt;"$manager"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dry run shows the proposed installation commands. The &lt;code&gt;25.0&lt;/code&gt; channel selects the HTCondor 25.0 LTS release series. Once the role and manager name look right, run the following in the &lt;strong&gt;same Bash session&lt;/strong&gt; on that host. The silent prompt keeps the pool password out of your typed command history. The installer reads it from standard input.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo -v
&lt;span class="o"&gt;(&lt;/span&gt;
  &lt;span class="nv"&gt;IFS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;read&lt;/span&gt; -r -s -p &lt;span class="s1"&gt;'Pool password: '&lt;/span&gt; pool_password &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1
  &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'\n'&lt;/span&gt;
  &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; -n &lt;span class="s2"&gt;"$pool_password"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1
  sudo -n /bin/bash ./get-htcondor.sh --no-dry-run \
    --channel 25.0 &lt;span class="s2"&gt;"${role:?Set role using the table above}"&lt;/span&gt; &lt;span class="s2"&gt;"$manager"&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s2"&gt;"$pool_password"&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the installer succeeds on each machine, check the installed version, the manager it points to, and the local service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_version
condor_config_val CONDOR_HOST
systemctl is-active condor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the manager’s service is active, test its TCP port from &lt;strong&gt;both the access point and the worker&lt;/strong&gt;. Use the &lt;code&gt;manager&lt;/code&gt; variable you set on each host. On Ubuntu, &lt;code&gt;nc&lt;/code&gt; is available in the &lt;code&gt;netcat-openbsd&lt;/code&gt; package (&lt;code&gt;sudo apt install netcat-openbsd&lt;/code&gt; if needed).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nc -vz -w 3 &lt;span class="s2"&gt;"$manager"&lt;/span&gt; 9618
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the connection times out or is refused, check the manager’s service, the resolved address, and the firewall rules. A successful connection establishes TCP reachability. To check whether the daemons have also registered with the collector, run the following on the &lt;strong&gt;access point&lt;/strong&gt; after all three services have started. Allow time for their first advertisements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_status -master -af Name
condor_status -schedd -af Name
condor_status -af Machine Name State Activity Cpus Memory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this layout, look for all three hosts in the first query, the access point in the second, and at least one slot on the worker in the third. A master entry tells you that the host’s managing daemon advertised itself. The slot entry tells you what that worker is offering. A machine can appear in the first list while offering no slots.&lt;/p&gt;

&lt;h2&gt;
  
  
  Send a file to the worker and get its contents back
&lt;/h2&gt;

&lt;p&gt;Log in to the &lt;strong&gt;access point as a regular user&lt;/strong&gt;. Create a working directory. Put a short script and a text file in it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p ~/first-condor-job/log
&lt;span class="nb"&gt;cd&lt;/span&gt; ~/first-condor-job
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; &lt;span class="s1"&gt;'sample-001'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; marker.txt
cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; probe.sh &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'SH'&lt;/span&gt;
&lt;span class="c"&gt;#!/bin/sh&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -eu
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Execution host: '&lt;/span&gt;
hostname
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Input received: '&lt;/span&gt;
cat marker.txt
SH
chmod +x probe.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In that directory, save this as &lt;code&gt;first.sub&lt;/code&gt;. HTCondor will transfer the executable and the specified input file, so the worker can run the test without a shared home directory, NAS mount, or Python environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;universe                = vanilla
executable              = probe.sh
transfer_input_files    = marker.txt
should_transfer_files   = YES
when_to_transfer_output = ON_EXIT
request_cpus            = 1
request_memory          = 128 MB
output                  = log/first.$(ClusterId).$(ProcId).out
error                   = log/first.$(ClusterId).$(ProcId).err
log                     = log/first.$(ClusterId).log
queue 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Submit the job and note the cluster number printed by &lt;code&gt;condor_submit&lt;/code&gt;. A quick job may already have finished by the time you inspect the queue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_submit first.sub
condor_q -nobatch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set &lt;code&gt;cluster&lt;/code&gt; to the number printed at submission. The submit file queues one process, so its job ID ends in &lt;code&gt;.0&lt;/code&gt;. Wait up to three minutes for a completion or removal event.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;cluster&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;123    &lt;span class="c"&gt;# Replace 123 with your cluster number.&lt;/span&gt;
&lt;span class="nv"&gt;job&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$cluster.0"&lt;/span&gt;
&lt;span class="nv"&gt;event_log&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"log/first.$cluster.log"&lt;/span&gt;
condor_wait -wait 180 &lt;span class="s2"&gt;"$event_log"&lt;/span&gt; &lt;span class="s2"&gt;"$job"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the wait times out or reports an error, use the troubleshooting steps below. A zero exit status from &lt;code&gt;condor_wait&lt;/code&gt; can also mean the job was removed. Check the job’s own exit status and read its standard output on the access point.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_history &lt;span class="s2"&gt;"$job"&lt;/span&gt; -af JobStatus ExitBySignal ExitCode
cat &lt;span class="s2"&gt;"log/first.$job.out"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a successful run, expect &lt;code&gt;4 false 0&lt;/code&gt; in the history. These values mean the job completed, exited normally, and returned exit code zero. The output file should look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Execution host: worker
Input received: sample-001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line should match the output of &lt;code&gt;hostname&lt;/code&gt; on &lt;strong&gt;your worker&lt;/strong&gt;. The second shows that the script read the transferred file. Reading both lines on the access point confirms that stdout made the return trip.&lt;/p&gt;

&lt;h3&gt;
  
  
  Troubleshoot the first job
&lt;/h3&gt;

&lt;p&gt;If the wait times out, the job may still be queued or running. On the access point, check its state and recent events.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;condor_q &lt;span class="s2"&gt;"$job"&lt;/span&gt; -af JobStatus HoldReason
tail -n 20 &lt;span class="s2"&gt;"$event_log"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;JobStatus&lt;/code&gt; 1 means Idle, 2 means Running, and 5 means Held. For a running job, repeat the wait with the same ID. If the queue query returns no row, check the history again. If the event log is missing, check the cluster number and make sure you are in &lt;code&gt;~/first-condor-job&lt;/code&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;If you see this&lt;/th&gt;
&lt;th&gt;What to check&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;The worker is missing from the collector&lt;/td&gt;
&lt;td&gt;On the worker, check &lt;code&gt;condor_config_val CONDOR_HOST&lt;/code&gt; and &lt;code&gt;systemctl status condor&lt;/code&gt;. Verify name resolution and TCP 9618 to the manager. Find the daemon log directory with &lt;code&gt;condor_config_val LOG&lt;/code&gt; and inspect &lt;code&gt;MasterLog&lt;/code&gt; and &lt;code&gt;StartLog&lt;/code&gt; for startup or authentication errors.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The job is still Idle when the wait times out&lt;/td&gt;
&lt;td&gt;On the access point, run &lt;code&gt;condor_q -better-analyze "$job"&lt;/code&gt;. Compare the reported requirements with the worker’s &lt;code&gt;Arch&lt;/code&gt;, available resources, and start policy. Use &lt;code&gt;condor_status -af Machine Arch Cpus Memory&lt;/code&gt; to see what it advertises.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The job is Held&lt;/td&gt;
&lt;td&gt;Read the hold reason. For a missing file or permission error, check that the submitting account can read the input file and write to the output directory. For a connection error during file transfer, check connectivity between the access point and the worker. The earlier &lt;code&gt;nc&lt;/code&gt; test checked the path to the manager.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The job ran but the output is incomplete&lt;/td&gt;
&lt;td&gt;Read &lt;code&gt;log/first.$job.err&lt;/code&gt;, the event log, and the exit status. An error from &lt;code&gt;cat marker.txt&lt;/code&gt; places the failure inside the running job.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  How I add a workstation to the lab pool
&lt;/h2&gt;

&lt;p&gt;For workstations joining our existing lab pool, I issue the daemon token centrally. A colleague sends me the workstation’s network address. I create the token on the central manager with &lt;code&gt;condor_token_create&lt;/code&gt; and give it to the colleague. They configure the workstation with our manager and trust domain and install the token under &lt;code&gt;/etc/condor/tokens.d/&lt;/code&gt; with restricted permissions.&lt;/p&gt;

&lt;p&gt;Our central manager is configured with &lt;code&gt;use ROLE : CentralManager, Submit, Execute&lt;/code&gt;. For a workstation that will both accept submissions and run jobs, our setup instructions specify &lt;code&gt;use ROLE : Submit, Execute&lt;/code&gt;. I look for its schedd with &lt;code&gt;condor_status -schedd&lt;/code&gt; and its execution slots with &lt;code&gt;condor_status&lt;/code&gt;. Submitting a job from the colleague’s local account checks that the workstation’s schedd accepts jobs from that user. To see which workstation actually ran the job, check the hostname printed by the probe.&lt;/p&gt;

&lt;p&gt;People also use these workstations at their desks. Our setup instructions use &lt;code&gt;START = (Cpus &amp;gt; 0) &amp;amp;&amp;amp; (LoadAvg / Cpus &amp;lt; 0.4)&lt;/code&gt; to decide when a slot can accept a new job. A workstation can remain visible in the pool while this condition prevents a new job from starting. On a partitionable slot, &lt;code&gt;Cpus&lt;/code&gt; counts the CPUs still available. As jobs claim CPUs, the denominator gets smaller, so even an unchanged &lt;code&gt;LoadAvg&lt;/code&gt; can bring the ratio up to the cutoff.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optional GPU sharing on an NVIDIA worker
&lt;/h2&gt;

&lt;p&gt;After the CPU test succeeds, you can configure HTCondor to let two jobs share one NVIDIA GPU. On the idle worker, check that &lt;code&gt;nvidia-smi -L&lt;/code&gt; lists the expected card, then apply the settings below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo tee /etc/condor/config.d/90-lab-gpu.config &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'CONF'&lt;/span&gt;
use feature : GPUs
GPU_DISCOVERY_EXTRA &lt;span class="o"&gt;=&lt;/span&gt; -properties -divide 2
CONF
sudo systemctl restart condor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-divide 2&lt;/code&gt; makes &lt;code&gt;condor_gpu_discovery&lt;/code&gt; list the same device ID twice in &lt;code&gt;DetectedGPUs&lt;/code&gt; and report half its usual &lt;code&gt;GlobalMemoryMb&lt;/code&gt; value for matching. Two jobs that each request one GPU can therefore be assigned the same card. They share its VRAM, and either job can use more than the advertised half if enough memory is free. Once the worker advertises again, run &lt;code&gt;condor_status -gpus&lt;/code&gt; on the access point to inspect the pool’s GPU resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to go after the first job
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Run PyTorch on an NVIDIA worker (Part 2).&lt;/strong&gt; Once the worker advertises a GPU, submit a small matrix multiplication and verify the result from the access point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run a compiled MATLAB application on a CPU worker (Part 3).&lt;/strong&gt; Start from the successful CPU test. Part 3 adds the build machine and MATLAB Runtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run jobs in dependency order (Part 4).&lt;/strong&gt; Use DAGMan to make a second job eligible to run only after the first succeeds. You can try the first example on your CPU pool. &lt;a href="https://dev.to/nha6ki/writing-htcondor-dag-files-job-dependencies-variables-and-concurrency-limits-15ng"&gt;Writing HTCondor DAG Files&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://htcondor.readthedocs.io/en/25.0/getting-htcondor/admin-quick-start.html" rel="noopener noreferrer"&gt;HTCondor 25.0 administrative quick start and pool roles&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://htcondor.readthedocs.io/en/25.0/man-pages/get_htcondor.html" rel="noopener noreferrer"&gt;The Linux installer and its authentication configuration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://htcondor.readthedocs.io/en/25.0/man-pages/condor_submit.html#requirements" rel="noopener noreferrer"&gt;Default job requirements in &lt;code&gt;condor_submit&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://htcondor.readthedocs.io/en/25.0/man-pages/condor_wait.html" rel="noopener noreferrer"&gt;Completion events and exit status in &lt;code&gt;condor_wait&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://htcondor.readthedocs.io/en/25.0/classad-attributes/machine-classad-attributes.html" rel="noopener noreferrer"&gt;Machine ClassAd attributes, including &lt;code&gt;Cpus&lt;/code&gt; and &lt;code&gt;LoadAvg&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://htcondor.readthedocs.io/en/25.0/users-manual/quick-start-guide.html" rel="noopener noreferrer"&gt;Submitting a first HTCondor job&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://htcondor.readthedocs.io/en/25.0/man-pages/condor_gpu_discovery.html" rel="noopener noreferrer"&gt;GPU discovery and the divide option&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;AI assistance was used in drafting and editing this article.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>ubuntu</category>
      <category>hpc</category>
      <category>devops</category>
    </item>
    <item>
      <title>Evaluating DeepSeek-V4.1-Flash-1017 on a 60-Page PDF: What Text Extraction Misses</title>
      <dc:creator>Haruki Niwa</dc:creator>
      <pubDate>Thu, 12 Nov 2026 04:25:24 +0000</pubDate>
      <link>https://dev.to/nha6ki/evaluating-deepseek-v41-flash-1017-on-a-60-page-pdf-what-text-extraction-misses-2efo</link>
      <guid>https://dev.to/nha6ki/evaluating-deepseek-v41-flash-1017-on-a-60-page-pdf-what-text-extraction-misses-2efo</guid>
      <description>&lt;p&gt;I recently deployed &lt;strong&gt;DeepSeek-V4.1-Flash-1017&lt;/strong&gt; across two NVIDIA DGX Spark systems and connected the model to &lt;strong&gt;Open WebUI&lt;/strong&gt;. Once the deployment was working, I wanted to test a common research workflow: attaching a long PDF and asking questions about its tables and figures.&lt;/p&gt;

&lt;p&gt;The most useful observation was not an overall accuracy score. It was how the same figure-dependent information was handled when the evidence was supplied within a PDF versus as individual PNG images.&lt;/p&gt;

&lt;p&gt;I used a 60-page fictional report, ASTER-47. I preserved the original PDF-question prompt and response, and later recovered the original Open WebUI chat exports for five separate PNG-input questions. This article examines what those records establish. It is &lt;strong&gt;not&lt;/strong&gt; a standardized benchmark or a controlled comparison of models.&lt;/p&gt;

&lt;p&gt;The two-node installation and operating procedures are covered in the &lt;a href="https://dev.to/nha6ki/running-deepseek-v41-flash-1017-across-two-nvidia-dgx-sparks-5hk9"&gt;companion implementation article&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Evaluation environment
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Tested configuration&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hardware&lt;/td&gt;
&lt;td&gt;Two NVIDIA DGX Spark systems (GB10)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Model&lt;/td&gt;
&lt;td&gt;DeepSeek-V4.1-Flash-1017&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Checkpoint&lt;/td&gt;
&lt;td&gt;Mia-AiLab EXL3 EAQ v1, 2.9 bpw&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inference&lt;/td&gt;
&lt;td&gt;TensorFold, two ranks (TP=2)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Serving settings&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CONTEXT=262144 PARALLEL=1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Web interface&lt;/td&gt;
&lt;td&gt;Open WebUI v0.13.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Document option&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Using Entire Document&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Evaluation material&lt;/td&gt;
&lt;td&gt;ASTER-47, a 60-page English PDF&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The serving configuration was based on &lt;a href="https://github.com/MiaAI-Lab/DeepSeek-v4.1-Flash-1017-2x-DGX-Sparks/tree/c7f2b85100f0a7b099c92a4e21825e30d93c9c51" rel="noopener noreferrer"&gt;MiaAI-Lab's two-DGX-Spark repository at the revision used for this deployment&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The 262,144-token context is a &lt;strong&gt;configured limit&lt;/strong&gt;, not a measured effective context length. The document-test API payload and complete performance measurements were not archived, so this article does not report throughput or long-context accuracy.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Evaluation document and actual procedure
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;ASTER-47&lt;/strong&gt; is a custom-generated, completely fictional report about a multi-site virtual monitoring study. Its facility names, event counts, detector statistics, tables, and figures were generated for this test. None represents a real-world measurement or research participant.&lt;/p&gt;

&lt;p&gt;The published evaluation package contains the &lt;strong&gt;original PDF (60 pages, 686,543 bytes)&lt;/strong&gt;, the 28-question set and answer key, generator and manifest, five figure-page PNGs, and preserved model responses.&lt;/p&gt;

&lt;p&gt;The questions were organized into three groups:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Q01–Q20:&lt;/strong&gt; facts, arithmetic, and reconciliation across selectable text and tables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Q21–Q25:&lt;/strong&gt; specific values and labels printed inside raster figures, intentionally not repeated in the selectable text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Q26–Q28:&lt;/strong&gt; information the fictional report explicitly does not contain, such as measured GPU power or human participants.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the recorded PDF run, I attached &lt;strong&gt;only the report PDF&lt;/strong&gt; to Open WebUI, selected &lt;strong&gt;Using Entire Document&lt;/strong&gt;, and submitted &lt;strong&gt;all 28 questions together in one message&lt;/strong&gt;. The answer key was not attached. The original model reply was exported as both text and a six-page PDF.&lt;/p&gt;

&lt;p&gt;The recorded Open WebUI session also showed file-tool activity (&lt;code&gt;list_chat_files&lt;/code&gt;, &lt;code&gt;query_chat_files&lt;/code&gt;, &lt;code&gt;view_file&lt;/code&gt;, and &lt;code&gt;grep_chat_files&lt;/code&gt;). Although &lt;strong&gt;Using Entire Document&lt;/strong&gt; was selected, the exact retrieved text and final API payload were not archived. Thus, this is not a verified test of placing all 60 pages into a single model request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An important methodological detail:&lt;/strong&gt; the PDF-question prompt instructed the model not to invent unsupported values and explicitly warned that a PDF-to-text-only workflow was &lt;em&gt;not expected to access raster pixels&lt;/em&gt;. The synthetic report repeated this warning. Therefore, the five figure-related abstentions cannot be taken as evidence that the model independently discovered a parser failure.&lt;/p&gt;

&lt;p&gt;For the separate image condition, each of Figures 6–10 was uploaded as &lt;strong&gt;one PNG in its own Open WebUI chat&lt;/strong&gt;, with one question. The recovered JSON exports identify the model as &lt;code&gt;DeepSeek-V4.1-Flash-1017&lt;/code&gt; and preserve each exact user prompt and complete final response. The attached-image SHA-256 hashes match the five PNG files in the repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Recorded outcomes
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Input condition&lt;/th&gt;
&lt;th&gt;Question group&lt;/th&gt;
&lt;th&gt;Recorded outcome&lt;/th&gt;
&lt;th&gt;Evidence&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;PDF attached&lt;/td&gt;
&lt;td&gt;Q01–Q20: text and tables&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;20/20&lt;/strong&gt; matched the prepared answer key&lt;/td&gt;
&lt;td&gt;Original combined prompt and full response retained&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PDF attached&lt;/td&gt;
&lt;td&gt;Q21–Q25: raster-only facts&lt;/td&gt;
&lt;td&gt;All &lt;strong&gt;5&lt;/strong&gt; figure-dependent answers withheld&lt;/td&gt;
&lt;td&gt;Original response retained; the prompt had warned about raster inaccessibility&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PDF attached&lt;/td&gt;
&lt;td&gt;Q26–Q28: unsupported facts&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;3/3&lt;/strong&gt; appropriately declined or qualified&lt;/td&gt;
&lt;td&gt;Original response retained; missing facts were explicit in the report&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PNGs attached individually&lt;/td&gt;
&lt;td&gt;Q21–Q25: figure-only facts&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;5/5&lt;/strong&gt; matched the prepared answer key&lt;/td&gt;
&lt;td&gt;Five original JSON exports recovered; complete prompts and final responses verified&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The PDF condition involved &lt;strong&gt;one combined 28-question interaction&lt;/strong&gt;; the PNG condition involved &lt;strong&gt;five separate, single-image chats&lt;/strong&gt;, with differently worded questions. These six interactions are not a controlled, identical-prompt comparison, and their scores should not be pooled into a general accuracy figure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example A: Reading a table and performing a calculation
&lt;/h3&gt;

&lt;p&gt;Question 9 asked for precision, recall, and F1 to four decimal places using the fictional S2 confusion matrix on page 17:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TP = 430&lt;/li&gt;
&lt;li&gt;FP = 224&lt;/li&gt;
&lt;li&gt;FN = 110&lt;/li&gt;
&lt;li&gt;TN = 16,156&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An excerpt from the &lt;strong&gt;original model response&lt;/strong&gt; reads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Precision = 430/(430+224) = 430/654 = 0.6575
Recall = 430/540 = 0.7963
F1 = 2(430)/(2·430 + 224 + 110) = 860/1194 = 0.7203
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The calculations match the prepared key. This demonstrates successful extraction and arithmetic for this example, not statistical validation of the fictional detector.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvl0xlrynx01j87jwbzg8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvl0xlrynx01j87jwbzg8.png" alt="Excerpt from the original ASTER-47 chat PDF export showing Q08–Q09 and the calculation." width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1. Cropped from the actual six-page chat PDF export. The numerical results and wording were not edited.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The response also correctly distinguished the report's 12 illustrative case-log rows from the larger population of 60 positive events in Q20. These examples are more informative than simply listing the overall 20/20 count.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example B: A figure value across two input conditions
&lt;/h3&gt;

&lt;p&gt;Question 22 asked for the value at &lt;strong&gt;site FX × Packet&lt;/strong&gt; in Figure 7 (page 26). The heatmap has the value &lt;strong&gt;0.72&lt;/strong&gt; printed inside its pixels; that numeric cell is deliberately omitted from the surrounding selectable text.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwtla2tib979im1ztd5hp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwtla2tib979im1ztd5hp.png" alt="ASTER-47 Figure 7, a fictional heatmap with FX × Packet equal to 0.72." width="800" height="1131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 2. The original fictional report's page 26. The cell value is visible in the raster figure.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the retained PDF-only response, the model marked Q22 &lt;strong&gt;“Not accessible”&lt;/strong&gt; and explained that the cell values were present in the raster image but absent from the text it could use. It withheld the requested numeric answer, as it did for Q21 and Q23–Q25.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm0mp7solpdvg5urf0qre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm0mp7solpdvg5urf0qre.png" alt="Excerpt from the original ASTER-47 chat PDF export showing the figure-only questions and their abstentions." width="800" height="827"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 3. Cropped from the actual six-page chat PDF export. The five figure-dependent responses are presented together.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is an observation about the &lt;strong&gt;tested end-to-end workflow&lt;/strong&gt;, not proof that the model lacks vision capabilities or that a particular parser discarded the images.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;separate PNG-input chat&lt;/strong&gt; for Figure 7, the user asked the model to examine the image directly and identify the FX × Packet value. The preserved answer reads:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I read the image directly. In Figure 7, the bottom row labeled &lt;strong&gt;FX&lt;/strong&gt; intersects the &lt;strong&gt;Packet&lt;/strong&gt; column (second column) at a cell annotated &lt;strong&gt;0.72&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exact value: 0.72&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The four other recovered PNG answers also match their keys:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Image-only fact requested&lt;/th&gt;
&lt;th&gt;Recorded answer&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Q21&lt;/td&gt;
&lt;td&gt;Highest W5 drift index&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;FX, 0.91&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q23&lt;/td&gt;
&lt;td&gt;Topmost and rightmost points&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;P11, P12&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q24&lt;/td&gt;
&lt;td&gt;Final routing-box token&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;AUDIT-PATH-K7&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q25&lt;/td&gt;
&lt;td&gt;Largest priority class&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Moderate, 37%&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The &lt;a href="https://github.com/nha6ki/deepseek-v4.1-flash-evaluation/blob/main/observations/ASTER47_PNG_direct_input_transcripts.md" rel="noopener noreferrer"&gt;public transcripts&lt;/a&gt; preserve the full prompts and final replies for all five PNG questions. This verifies the recorded answers, but the input modality was not the only difference between the two conditions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example C: Declining unsupported requests
&lt;/h3&gt;

&lt;p&gt;Questions 26–28 requested real measured GPU power, actual geographical coordinates of a fictional site, and the number of human participants in a supposed field study.&lt;/p&gt;

&lt;p&gt;The recorded model reply did not fabricate these facts. However, the fictional report expressly says there were no physical measurements, real facilities, or human-subject experiments. The initial user prompt also prohibited unsupported claims.&lt;/p&gt;

&lt;p&gt;Thus, &lt;strong&gt;3/3&lt;/strong&gt; describes agreement with an intentionally easy, explicitly signposted abstention test. It is &lt;strong&gt;not&lt;/strong&gt; evidence of general hallucination resistance.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Interpretation and limitations
&lt;/h2&gt;

&lt;p&gt;The experiment supports a practical distinction: &lt;strong&gt;the fact that a figure is visible in a PDF does not establish that its values are available in the tested question-answering workflow&lt;/strong&gt;. In the recorded PDF chat, the model withheld the requested raster-only values; when the corresponding PNGs were uploaded separately, it provided the correct values.&lt;/p&gt;

&lt;p&gt;The following details matter when interpreting that difference:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Synthetic and purpose-built material.&lt;/strong&gt; ASTER-47 was designed with auditable text answers and deliberately image-only facts. It is not a representative sample of published research PDFs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Different question procedures.&lt;/strong&gt; The PDF condition used one 28-question prompt; the PNG condition used five separate chats with shorter, individually phrased questions. These results are descriptive, not a controlled paired modality benchmark.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explicit hints.&lt;/strong&gt; The PDF prompt and document warned about missing raster evidence and nonexistent real-world measurements. Therefore, the abstentions do not independently demonstrate parser-failure detection or general resistance to hallucination.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Uninspected internal payload.&lt;/strong&gt; File tools were used, but the exact final model request and retrieved chunks were not archived. The observation does not identify the component responsible for the inaccessible figure values or prove that all 60 pages were present in a single context.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ambiguity in the fictional report.&lt;/strong&gt; Page 14 describes R0 calibration as using a training quantile, while page 15 presents validation-based R0 threshold selection. These may describe different steps, but their relationship is not explained. The model flagged this ambiguity in Q14; its reported threshold values still match the prepared answer key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No repeated trials or performance benchmark.&lt;/strong&gt; The article reports observed answers, not a measured error rate, confidence interval, token throughput, or 262,144-token context-quality result.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  5. Materials and reproducibility
&lt;/h2&gt;

&lt;p&gt;The published repository includes the original 60-page PDF, exact combined 28-question prompt, answer key, generator and manifest, five figure PNGs, and the &lt;strong&gt;unaltered PDF-chat TXT and six-page PDF export&lt;/strong&gt;. It also contains the &lt;strong&gt;verbatim prompts and complete final responses from five PNG-input chats&lt;/strong&gt;, extracted into public-facing Markdown and JSON files.&lt;/p&gt;

&lt;p&gt;The public PNG transcripts omit account identifiers and model reasoning traces from the raw chat exports while retaining the original user prompts and final answers. The five attached PNGs were verified against the repository files using SHA-256 hashes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Evaluation materials:&lt;/strong&gt; &lt;a href="https://github.com/nha6ki/deepseek-v4.1-flash-evaluation" rel="noopener noreferrer"&gt;ASTER-47 PDF, questions, answer key, figures, and recorded DeepSeek responses&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To reproduce the &lt;strong&gt;PDF condition&lt;/strong&gt;, open a new Open WebUI chat with the same model and document setting, attach only the ASTER-47 PDF (not the answer key), submit the &lt;strong&gt;original combined 28-question prompt&lt;/strong&gt;, and preserve the response before scoring it.&lt;/p&gt;

&lt;p&gt;To reproduce the &lt;strong&gt;PNG condition&lt;/strong&gt;, use five separate chats, each with the corresponding Figure 6–10 PNG and its &lt;strong&gt;original individual prompt&lt;/strong&gt;. Save each answer verbatim before comparing it with the key. The supplied transcripts make it possible to check the five previously observed answers without repeating the experiment.&lt;/p&gt;

&lt;p&gt;The article screenshots illustrate selected responses; the original exports and transcripts are the primary evaluation record.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this recorded deployment, DeepSeek-V4.1-Flash-1017 matched the prepared key on all 20 text/table questions in the synthetic PDF, while withholding answers to five raster-only figure questions in the PDF chat. In five separate chats with the relevant PNGs attached directly, it correctly answered all five figure questions. &lt;strong&gt;The prompts and final answers for both conditions are now preserved.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because the PDF prompt included explicit raster-related hints and the two conditions used different question formats, the results describe this workflow rather than a controlled modality comparison or a general model-accuracy score.&lt;/p&gt;

&lt;p&gt;The practical takeaway is to &lt;strong&gt;verify whether a document-processing workflow makes the visual evidence needed for a question accessible&lt;/strong&gt;, especially when interpreting scientific figures and diagrams.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;AI disclosure: This article documents my own technical setup and results. An LLM was used to help draft, organize, and edit the English text. I reviewed the technical claims against the available original prompt, answer key, document, and chat exports.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>deepseek</category>
      <category>nvidia</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
