How idiap/gridtk works
Project type and purpose
• GridTK is a Python-based command-line application (CLI tool) that wraps and extends Slurm’s sbatch interface.
• Its goal is to simplify job submission, monitoring, dependencies, logging, and resubmission for Slurm clusters.
File structure
• Top-level:
• .github/, CI/CD workflows, code coverage, deployment.
• doc/, Sphinx docs.
• src/gridtk/, main application package.
• tests/, unit tests.
• pyproject.toml, package metadata.
• Inside src/gridtk/:
• __main__.py, CLI entrypoint.
• cli.py, command definitions (submit, list, report, stop, delete, resubmit, etc.).
• manager.py, core orchestration and business logic.
• models.py, data structures (job metadata, state transitions).
• tools.py, low-level helpers (filesystem operations, subprocess wrappers for sbatch, environment-variable handling).
Key insights from README
• Commands correspond to subcommands in cli.py.
• GridTK maintains “local job IDs,” wraps Slurm calls, tracks logs under a logs/ directory.
• Supports environment-variable overrides for defaults, temporary-script generation, dependencies, arrays, repeat jobs.
• External integration point: Slurm cluster via system calls (sbatch, squeue, scontrol, sacct).
Main components
A. CLI Frontend
• The user interacts via the gridtk command (installed via pipx).
• Implements parsing of subcommands & options.
B. Core Service Layer (Manager)
• Receives parsed commands, applies business rules (e.g., dependency resolution, repeat logic).
C. Data Layer (Models & Metadata Store)
• Defines Job objects, maintains a local store (e.g., JSON or lightweight file) mapping local job IDs → Slurm IDs → state.
D. Tools Layer
• Subprocess wrapper for invoking Slurm commands.
• File/IO helpers for creating temporary scripts, writing log files, reading environment variables.
E. External Services
• Slurm scheduler (executes batch jobs).
F. Local File System
• logs/ directory for job stdout/stderr.
• Temporary script storage (/tmp/...).
• Local metadata file(s) under working directory.
Relationships and data flows
• User Input → CLI Frontend
• CLI Frontend → Manager
• Manager ↔ Models (read/write job metadata)
• Manager ↔ Tools
• Tools → Slurm (via subprocess calls)
• Tools → File System (logs, temp scripts)
• Manager → Output back to CLI → Console
• Manager → Slurm → returns Slurm job ID, state updates
• Manager reads Slurm via squeue/sacct for status reports
Architectural patterns & principles
• Layered architecture: clear separation between CLI, service logic, data model, and low-level tools.
• Single responsibility: each module handles one concern (parsing, orchestration, data, IO).
• Dependency injection (via environment variables) for default options.
Technologies & frameworks
• Python packaging (pyproject.toml), pipx installation
• Standard library for subprocess and file IO
• Sphinx for documentation
• GitHub Actions for CI/CD