Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ruff formatter instead of black formatter #136

Merged
merged 1 commit into from
Mar 18, 2024
Merged
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ uninstall: FORCE

lint: FORCE
ruff check .
black --check .
ruff format --check .

docs: FORCE
cd docs && make html
Expand All @@ -18,7 +18,7 @@ license: FORCE

format: license FORCE
ruff check --fix .
black .
ruff format .

typecheck: FORCE
mypy cellarium tests
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ To run the tests::

To automatically format the code::

$ make format # runs ruff and black formatters
$ make format # runs ruff formatter and fixes linter errors

To run the linters::

$ make lint # runs ruff and black checks
$ make lint # runs ruff linter and checks for formatter errors

To build the documentation::

Expand Down
6 changes: 3 additions & 3 deletions cellarium/ml/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def lightning_cli_factory(
"max_epochs": 1, # one pass
"strategy": {
"class_path": "lightning.pytorch.strategies.DDPStrategy",
"init_args": {"broadcast_buffers": False},
"dict_kwargs": {"broadcast_buffers": False},
},
},
)
Expand Down Expand Up @@ -373,7 +373,7 @@ def incremental_pca(args: ArgsType = None) -> None:
"max_epochs": 1, # one pass
"strategy": {
"class_path": "lightning.pytorch.strategies.DDPStrategy",
"init_args": {"broadcast_buffers": False},
"dict_kwargs": {"broadcast_buffers": False},
},
},
)
Expand Down Expand Up @@ -455,7 +455,7 @@ def onepass_mean_var_std(args: ArgsType = None) -> None:
"max_epochs": 1, # one pass
"strategy": {
"class_path": "lightning.pytorch.strategies.DDPStrategy",
"init_args": {"broadcast_buffers": False},
"dict_kwargs": {"broadcast_buffers": False},
},
},
)
Expand Down
1 change: 0 additions & 1 deletion cellarium/ml/models/geneformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def tokenize_with_perturbations(
feature_deletion: list[str] | None = None,
feature_map: dict[str, int] | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:

# activation and deletion happen before sorting
if feature_deletion:
if not all([g in self.var_names_g for g in feature_deletion]):
Expand Down
13 changes: 6 additions & 7 deletions notebooks/geneformer_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
"metadata": {},
"outputs": [],
"source": [
"from cellarium.ml.models import Geneformer\n",
"from cellarium.ml.core import CellariumPipeline\n",
"from cellarium.ml.transforms import NormalizeTotal, DivideByScale\n",
"import os\n",
"import pickle\n",
"import tempfile\n",
"\n",
"import torch\n",
"from transformers import AutoModel\n",
"\n",
"import os\n",
"import pickle\n",
"import tempfile"
"from cellarium.ml.core import CellariumPipeline\n",
"from cellarium.ml.models import Geneformer\n",
"from cellarium.ml.transforms import DivideByScale, NormalizeTotal"
]
},
{
Expand All @@ -32,7 +32,6 @@
"outputs": [],
"source": [
"def get_pretrained_geneformer_pipeline(device) -> CellariumPipeline:\n",
"\n",
" with tempfile.TemporaryDirectory() as tmpdir:\n",
" os.system(\n",
" f\"wget -O {os.path.join(tmpdir, 'token_dictionary.pkl')} https://huggingface.co/ctheodoris/Geneformer/resolve/main/geneformer/token_dictionary.pkl\"\n",
Expand Down
8 changes: 3 additions & 5 deletions notebooks/mup_mlp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
"outputs": [],
"source": [
"import math\n",
"from collections.abc import Callable, Iterator\n",
"from collections.abc import Callable\n",
"from typing import Literal\n",
"\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"import torch\n",
"import torch.nn.functional as F\n",
"from torch import nn\n",
"from torchvision import datasets, transforms\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from cellarium.ml.models import MuLinear\n",
"from cellarium.ml.utilities.testing import get_coord_data"
Expand Down
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ dependencies = [
dynamic = ["version"]

[project.optional-dependencies]
lint = [
"black[jupyter]",
"ruff",
]
lint = ["ruff"]
mypy = ["mypy", "types-PyYAML"]
test = [
"pytest-xdist",
Expand Down Expand Up @@ -78,10 +75,11 @@ dev_template = "{tag}.post{ccount}"

[tool.ruff]
line-length = 120
select = ["E", "F", "I", "W"]
extend-include = ["*.ipynb"]
target-version = "py310"

[tool.black]
line-length = 120
[tool.ruff.lint]
select = ["E", "F", "I", "W"]

[tool.mypy]
ignore_missing_imports = true
Expand Down
Loading