Skip to content

Commit

Permalink
Lints with ruff (#226)
Browse files Browse the repository at this point in the history
* Runs the ruff linter

* Adds ruff to the pre-commit hooks

* Runs ruff and adds it to the linting checks

* Fixes a small error on tox's use of ruff

* Fixes an erroneous import in a test
  • Loading branch information
miguelgondu authored Jul 29, 2024
1 parent 664a69b commit 2b4142a
Show file tree
Hide file tree
Showing 68 changed files with 122 additions and 185 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ repos:
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.5
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import numpy as np
from wandb_observer import WandbObserver

from poli.core.problem import Problem
from poli.objective_repository import QEDProblemFactory

THIS_DIR = Path(__file__).parent.resolve()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ def initialize_observer(
}
)

mlflow.log_param("x0", x0)
mlflow.log_param("y0", y0)
mlflow.log_param("seed", seed)

def observe(self, x: np.ndarray, y: np.ndarray, context=None) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

from string import ascii_uppercase
from typing import Tuple

import numpy as np

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ markers = [

[tool.isort]
profile = "black"

[tool.ruff]
exclude = ["src/poli/core/util/proteins/rasp/inner_rasp", "src/poli/objective_repository/gfp_cbas"]
2 changes: 2 additions & 0 deletions src/poli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
# from .core import get_problems
from .objective_factory import create
from .objective_repository import get_problems

__all__ = ["create", "get_problems", "instance_function_as_isolated_process"]
8 changes: 8 additions & 0 deletions src/poli/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
EmbeddedHartmann6D,
ToyContinuousFunctionsBenchmark,
)

__all__ = [
"GuacaMolGoalDirectedBenchmark",
"PMOBenchmark",
"ToyContinuousFunctionsBenchmark",
"EmbeddedBranin2D",
"EmbeddedHartmann6D",
]
1 change: 0 additions & 1 deletion src/poli/core/abstract_black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from poli.core.black_box_information import BlackBoxInformation
from poli.core.exceptions import BudgetExhaustedException
from poli.core.problem_setup_information import ProblemSetupInformation
from poli.core.util.abstract_observer import AbstractObserver
from poli.core.util.alignment import is_aligned_input
from poli.core.util.batch import batched
Expand Down
5 changes: 0 additions & 5 deletions src/poli/core/abstract_problem_factory.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
"""This module implements the abstract problem factory."""

from typing import Tuple

import numpy as np

from poli.core.abstract_black_box import AbstractBlackBox
from poli.core.black_box_information import BlackBoxInformation
from poli.core.problem import Problem

Expand Down
2 changes: 1 addition & 1 deletion src/poli/core/chemistry/tdc_isolated_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __call__(self, x, context=None):
scores : array-like
An array of oracle scores computed for each input molecule.
"""
if not x.dtype.kind in ["U", "S"]:
if x.dtype.kind not in ["U", "S"]:
raise ValueError(
f"We expect x to be an array of strings, but we got {x.dtype}"
)
Expand Down
1 change: 0 additions & 1 deletion src/poli/core/multi_objective_black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from poli.core.abstract_black_box import AbstractBlackBox
from poli.core.black_box_information import BlackBoxInformation
from poli.core.problem_setup_information import ProblemSetupInformation


class MultiObjectiveBlackBox(AbstractBlackBox):
Expand Down
2 changes: 0 additions & 2 deletions src/poli/core/problem_setup_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Implements the problem setup information, which contains the problem information (e.g. alphabet, sequence length...).
"""

import numpy as np

from poli.core.black_box_information import BlackBoxInformation


Expand Down
2 changes: 0 additions & 2 deletions src/poli/core/proteins/foldx_isolated_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from multiprocessing import cpu_count
from pathlib import Path
from time import time
from typing import List, Union
Expand All @@ -7,7 +6,6 @@
import numpy as np

