bujang 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bujang-0.1.1/LICENSE +21 -0
- bujang-0.1.1/MANIFEST.in +10 -0
- bujang-0.1.1/PKG-INFO +384 -0
- bujang-0.1.1/README.md +348 -0
- bujang-0.1.1/bujang/__init__.py +9 -0
- bujang-0.1.1/bujang/cli/__init__.py +62 -0
- bujang-0.1.1/bujang/cli/cleanup.py +184 -0
- bujang-0.1.1/bujang/cli/dev.py +172 -0
- bujang-0.1.1/bujang/cli/serve/__init__.py +49 -0
- bujang-0.1.1/bujang/cli/serve/app.py +105 -0
- bujang-0.1.1/bujang/cli/serve/static/assets/index-Bjyezt0r.js +107 -0
- bujang-0.1.1/bujang/cli/serve/static/assets/index-H6REUvAg.css +1 -0
- bujang-0.1.1/bujang/cli/serve/static/index.html +13 -0
- bujang-0.1.1/bujang/cli/ssh/__init__.py +39 -0
- bujang-0.1.1/bujang/cli/ssh/common.py +94 -0
- bujang-0.1.1/bujang/cli/ssh/install.py +68 -0
- bujang-0.1.1/bujang/cli/ssh/remove.py +39 -0
- bujang-0.1.1/bujang/cli/ssh/show.py +45 -0
- bujang-0.1.1/bujang/cli/ssh/test.py +97 -0
- bujang-0.1.1/bujang/config.py +194 -0
- bujang-0.1.1/bujang/constant.py +10 -0
- bujang-0.1.1/bujang/defaults/profiles.yaml +12 -0
- bujang-0.1.1/bujang/defaults/scripts/common/hello_world.sh +47 -0
- bujang-0.1.1/bujang/defaults/scripts/common/job_array.sh +46 -0
- bujang-0.1.1/bujang/defaults/scripts/common/pipeline/two_step_pipeline.json +23 -0
- bujang-0.1.1/bujang/defaults/scripts/common/pipeline_prepare.sh +37 -0
- bujang-0.1.1/bujang/defaults/scripts/common/pipeline_use.sh +36 -0
- bujang-0.1.1/bujang/errors.py +16 -0
- bujang-0.1.1/bujang/fastapi.py +90 -0
- bujang-0.1.1/bujang/flask.py +49 -0
- bujang-0.1.1/bujang/mcp_server.py +839 -0
- bujang-0.1.1/bujang/models.py +115 -0
- bujang-0.1.1/bujang/scripts/__init__.py +1 -0
- bujang-0.1.1/bujang/scripts/dm_runner.sh +52 -0
- bujang-0.1.1/bujang/scripts/epilogue.sh +22 -0
- bujang-0.1.1/bujang/scripts/hook_end.sh +4 -0
- bujang-0.1.1/bujang/scripts/hook_epilogue.sh +10 -0
- bujang-0.1.1/bujang/scripts/hook_proxy.sh +14 -0
- bujang-0.1.1/bujang/scripts/hook_start.sh +19 -0
- bujang-0.1.1/bujang/scripts/prologue.sh +22 -0
- bujang-0.1.1/bujang/scripts/ssh_runner.sh +143 -0
- bujang-0.1.1/bujang/scripts/submit_epilogue.sh +9 -0
- bujang-0.1.1/bujang/scripts/submit_prologue.sh +11 -0
- bujang-0.1.1/bujang/server/__init__.py +1 -0
- bujang-0.1.1/bujang/server/agent.py +308 -0
- bujang-0.1.1/bujang/server/cache.py +47 -0
- bujang-0.1.1/bujang/server/commands.py +58 -0
- bujang-0.1.1/bujang/server/jsonutil.py +36 -0
- bujang-0.1.1/bujang/server/paths.py +23 -0
- bujang-0.1.1/bujang/server/pipeline.py +411 -0
- bujang-0.1.1/bujang/server/routes.py +186 -0
- bujang-0.1.1/bujang/server/scheduled.py +417 -0
- bujang-0.1.1/bujang/server/secrets.py +386 -0
- bujang-0.1.1/bujang/server/service.py +2446 -0
- bujang-0.1.1/bujang/server/slurm.py +543 -0
- bujang-0.1.1/bujang/server/sources.py +300 -0
- bujang-0.1.1/bujang/server/templates.py +180 -0
- bujang-0.1.1/bujang/sshcheck.py +203 -0
- bujang-0.1.1/bujang/sshconfig.py +398 -0
- bujang-0.1.1/bujang.egg-info/PKG-INFO +384 -0
- bujang-0.1.1/bujang.egg-info/SOURCES.txt +80 -0
- bujang-0.1.1/bujang.egg-info/dependency_links.txt +1 -0
- bujang-0.1.1/bujang.egg-info/entry_points.txt +2 -0
- bujang-0.1.1/bujang.egg-info/requires.txt +32 -0
- bujang-0.1.1/bujang.egg-info/top_level.txt +1 -0
- bujang-0.1.1/docs/DESIGN.md +185 -0
- bujang-0.1.1/docs/EXAMPLES.md +107 -0
- bujang-0.1.1/pyproject.toml +79 -0
- bujang-0.1.1/setup.cfg +4 -0
- bujang-0.1.1/setup.py +51 -0
- bujang-0.1.1/tests/conftest.py +148 -0
- bujang-0.1.1/tests/unit/test_agent_activity.py +101 -0
- bujang-0.1.1/tests/unit/test_examples.py +383 -0
- bujang-0.1.1/tests/unit/test_host_options.py +67 -0
- bujang-0.1.1/tests/unit/test_mcp_mount.py +96 -0
- bujang-0.1.1/tests/unit/test_mila_plugin.py +78 -0
- bujang-0.1.1/tests/unit/test_parity.py +303 -0
- bujang-0.1.1/tests/unit/test_placeholders.py +347 -0
- bujang-0.1.1/tests/unit/test_scheduled_jobs.py +220 -0
- bujang-0.1.1/tests/unit/test_service.py +235 -0
- bujang-0.1.1/tests/unit/test_sources.py +162 -0
- bujang-0.1.1/tests/unit/test_ssh_cli.py +405 -0
bujang-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Milabench
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
bujang-0.1.1/MANIFEST.in
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# sdist: the package (with the built UI and the examples) and the docs, not the UI sources
|
|
2
|
+
include README.md LICENSE setup.py
|
|
3
|
+
recursive-include docs *.md
|
|
4
|
+
recursive-include bujang/cli/serve/static *
|
|
5
|
+
recursive-include bujang/defaults *
|
|
6
|
+
recursive-include bujang/scripts *.sh
|
|
7
|
+
recursive-include tests *.py
|
|
8
|
+
prune ui
|
|
9
|
+
prune contrib
|
|
10
|
+
global-exclude __pycache__ *.py[cod]
|
bujang-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bujang
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Slurm job management (jobs, pipelines, scheduled jobs, agent activity) as a reusable library
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: argklass
|
|
10
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
11
|
+
Requires-Dist: pyyaml
|
|
12
|
+
Requires-Dist: filelock
|
|
13
|
+
Requires-Dist: apscheduler<4,>=3.10
|
|
14
|
+
Requires-Dist: croniter
|
|
15
|
+
Requires-Dist: fastapi
|
|
16
|
+
Requires-Dist: uvicorn[standard]
|
|
17
|
+
Requires-Dist: mcp>=2
|
|
18
|
+
Provides-Extra: fastapi
|
|
19
|
+
Provides-Extra: server
|
|
20
|
+
Provides-Extra: mcp
|
|
21
|
+
Requires-Dist: requests; extra == "mcp"
|
|
22
|
+
Provides-Extra: flask
|
|
23
|
+
Requires-Dist: flask>=2.3; extra == "flask"
|
|
24
|
+
Provides-Extra: mila
|
|
25
|
+
Requires-Dist: bujang-mila>=0.1.1; extra == "mila"
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff; extra == "dev"
|
|
31
|
+
Requires-Dist: httpx; extra == "dev"
|
|
32
|
+
Requires-Dist: fastapi; extra == "dev"
|
|
33
|
+
Requires-Dist: uvicorn; extra == "dev"
|
|
34
|
+
Requires-Dist: flask>=2.3; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# bujang
|
|
38
|
+
|
|
39
|
+
Slurm job management that runs **on your own machine**. bujang drives your clusters the
|
|
40
|
+
way you already do by hand: over SSH, with your own account and `~/.ssh/config`. Nothing
|
|
41
|
+
to deploy, nothing installed on the cluster, no database server, no admin rights. Every
|
|
42
|
+
job gets the same folder on the cluster (`~/scratch/bujang/<job id>/` by default:
|
|
43
|
+
script, logs, accounting, outputs), and bujang rsyncs those folders back into a local
|
|
44
|
+
cache (`~/.local/share/bujang`), so results stay with you after the scratch is purged.
|
|
45
|
+
|
|
46
|
+
It provides job submission and monitoring, pipelines (Slurm and ssh steps with
|
|
47
|
+
dependencies), cron-scheduled jobs, secrets in scripts, an agent activity log (MCP
|
|
48
|
+
server), a React UI (`ui/`, npm `@bujang/ui`), and the same HTTP API (`/api/slurm/*`) as a
|
|
49
|
+
FastAPI router or a Flask adapter. The only requirement: `ssh <cluster>` works without a
|
|
50
|
+
prompt (keys, an agent, or a ControlMaster for MFA clusters).
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
uv tool install bujang # `bujang serve`: API + UI + MCP (UI built in, no Node needed)
|
|
56
|
+
uv add bujang # the FastAPI router, in your app
|
|
57
|
+
uv add "bujang[mila]" # + the Mila clusters plugin (bujang-mila)
|
|
58
|
+
pip install "bujang[flask]" # + the Flask adapter
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
FastAPI, uvicorn and the MCP server come with bujang: the default server works out of the box.
|
|
62
|
+
|
|
63
|
+
bujang and its plugins are on PyPI. From git, or a source checkout, see
|
|
64
|
+
[Development](#development).
|
|
65
|
+
|
|
66
|
+
The wheel and the sdist ship the built UI (`bujang/cli/serve/static`). Building from a git
|
|
67
|
+
checkout runs `npm ci && npm run build:app` in `ui/` when it is missing (setup.py), and fails with
|
|
68
|
+
a clear message without npm. Editable installs (`uv sync`) skip that step. The React views are the
|
|
69
|
+
npm package `@bujang/ui`, see [ui/README.md](ui/README.md):
|
|
70
|
+
|
|
71
|
+
```jsonc
|
|
72
|
+
"@bujang/ui": "https://github.com/milabench/bujang/releases/download/v0.1.1/bujang-ui-0.1.1.tgz"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
or, next to a checkout, in the host's `pyproject.toml`:
|
|
76
|
+
|
|
77
|
+
```toml
|
|
78
|
+
[tool.uv.sources]
|
|
79
|
+
bujang = { path = "../bujang", editable = true }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Extras: `flask` (the Flask adapter), `mila` (`contrib/bujang-mila`), `mcp` (`requests`, for the standalone MCP process), `dev`. `fastapi` and `server` are kept as empty extras: the server is installed by default.
|
|
83
|
+
|
|
84
|
+
## Run the default server
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
bujang serve # http://127.0.0.1:8000: API + UI + MCP endpoint at /mcp
|
|
88
|
+
bujang serve --config ~/clusters.yaml --port 8080
|
|
89
|
+
bujang serve --no-mcp # without the MCP endpoint
|
|
90
|
+
bujang cleanup --dry-run # old job folders of the local cache without data
|
|
91
|
+
bujang ssh install --plugin mila --set MILA_USER=me --set ALLIANCE_USER=me2 # ~/.ssh/config entries
|
|
92
|
+
bujang ssh test # can bujang reach every cluster?
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## SSH setup (`bujang ssh`)
|
|
96
|
+
|
|
97
|
+
Plugins can ship the `~/.ssh/config` entries of their clusters. `bujang ssh` manages them:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
bujang ssh show --plugin mila # print the block
|
|
101
|
+
bujang ssh install --plugin mila --set MILA_USER=me --set ALLIANCE_USER=me2
|
|
102
|
+
bujang ssh install --plugin mila --dedupe # also drop older Host entries for the same aliases
|
|
103
|
+
bujang ssh remove --plugin mila # undo
|
|
104
|
+
bujang ssh test [CLUSTER ...] [--json] # connect to each cluster, read only
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
* `install` writes the block between `# >>> bujang:<plugin> <version> ...` / `# <<< bujang:<plugin> <<<`
|
|
108
|
+
anchors, and replaces it in place on the next install (an update). The placeholder values are
|
|
109
|
+
remembered in the block (`# bujang-vars:`), prompted for on a terminal, an error otherwise.
|
|
110
|
+
* Every write backs the file up first (`<file>.bujang-<YYYYmmdd-HHMMSS>.bak`, `--no-backup` to skip),
|
|
111
|
+
prints the diff (`--dry-run`: only the diff), keeps the file mode, line endings and everything
|
|
112
|
+
outside the anchors, and checks each alias with `ssh -G`.
|
|
113
|
+
* ssh uses the first value it finds: a `Host` entry above the block with the same alias wins over
|
|
114
|
+
bujang's. `install` warns about each one; `--dedupe` removes those aliases (never wildcards,
|
|
115
|
+
`Match` or `Include` lines).
|
|
116
|
+
* `test` checks, for every cluster and ssh executor host (data movers): an open ControlMaster
|
|
117
|
+
connection (`ssh -O check`), a connection without prompts (BatchMode; auth / MFA, host key, DNS,
|
|
118
|
+
timeout and refused are told apart), the Slurm commands and the remote workdir. Exit code 0 when
|
|
119
|
+
every host passes. On clusters with MFA, run `ssh <alias>` once in a terminal first.
|
|
120
|
+
|
|
121
|
+
## Configuration
|
|
122
|
+
|
|
123
|
+
Clusters, profiles and scripts are YAML, merged in this order (later wins, per key):
|
|
124
|
+
plugins (entry point group `bujang.plugins`, e.g. `bujang[mila]`) <
|
|
125
|
+
`~/.config/bujang/*.yaml` < `BUJANG_CONFIG` / `--config` / `config_paths` < explicit fields.
|
|
126
|
+
|
|
127
|
+
```yaml
|
|
128
|
+
# ~/.config/bujang/clusters.yaml
|
|
129
|
+
clusters:
|
|
130
|
+
mycluster:
|
|
131
|
+
ssh: mycluster # ~/.ssh/config alias
|
|
132
|
+
remote_folder: ~/scratch/bujang
|
|
133
|
+
proxy: true # compute nodes get internet through the login node
|
|
134
|
+
nodes: nodes/mycluster.yaml # node types and their slurm "chunks" (one profile each)
|
|
135
|
+
profiles:
|
|
136
|
+
short-gpu: {cluster: mycluster, args: ["--gpus=1", "--time=1:00:00"]}
|
|
137
|
+
scripts: scripts # scripts/<cluster>/*.sh, scripts/<cluster>/pipeline/*.json
|
|
138
|
+
default_cluster: mycluster # any BujangConfig field can be set here
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`GET /api/slurm/config/sources` shows which plugin or file each cluster came from.
|
|
142
|
+
In code, everything is a `BujangConfig` field (`bujang/config.py`); `BujangConfig.from_env()`
|
|
143
|
+
reads `BUJANG_<FIELD>` variables (`BUJANG_LOCAL_CACHE`, `BUJANG_PLUGINS=mila`, ...).
|
|
144
|
+
`BujangConfig.from_env(extra_config_paths=["config/clusters.yaml"])` adds the host's files after
|
|
145
|
+
the `BUJANG_CONFIG` ones instead of replacing them.
|
|
146
|
+
|
|
147
|
+
Example scripts and pipelines (hello world, job array, pipelines that prepare on the login node and
|
|
148
|
+
run offline, ...) come with bujang and the Mila plugin: see [docs/EXAMPLES.md](docs/EXAMPLES.md).
|
|
149
|
+
|
|
150
|
+
Job scripts can say where bujang puts its bookkeeping with `# {START}` / `# {END}` lines, see
|
|
151
|
+
[Script placeholders](#script-placeholders), and take arguments, see [Script arguments](#script-arguments).
|
|
152
|
+
|
|
153
|
+
Secrets in scripts (`{{ secrets.NAME }}`) come from the environment, Bitwarden (`bw`),
|
|
154
|
+
`secrets.toml` / `.secrets` in the local cache, or `BUJANG_SECRET_CMD`. Bitwarden takes
|
|
155
|
+
`BujangConfig(bitwarden_collection=..., bitwarden_session=...)` (or `BUJANG_BW_COLLECTION` /
|
|
156
|
+
`BW_SESSION`); `create_default_store(root, collection=..., session=...)` builds the same chain.
|
|
157
|
+
|
|
158
|
+
## Script arguments
|
|
159
|
+
|
|
160
|
+
A job script is a function: its arguments are the `export NAME=CONSTANT` lines of a
|
|
161
|
+
`# ---- Arguments` section, before `# {START}`. The UI shows them as a form and writes the values
|
|
162
|
+
back into those lines on submit, a scheduled job keeps its own values, and the `env` of a pipeline
|
|
163
|
+
step sets them for that step (`two_step_pipeline.json` sets `MESSAGE` of `pipeline_prepare.sh`).
|
|
164
|
+
Every example follows this layout:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
#!/bin/bash
|
|
168
|
+
#SBATCH ...
|
|
169
|
+
# header comment: what it shows, what to change
|
|
170
|
+
|
|
171
|
+
# ---- Arguments
|
|
172
|
+
# learning rate of the optimizer
|
|
173
|
+
export LEARNING_RATE=0.001
|
|
174
|
+
# git repository of the code
|
|
175
|
+
export REPO_URL=https://github.com/pytorch/examples.git
|
|
176
|
+
# a list: space separated, split in the script
|
|
177
|
+
export SETTINGS="0.1 0.01 0.001"
|
|
178
|
+
# secrets too, before `set -x`
|
|
179
|
+
export HF_TOKEN="{{ secrets.HF_TOKEN }}"
|
|
180
|
+
|
|
181
|
+
# {START}
|
|
182
|
+
set -euo pipefail
|
|
183
|
+
|
|
184
|
+
# ---- Script
|
|
185
|
+
RUN_DIR="$SCRATCH/runs/$SLURM_JOB_ID" # derived values go here, after START
|
|
186
|
+
read -ra SETTING_LIST <<< "$SETTINGS"
|
|
187
|
+
python train.py --lr "$LEARNING_RATE"
|
|
188
|
+
|
|
189
|
+
# {END}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
How an argument is read (`parseExportVariables` in `ui/src/views/JobSubmit.tsx`; the example tests
|
|
193
|
+
port it in `tests/unit/test_examples.py`):
|
|
194
|
+
|
|
195
|
+
* `export NAME=VALUE` on its own line, ending with a newline. A value with a `$` (a variable, `$(...)`)
|
|
196
|
+
is derived, not an argument: compute it in the script after `# {START}`. Use a path relative
|
|
197
|
+
to `$HOME` / `$SCRATCH` (or the job folder) as the argument and build the full path in the script.
|
|
198
|
+
* Constants only: no arrays (`SETTINGS=(a b)`); give a space separated string and split it.
|
|
199
|
+
* One pair of outer quotes is removed (`"a b"` or `'a b'`), an unquoted value is trimmed. Nothing
|
|
200
|
+
else is unquoted: no escapes, and a trailing `# comment` would be part of the value. Put the comment
|
|
201
|
+
on the line above.
|
|
202
|
+
* Every constant `export` line of the script is read, wherever it is, even in a comment: keep
|
|
203
|
+
constant exports of the body as `NAME=1` then `export NAME`.
|
|
204
|
+
|
|
205
|
+
On submit the UI writes the value back, in double quotes if it has spaces or shell characters; a
|
|
206
|
+
pipeline step's `env` replaces the value of an argument the same way (single quotes), and a name that is
|
|
207
|
+
not an argument of the script is exported before it.
|
|
208
|
+
|
|
209
|
+
## Script placeholders
|
|
210
|
+
|
|
211
|
+
At submission bujang adds its hooks to the job script: `$JR_JOB_ID` / `$JR_JOB_DIR`, a snapshot of
|
|
212
|
+
the job, the SOCKS proxy (`proxy: true`) and the EXIT trap that runs `epilogue.sh` on the login
|
|
213
|
+
node. A script chooses where with two optional lines, each at most once (a line that is exactly
|
|
214
|
+
`# {START}` or `# {END}`, surrounding spaces allowed; a repeated one, or `# {END}` before
|
|
215
|
+
`# {START}`, is a 400 error):
|
|
216
|
+
|
|
217
|
+
* `# {START}`: exports `JR_JOB_ID` and `JR_JOB_DIR` (written in at submission), `mkdir -p
|
|
218
|
+
"$JR_JOB_DIR/meta"`, snapshots `scontrol show job --json` into `meta/job_info.json` (the job
|
|
219
|
+
entry, `.jobs[0]`, with `jq`; without `jq` the raw output goes to `meta/job_info.raw.json`), then
|
|
220
|
+
the proxy hook and the EXIT trap. It never fails the job, never turns on `set -x` and prints no
|
|
221
|
+
secret. Put the arguments and `{{ secrets.NAME }}` lines above it and `set -x` below it: what
|
|
222
|
+
is above `# {START}` stays above it.
|
|
223
|
+
* `# {END}`: snapshots `meta/job_info.json` again and writes the time to `meta/end.txt`. It runs
|
|
224
|
+
only if the script gets there: under `set -e` a failing script never reaches it. The EXIT trap
|
|
225
|
+
(epilogue, `meta/epilogue.txt` with the exit code) is what always runs, so END is an extra hook,
|
|
226
|
+
not a replacement.
|
|
227
|
+
* Without `# {START}` its content goes after the shebang / `#SBATCH` header, as before (with only
|
|
228
|
+
`# {END}` too). Without `# {END}` there is no END block. ssh steps of a pipeline (outside of
|
|
229
|
+
Slurm) get START / END without the Slurm hooks, and are run as is without placeholders.
|
|
230
|
+
|
|
231
|
+
The snapshot is `meta/job_info.json` and not `meta/info.json`: `info.json` is the local mirror's
|
|
232
|
+
cache of the same `scontrol` entry, written once the job is over, and a running-state copy from the
|
|
233
|
+
cluster would replace it at the next rsync.
|
|
234
|
+
|
|
235
|
+
Everything bujang inserts sits between markers, `# >>> bujang START (inserted at submit) >>>` ...
|
|
236
|
+
`# <<< bujang START <<<` (also `END`, `HOOKS` for the after-header fallback and `PIPELINE` for the
|
|
237
|
+
`JR_PIPELINE_*` of pipeline steps). Saving a submitted script as a template, editing a job to
|
|
238
|
+
resubmit it (`GET /api/slurm/jobs/<id>/script`: `script` without the blocks, `raw_script` as
|
|
239
|
+
submitted), the scheduled-job template diff and a rerun turn the blocks back into the placeholders
|
|
240
|
+
(and drop `HOOKS` / `PIPELINE`), so templates never collect inserted code and a rerun replaces
|
|
241
|
+
the blocks instead of repeating them. Submitting an expanded script expands it again cleanly.
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# ---- Arguments
|
|
245
|
+
# before `set -x`: not traced
|
|
246
|
+
export FOO={{ secrets.FOO }}
|
|
247
|
+
|
|
248
|
+
# {START}
|
|
249
|
+
|
|
250
|
+
set -ex
|
|
251
|
+
# ---- Script
|
|
252
|
+
python train.py
|
|
253
|
+
|
|
254
|
+
# {END}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
is submitted (job `train_ab12cd34`, no proxy) as:
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# ---- Arguments
|
|
261
|
+
# before `set -x`: not traced
|
|
262
|
+
export FOO=<the secret>
|
|
263
|
+
|
|
264
|
+
# >>> bujang START (inserted at submit) >>>
|
|
265
|
+
# --- job folder and bookkeeping (it does not turn on tracing, nothing secret is printed) ---
|
|
266
|
+
export JR_JOB_ID=train_ab12cd34
|
|
267
|
+
export JR_JOB_DIR="$(eval echo ~/scratch/bujang/train_ab12cd34)"
|
|
268
|
+
mkdir -p "$JR_JOB_DIR/meta" 2>/dev/null || true
|
|
269
|
+
__jr_job_info() { # scontrol | jq '.jobs[0]' > meta/job_info.json, best effort
|
|
270
|
+
...
|
|
271
|
+
}
|
|
272
|
+
__jr_job_info || true
|
|
273
|
+
# --- jobrunner epilogue: run bookkeeping on the login node (has internet) ---
|
|
274
|
+
__jr_epilogue() { ... ssh <login> "... bash ~/scratch/bujang/train_ab12cd34/epilogue.sh" ... }
|
|
275
|
+
trap __jr_epilogue EXIT
|
|
276
|
+
# <<< bujang START <<<
|
|
277
|
+
|
|
278
|
+
set -ex
|
|
279
|
+
# ---- Script
|
|
280
|
+
python train.py
|
|
281
|
+
|
|
282
|
+
# >>> bujang END (inserted at submit) >>>
|
|
283
|
+
# --- end of the script: only reached when it gets here (not under `set -e` after a failure,
|
|
284
|
+
# the EXIT trap / epilogue is what always runs) ---
|
|
285
|
+
__jr_job_info 2>/dev/null || true
|
|
286
|
+
date -Is > "$JR_JOB_DIR/meta/end.txt" 2>/dev/null || true
|
|
287
|
+
# <<< bujang END <<<
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
The blocks are `bujang/scripts/hook_start.sh`, `hook_proxy.sh`, `hook_epilogue.sh` and
|
|
291
|
+
`hook_end.sh` (`BujangConfig.scripts_dir` to use your own).
|
|
292
|
+
|
|
293
|
+
## Include it in a FastAPI app
|
|
294
|
+
|
|
295
|
+
```python
|
|
296
|
+
from fastapi import Depends, FastAPI
|
|
297
|
+
from bujang import Bujang, BujangConfig
|
|
298
|
+
from bujang.fastapi import create_router
|
|
299
|
+
|
|
300
|
+
bujang = Bujang(BujangConfig(config_paths=["config/clusters.yaml"], database=engine))
|
|
301
|
+
app = FastAPI(lifespan=...) # call bujang.start() / bujang.stop() in the lifespan
|
|
302
|
+
app.include_router(create_router(bujang, prefix="/api/slurm", dependencies=[Depends(auth)]))
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## Flask
|
|
306
|
+
|
|
307
|
+
```python
|
|
308
|
+
from bujang.flask import register_flask
|
|
309
|
+
|
|
310
|
+
bujang = Bujang(BujangConfig(database=session_factory, scheduler=app_scheduler, cache=flask_cache))
|
|
311
|
+
register_flask(protected_blueprint, bujang) # routes under /api/slurm, auth is the blueprint's
|
|
312
|
+
bujang.start() # book keeping + scheduled-job checker
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Both adapters answer with the same status codes and the same JSON bytes.
|
|
316
|
+
|
|
317
|
+
## Logging
|
|
318
|
+
|
|
319
|
+
bujang logs to the `bujang` logger and adds no handler to it: the host decides where it goes,
|
|
320
|
+
e.g. `logging.getLogger("bujang").addHandler(...)` or `logging.basicConfig(level=logging.INFO)`.
|
|
321
|
+
`bujang serve` uses uvicorn's logging.
|
|
322
|
+
|
|
323
|
+
## MCP server
|
|
324
|
+
|
|
325
|
+
`bujang serve` and `bujang dev` serve the MCP endpoint by default, on the same port as the API
|
|
326
|
+
and the UI. Agents submit and monitor jobs through the same code as the UI, and what they do
|
|
327
|
+
shows up on the Agent Activity page:
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
claude mcp add --transport http bujang http://127.0.0.1:8000/mcp --header "X-Agent-Name: my-agent"
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
`--no-mcp` (or `BUJANG_SERVE_MCP=0`) turns it off. In your own FastAPI app, mount it the same
|
|
334
|
+
way the default server does, and run its session manager in the app lifespan:
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
from bujang import mcp_server
|
|
338
|
+
|
|
339
|
+
manager = mcp_server.mount(app, host="127.0.0.1", url="http://127.0.0.1:8000")
|
|
340
|
+
# lifespan: async with manager.run(): yield
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
It can also run on its own port, as a thread of a Flask or ASGI host
|
|
344
|
+
(`mcp_server.serve_in_background(app)`, port `BUJANG_MCP_PORT`, 5002), or as a separate process
|
|
345
|
+
talking to a bujang server over HTTP (`python -m bujang.mcp_server --url http://127.0.0.1:8000`,
|
|
346
|
+
stdio, or `--http`). The environment variables (`BUJANG_MCP_*`, see `bujang/mcp_server.py`) give
|
|
347
|
+
the defaults, `configure()` overrides them. The MCP server object is created on first use, so
|
|
348
|
+
`name` can be set by the host.
|
|
349
|
+
|
|
350
|
+
## Database (scheduled jobs)
|
|
351
|
+
|
|
352
|
+
`database` is an Engine, a sessionmaker, or a callable returning a session context manager.
|
|
353
|
+
The standalone server uses sqlite in the local cache (`create_tables=True`). A host with
|
|
354
|
+
alembic adds bujang's metadata and autogenerates the migration:
|
|
355
|
+
|
|
356
|
+
```python
|
|
357
|
+
# alembic/env.py
|
|
358
|
+
import bujang.models
|
|
359
|
+
|
|
360
|
+
target_metadata = [Base.metadata, bujang.models.Base.metadata]
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## Development
|
|
364
|
+
|
|
365
|
+
```bash
|
|
366
|
+
uv sync --all-extras
|
|
367
|
+
bujang dev # API with auto-reload on 127.0.0.1:8000 + UI dev server (HMR)
|
|
368
|
+
# open http://127.0.0.1:5173; --port, --ui-port, --config, --plugins
|
|
369
|
+
uv run pytest
|
|
370
|
+
uv run ruff check . && uv run ruff format --check .
|
|
371
|
+
cd ui && npm run build:app # bundle the UI into bujang/cli/serve/static for `bujang serve`
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## Release
|
|
375
|
+
|
|
376
|
+
Bump the version in `pyproject.toml`, `bujang/__init__.py`, `contrib/bujang-mila/pyproject.toml`
|
|
377
|
+
and `ui/package.json` (+ `npm install` for the lock file), check with
|
|
378
|
+
`python .github/scripts/check_version.py`, then push a tag `v<version>`.
|
|
379
|
+
`.github/workflows/release.yml` builds `bujang-ui-<version>.tgz` (`npm pack`), the standalone UI,
|
|
380
|
+
the sdist and wheel of `bujang` and `bujang-mila`, and attaches them to a GitHub release of the tag.
|
|
381
|
+
It fails if a version differs from the tag.
|
|
382
|
+
|
|
383
|
+
`bujang dev` needs a source checkout (it runs `npm run dev` in `ui/`, `npm install` first
|
|
384
|
+
if needed). Ctrl-C stops both; if one of them exits, the other is stopped too.
|