|
| 1 | +# PROJECT KNOWLEDGE BASE |
| 2 | + |
| 3 | +**Generated:** 2026-08-21 16:23 UTC |
| 4 | +**Commit:** 7d28428 |
| 5 | +**Branch:** work/priorities-and-docs |
| 6 | + |
| 7 | +## OVERVIEW |
| 8 | + |
| 9 | +Clustrix is a Python distributed computing framework: `@cluster` on a function serializes it (dill/cloudpickle, by value) and runs it on a configured backend — `local`, `ssh`, `slurm`, `huggingface` (HF Jobs). Those four are the whole list (`clustrix.config.SUPPORTED_CLUSTER_TYPES`); pbs/sge/kubernetes/AWS/GCP/Azure/Lambda raise `ValueError` (issues #140–#146). Python >=3.10, version 0.2.0, beta. |
| 10 | + |
| 11 | +**CLAUDE.md is the deep curated knowledge base** (architecture, security invariants, mocking policy, two-venv execution). This file is the map; read CLAUDE.md before non-trivial work. |
| 12 | + |
| 13 | +## STRUCTURE |
| 14 | + |
| 15 | +``` |
| 16 | +clustrix/ |
| 17 | +├── clustrix/ # the package — flat, 34 modules (see clustrix/AGENTS.md) |
| 18 | +├── tests/ # unit/ + real_world/ + integration/ + comprehensive/ (see tests/AGENTS.md) |
| 19 | +├── scripts/ # dev/ops tooling; aws/ is operator cleanup, NOT a backend |
| 20 | +├── docs/ # source/ (Sphinx) + evidence/ (committed proof) + build/ (generated) |
| 21 | +├── notes/ # session notes; per user policy, update as work proceeds |
| 22 | +├── .claude/ # pm command system (commands/pm, scripts/pm, rules, agents) |
| 23 | +├── .github/workflows/ # tests.yml, fast_ci.yml, real-world-tests.yml |
| 24 | +├── build/ # STALE setuptools output — see NOTES |
| 25 | +├── htmlcov/, performance_test_results/, docs/build/ # generated; ignore |
| 26 | +└── pyproject.toml # the ONLY pytest/coverage config; black/mypy/flake8 too |
| 27 | +``` |
| 28 | + |
| 29 | +## WHERE TO LOOK |
| 30 | + |
| 31 | +| Task | Location | Notes | |
| 32 | +|-|-|-| |
| 33 | +| Add a backend | `config.SUPPORTED_CLUSTER_TYPES` + `executor_core.py` dispatch + `executor_schedulers.py` | Gate: real job on real hardware, evidence committed | |
| 34 | +| Change execution flow | `executor_core.py` (ClusterExecutor), split across `executor_connections/_schedulers/_scheduler_status` | `executor.py` is a 39-line shim | |
| 35 | +| Touch serialization | `utils.py` `serialize_function`/`deserialize_function`, `generate_two_venv_execution_commands` | Keep each serialize/deserialize pair symmetric; never stdlib `pickle` | |
| 36 | +| Config change | `config.py` (ClusterConfig, configure, load_config) | No env-var overlay exists; only `CLUSTRIX_CONFIG_DIR` + `password_env_var` | |
| 37 | +| SSH/auth | `ssh_security.py` (host keys), `ssh_utils.py`, `auth_manager.py`, `credential_manager.py` | Never `AutoAddPolicy` directly | |
| 38 | +| Notebook UI | `notebook_magic_core.py` (%%remote, %clustrix), `modern_notebook_widget.py` | Widget never auto-displays on import unless `CLUSTRIX_AUTO_WIDGET=1` | |
| 39 | +| Data staging | `staging.py` (`data_package`, `materialize_packages`) | Declaration only; nothing inferred; nothing auto-deleted | |
| 40 | +| Quality gates | `scripts/pre_push_check.py` (retries 5x), `scripts/check_quality.py` | Run repeatedly until ALL pass before commit | |
| 41 | +| Regenerate backend evidence | `scripts/verify_cluster_usecases.py`, `scripts/collect_execution_evidence.py` | Output committed under `docs/evidence/` | |
| 42 | +| CI changes | `.github/workflows/` | `real-world-tests.yml` has NO push/PR trigger deliberately (credentialed jobs); secrets gate via `check-secrets` job outputs — `secrets` context is illegal in `if:` | |
| 43 | + |
| 44 | +## CODE MAP |
| 45 | + |
| 46 | +Centrality from codegraph (Python LSP not installed; ruff is lint-only). |
| 47 | + |
| 48 | +| Symbol | Type | Location | Refs | Role | |
| 49 | +|-|-|-|-|-| |
| 50 | +| `configure` | function | `clustrix/config.py:559` | 288 | Singleton config entry point; validates all keys before applying any | |
| 51 | +| `ClusterExecutor` | class | `clustrix/executor_core.py:27` | 81 | Dispatch, submission, HMAC-verified result retrieval | |
| 52 | +| `cluster` | decorator | `clustrix/decorator.py:58` | public API | `@cluster`; extras limited to `hf_*` + `key_file` — `cluster_type=` is NOT accepted | |
| 53 | +| `ClusterConfig` | dataclass | `clustrix/config.py` | high | Plain-`str` `cluster_type`; no ClusterType enum | |
| 54 | +| `ClusterfyMagics` | class | `clustrix/notebook_magic_core.py:69` | 6 | `%%remote`, `%clustrix`, deprecated `%%clusterfy` alias | |
| 55 | +| `LocalExecutor` | class | `clustrix/local_executor.py` | — | Real local parallelism; `choose_executor_type` at :339 | |
| 56 | +| `HFJobsManager` | class | `clustrix/hf_jobs.py` | — | HuggingFace Jobs backend; 256 KB payload cap | |
| 57 | +| `data_package` | function | `clustrix/staging.py` | — | Declared data staging; large packages go to a private HF dataset repo | |
| 58 | + |
| 59 | +## CONVENTIONS |
| 60 | + |
| 61 | +- black line-length 88, target py310, **pinned `black==26.3.1`** (unbounded `>=` broke CI, #110); flake8 max-line 88, extend-ignore E203/W503; mypy python_version 3.10, `files=["clustrix/"]`, tests ignored, `follow_imports="skip"`. |
| 62 | +- **pyproject.toml is the only pytest config.** No pytest.ini/tox.ini/setup.cfg — the first found shadows this block (#130); `tests/unit/test_pytest_config.py` enforces it. |
| 63 | +- pytest `--strict-markers`; all 6 markers registered in pyproject. `testpaths` must never list `tests/integration` (billable, #109). |
| 64 | +- Coverage `fail_under = 66` — a floor 2 points under measured 68%, not a target (#115). |
| 65 | +- Pre-commit runs on python3.12 explicitly (system python3 may be 3.9, which the project does not support). |
| 66 | +- Version string lives in 4 places and must stay identical: `pyproject.toml`, `setup.py`, `clustrix/__init__.py`, `docs/source/conf.py`. |
| 67 | +- Comments explain *why*, often with issue refs (#109–#159). Match that style; do not strip them. |
| 68 | + |
| 69 | +## ANTI-PATTERNS (THIS PROJECT) |
| 70 | + |
| 71 | +- Never `set_missing_host_key_policy(paramiko.AutoAddPolicy())` — go through `ssh_security.configure_host_key_policy`. |
| 72 | +- Never stdlib `pickle` in the two-venv handoffs — dill/cloudpickle only, symmetric pairs. |
| 73 | +- Never a mock as a fallback when the real thing is unavailable — fail instead. Production code must never know it is being tested (no `isinstance(x, Mock)`; `grep -rn "unittest.mock\|MagicMock" clustrix/` stays empty). |
| 74 | +- Never weaken a failing test; fix the code or explicitly rewrite a wrong assertion. |
| 75 | +- Never document unsupported backends (pbs/sge/k8s/cloud VMs), cost monitoring, or HF Spaces as working. |
| 76 | +- Never add `@cluster(cluster_type=...)` to examples — it is ignored with a warning; backend is set via `configure()`. |
| 77 | +- `auto_gpu_parallel` does nothing (deleted; it fabricated results). Don't document it as a feature. |
| 78 | +- No `cluster_put`/`cluster_get` — the `cluster_*` fs helpers are read-only by design. |
| 79 | + |
| 80 | +## UNIQUE STYLES |
| 81 | + |
| 82 | +- Honesty-first docs: verified vs unsupported backends stated up front; evidence transcripts committed under `docs/evidence/`. |
| 83 | +- Defensive validation with explanatory errors (removed settings raise `ValueError` naming the replacement; unknown config keys get did-you-mean). |
| 84 | +- One shared async executor per process (`decorator._shared_async_executor`), context-manager support on `SimpleAsyncClusterExecutor`. |
| 85 | + |
| 86 | +## COMMANDS |
| 87 | + |
| 88 | +```bash |
| 89 | +pip install -e ".[dev]" # dev env (widget extra needed for widget tests) |
| 90 | +python scripts/pre_push_check.py # black+flake8+mypy+pytest, retries until clean — run before EVERY commit |
| 91 | +pytest tests/ -m "not real_world" --ignore=tests/real_world --ignore=tests/integration # what CI runs |
| 92 | +pytest tests/unit/ -q # fast loop |
| 93 | +python scripts/collect_execution_evidence.py # real job per reachable backend; needs credentials |
| 94 | +cd docs && make html # docs build |
| 95 | +``` |
| 96 | + |
| 97 | +## NOTES |
| 98 | + |
| 99 | +- **`build/lib/clustrix/` is stale**: it still contains `kubernetes/`, `cloud_providers/`, `pricing_clients/`, `cost_providers/` — modules deleted from the source tree. Grep results there are ghosts; exclude `build/` from searches. |
| 100 | +- `htmlcov/`, `performance_test_results/`, `docs/build/` are generated output, not source. |
| 101 | +- `tests/integration/` provisions real billable AWS resources; refuses without `CLUSTRIX_ALLOW_BILLABLE=1` (guard reads `config.args`, deliberately). |
| 102 | +- `remote_work_dir` must be on a filesystem compute nodes see — `/tmp` dies with exit 127 on SLURM. |
| 103 | +- Fresh count: 21 of 166 test modules use `unittest.mock` (issue #117 migrates them; new tests must not add to it). |
0 commit comments