dmx Python Implementation
Use this skill for changes under src/dmx, examples*, and related Python entry points.
Start Here
- Read the target module and at least one neighboring module in the same package before editing.
- Read the matching tests when they exist.
- Keep changes scoped to the package split already used by the repo:
src/dmx/stats: NumPy/SciPy statistical distributions
src/dmx/torch_stats: PyTorch-backed statistical distributions
src/dmx/utils: non-torch utilities
src/dmx/torch_utils: torch-specific utilities
examples*: runnable examples, kept simple and explicit
Coding Rules Enforced by CI
- Format for Black with line length
88.
- Sort imports with isort using the Black profile.
- Add type annotations for every new or changed function or method.
- Do not rely on implicit
Optional; write Optional[T] or T | None explicitly.
- Return concrete types where possible. Avoid untyped helper functions.
- Keep code compatible with the repo's Python floor of
3.10.
- Prefer small, direct functions over clever abstractions. This repo already tolerates some repetitive statistical scaffolding; do not invent framework layers just to deduplicate a few lines.
- Preserve device and dtype behavior in torch code. In this repo, MPS and CPU/GPU differences are often handled intentionally.
- Avoid broad exception handling unless the surrounding code already depends on it or the failure mode is genuinely variable.
- If a
pylint disable is necessary, keep it local and explain why in one short comment.
Docstrings
- Use Google-style docstrings for public functions, methods, and classes you touch.
- Keep the first line short and descriptive.
- Include
Args, Returns, and Raises when they add real value.
- Match the repo's current style: concise summaries, then argument details only where behavior is not obvious.
- Be stricter in modules similar to:
src/dmx/stats/pdist.py
src/dmx/torch_stats/pdist.py
src/dmx/utils/optsutil.py
src/dmx/utils/vector.py
Those paths are checked directly by pydocstyle in CI.
Implementation Guidance
- Preserve public names and constructor signatures unless the task explicitly changes API.
- When touching distributions, maintain consistency between scalar and sequence paths such as
log_density, seq_log_density, encoders, samplers, and estimators.
- Prefer existing helper utilities over reimplementing numeric or tensor behavior.
- In torch code, keep generators, devices, and dtype conversions explicit.
- In utility code, favor NumPy arrays and deterministic conversions over loose container handling.
Validation
Run focused checks on touched files first, then broader checks if the change is substantial.
Common commands:
poetry run black --check <paths>
poetry run isort --check <paths>
poetry run mypy --explicit-package-bases <paths>
poetry run pylint <paths> --jobs=1 --fail-under=10
If the change touches one of the docstring-gated files, also run:
poetry run pydocstyle <path>
If behavior changed, run the matching tests in tests/ as well.
1---2name: dmx-python-implementation3description: dmx Python Implementation4---56# dmx Python Implementation78Use this skill for changes under `src/dmx`, `examples*`, and related Python entry points.910## Start Here11121. Read the target module and at least one neighboring module in the same package before editing.132. Read the matching tests when they exist.143. Keep changes scoped to the package split already used by the repo:15 - `src/dmx/stats`: NumPy/SciPy statistical distributions16 - `src/dmx/torch_stats`: PyTorch-backed statistical distributions17 - `src/dmx/utils`: non-torch utilities18 - `src/dmx/torch_utils`: torch-specific utilities19 - `examples*`: runnable examples, kept simple and explicit2021## Coding Rules Enforced by CI2223- Format for Black with line length `88`.24- Sort imports with isort using the Black profile.25- Add type annotations for every new or changed function or method.26- Do not rely on implicit `Optional`; write `Optional[T]` or `T | None` explicitly.27- Return concrete types where possible. Avoid untyped helper functions.28- Keep code compatible with the repo's Python floor of `3.10`.29- Prefer small, direct functions over clever abstractions. This repo already tolerates some repetitive statistical scaffolding; do not invent framework layers just to deduplicate a few lines.30- Preserve device and dtype behavior in torch code. In this repo, MPS and CPU/GPU differences are often handled intentionally.31- Avoid broad exception handling unless the surrounding code already depends on it or the failure mode is genuinely variable.32- If a `pylint` disable is necessary, keep it local and explain why in one short comment.3334## Docstrings3536- Use Google-style docstrings for public functions, methods, and classes you touch.37- Keep the first line short and descriptive.38- Include `Args`, `Returns`, and `Raises` when they add real value.39- Match the repo's current style: concise summaries, then argument details only where behavior is not obvious.40- Be stricter in modules similar to:41 - `src/dmx/stats/pdist.py`42 - `src/dmx/torch_stats/pdist.py`43 - `src/dmx/utils/optsutil.py`44 - `src/dmx/utils/vector.py`45 Those paths are checked directly by `pydocstyle` in CI.4647## Implementation Guidance4849- Preserve public names and constructor signatures unless the task explicitly changes API.50- When touching distributions, maintain consistency between scalar and sequence paths such as `log_density`, `seq_log_density`, encoders, samplers, and estimators.51- Prefer existing helper utilities over reimplementing numeric or tensor behavior.52- In torch code, keep generators, devices, and dtype conversions explicit.53- In utility code, favor NumPy arrays and deterministic conversions over loose container handling.5455## Validation5657Run focused checks on touched files first, then broader checks if the change is substantial.5859Common commands:6061```bash62poetry run black --check <paths>63poetry run isort --check <paths>64poetry run mypy --explicit-package-bases <paths>65poetry run pylint <paths> --jobs=1 --fail-under=1066```6768If the change touches one of the docstring-gated files, also run:6970```bash71poetry run pydocstyle <path>72```7374If behavior changed, run the matching tests in `tests/` as well.