Skip to content
Merged

uv #23

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions .github/workflows/ci.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.1
22 changes: 22 additions & 0 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: unit

on:
pull_request:
push:
branches: [main]


jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Install the project
run: uv sync --all-extras --dev

- name: Run tests
run: uv run pytest -svv --cov=cortex tests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
__pycache__
*.egg-info
docs/build
temp
.coverage
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ repos:
rev: 0.6.0
hooks:
- id: nbstripout
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.2.1
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.7
hooks:
# Run the linter.
- id: ruff
name: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
20 changes: 4 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,11 @@ Rather than tack on auxiliary abstractions to a single input --> single task mod

Note: conda/mamba are no longer actively supported. We recommend using `uv` for package management.

Note: Support for Python versions > 3.10 is blocked by the current dependency on `pytorch-lightning==1.9.5`.

```bash
uv venv -n ~/.venv/cortex --python 3.10
uv sync
source ~/.venv/cortex/bin/activate
uv pip install pytorch-cortex
```


If you have a package version issue we provide pinned versions of all dependencies in `requirements.txt`.
To update the frozen dependencies run

```bash
uv pip freeze > requirements.txt
```


## Running

Use `cortex_train_model --config-name <CONFIG_NAME>` to train, e.g.:
Expand All @@ -57,14 +45,14 @@ Contributions are welcome!
### Install dev requirements and pre-commit hooks

```bash
python -m pip install -r requirements-dev.in
pre-commit install
uv sync --dev
uv run pre-commit install
```

### Testing

```bash
python -m pytest -v --cov-report term-missing --cov=./cortex ./tests
uv run pytest -v --cov-report term-missing --cov=./cortex ./tests
```

### Build and browse docs locally
Expand Down
Empty file removed README.rst
Empty file.
4 changes: 1 addition & 3 deletions cortex/data/dataset/_data_frame_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def __init__(
remove_archive=True,
)
else:
raise ValueError(
f"Dataset not found at {path}. " "If `download` is `True`, the dataset will be downloaded."
)
raise ValueError(f"Dataset not found at {path}. If `download` is `True`, the dataset will be downloaded.")
self._data = self._read_data(path, dedup=dedup, train=train, random_seed=random_seed, **kwargs)

def _read_data(self, path: str, dedup: bool, train: bool, random_seed: int, **kwargs: Any) -> DataFrame:
Expand Down
2 changes: 1 addition & 1 deletion cortex/model/elemental/_ddp_standardize.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def forward(self, Y: Tensor, Yvar: Optional[Tensor] = None) -> tuple[Tensor, Opt
f"Y.shape[:-2]={Y.shape[:-2]}."
)
if Y.size(-1) != self._m:
raise RuntimeError(f"Wrong output dimension. Y.size(-1) is {Y.size(-1)}; expected " f"{self._m}.")
raise RuntimeError(f"Wrong output dimension. Y.size(-1) is {Y.size(-1)}; expected {self._m}.")
stdvs = Y.std(dim=-2, keepdim=True)
stdvs = stdvs.where(stdvs >= self._min_stdv, torch.full_like(stdvs, 1.0))
means = Y.mean(dim=-2, keepdim=True)
Expand Down
48 changes: 40 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
[project]
name = "pytorch-cortex"
dynamic = ["version", "readme", "dependencies", "optional-dependencies"]
dynamic = ["version"]
readme = "README.md"
description = "A modular architecture for deep learning systems."
authors = [{name = "Samuel Stanton", email = "stanton.samuel@gene.com"}]
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3",
]
requires-python = ">=3.10"
dependencies = [
"boto3>=1.37.1",
"botorch>=0.9.4",
"cachetools>=5.5.2",
"edlib>=1.3.9.post1",
"hydra-core>=1.2.0",
"lightning>=2.0",
"numpy>=2",
"omegaconf>=2.3.0",
"pandas>=2",
"pyarrow>=19.0.1",
"pytorch-warmup>=0.2.0",
"s3fs>=2025.3.2",
"tabulate>=0.9.0",
"torch>=2.5.1",
"torchvision",
"tqdm>=4.67.1",
"transformers>=4.24.0",
"universal-pathlib>=0.2.6",
"wandb>=0.19.9",
]

[project.scripts]
cortex_train_model = "cortex.cmdline.train_cortex_model:main"
Expand All @@ -19,11 +42,6 @@ cortex_generate_designs = "cortex.cmdline.generate_designs:main"
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.in"]}
optional-dependencies = {dev = {file = ["requirements-dev.in"]}}
readme = {file = "README.rst"}

[tool.setuptools.packages.find]
include = ["cortex*"]

Expand All @@ -39,6 +57,11 @@ fallback_version = "0.0.0"

[tool.ruff]
line-length = 120
extend-exclude = [
"*.ipynb",
"**/torchinductor/**/*.py",
"notebooks",
]

[tool.ruff.lint]
select = [
Expand All @@ -61,5 +84,14 @@ ignore = [
"F401", # MODULE IMPORTED BUT UNUSED
]

[tool.uv]
cache-keys = [{file = "requirements.in"}, {file = "requirements-dev.in"}]
[dependency-groups]
dev = [
"ipykernel>=6.29.5",
"ipython>=8.34.0",
"pre-commit>=4.2.0",
"pytest>=8.3.5",
"pytest-cov>=6.1.0",
"sphinx>=8.1.3",
"sphinx-autoapi>=3.6.0",
"sphinx-rtd-theme>=3.0.2",
]
7 changes: 0 additions & 7 deletions requirements-dev.in

This file was deleted.

19 changes: 0 additions & 19 deletions requirements.in

This file was deleted.

Loading