from poli.core.abstract_isolated_function import AbstractIsolatedFunction
from poli.core.problem_setup_information import ProblemSetupInformation
from poli.core.util.proteins.foldx import FoldxInterface
from poli.core.util.proteins.pdb_parsing import (
parse_pdb_as_residue_strings,
Expand Down
2 changes: 1 addition & 1 deletion src/poli/core/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import warnings
from pathlib import Path
from typing import Dict, List, Type, Union
from typing import List, Type, Union

from poli.core.abstract_black_box import AbstractBlackBox
from poli.core.abstract_isolated_function import AbstractIsolatedFunction
Expand Down
2 changes: 2 additions & 0 deletions src/poli/core/util/alignment/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .is_aligned import is_aligned_input

__all__ = ["is_aligned_input"]
2 changes: 2 additions & 0 deletions src/poli/core/util/batch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Utility functions for batching data."""

from .batch_input import batched

__all__ = ["batched"]
4 changes: 2 additions & 2 deletions src/poli/core/util/chemistry/string_to_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def translate_smiles_to_selfies(
selfies_strings.append(sf.encoder(smile))
except sf.EncoderError:
if strict:
raise ValueError(f"Failed to encode SMILES to SELFIES.")
raise ValueError("Failed to encode SMILES to SELFIES.")
else:
selfies_strings.append(None)

Expand Down Expand Up @@ -78,7 +78,7 @@ def translate_selfies_to_smiles(
smiles_strings.append(sf.decoder(selfies))
except sf.DecoderError:
if strict:
raise ValueError(f"Failed to decode SELFIES to SMILES.")
raise ValueError("Failed to decode SELFIES to SMILES.")
else:
smiles_strings.append(None)

Expand Down
2 changes: 2 additions & 0 deletions src/poli/core/util/files/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Utilities for downloading files from GitHub repositories."""

from .download_files_from_github import download_file_from_github_repository

__all__ = ["download_file_from_github_repository"]
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def get_connection(port: int, password: str) -> Client:
# if we manage to establish a connection we exit the function
return Client(address, authkey=password.encode())
# maybe the host process isn't ready yet
except EOFError as e:
except EOFError:
pass
except ConnectionRefusedError as e:
except ConnectionRefusedError:
pass
retries -= 1
# when we get here, e must have been instantiated
logging.fatal("Could not connect to host process.")
raise e
raise ConnectionError("Could not connect to host process.")


class ProcessWrapper:
Expand Down
2 changes: 1 addition & 1 deletion src/poli/core/util/isolation/external_black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def terminate(self):
try:
self.observer.finish()
self.observer = None
except:
except Exception:
pass

def __getattr__(self, __name: str) -> Any:
Expand Down
4 changes: 2 additions & 2 deletions src/poli/core/util/isolation/instancing.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ def register_isolated_function_if_available(
# Register problem
if name == "tdc__isolated":
logging.debug(
f"poli 🧪: Registered the isolated function from the repository."
"poli 🧪: Registered the isolated function from the repository."
)
__register_isolated_function_from_core(name, quiet=quiet)
config = load_config()
else:
logging.debug(
f"poli 🧪: Registered the isolated function from the repository."
"poli 🧪: Registered the isolated function from the repository."
)
__register_isolated_function_from_repository(name, quiet=quiet)
# Refresh the config
Expand Down
1 change: 0 additions & 1 deletion src/poli/core/util/objective_management/make_run_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import List, Type, Union

from poli import external_isolated_function_script, external_problem_factory_script
from poli.core.abstract_black_box import AbstractBlackBox
from poli.core.abstract_isolated_function import AbstractIsolatedFunction
from poli.core.abstract_problem_factory import AbstractProblemFactory
from poli.core.util import observer_wrapper
Expand Down
5 changes: 1 addition & 4 deletions src/poli/core/util/observer_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

from poli.core.util.abstract_observer import AbstractObserver
from poli.core.util.inter_process_communication.process_wrapper import get_connection
from poli.external_problem_factory_script import (
dynamically_instantiate,
parse_factory_kwargs,
)
from poli.external_problem_factory_script import dynamically_instantiate


def start_observer_process(observer_name, port: int, password: str):
Expand Down
2 changes: 2 additions & 0 deletions src/poli/core/util/proteins/rasp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

from .load_models import load_cavity_and_downstream_models
from .rasp_interface import RaspInterface

__all__ = ["load_cavity_and_downstream_models", "RaspInterface"]
Loading

0 comments on commit 2b4142a

Please sign in to comment.