Skip to content

Commit

Permalink
Adds pre-commit hooks (#216)
Browse files Browse the repository at this point in the history
* Adds a first version of the Ehrlich function proposed by Stanton et al

* Adds seeds for all functions in Ehrlich

* Adds tests for motif matching, seeding and optimal sequence creation

* Adds problem factory and associated tests

* Adds docstrings

* Adds pre-commit hooks

* Adds isort with black compatiblity

* Removes the examples folder from isort

* Adds pre-commit hooks

* Adds isort with black compatiblity

* Removes the examples folder from isort
  • Loading branch information
miguelgondu authored Jul 11, 2024
1 parent 52d0dd8 commit 7d531bd
Show file tree
Hide file tree
Showing 133 changed files with 385 additions and 636 deletions.
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
exclude: '.*\.pdb$'
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
1 change: 1 addition & 0 deletions examples/minimal_working_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import numpy as np

from poli import objective_factory

problem = objective_factory.create(name="white_noise")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
from pathlib import Path

import numpy as np
from wandb_observer import WandbObserver

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

from wandb_observer import WandbObserver

THIS_DIR = Path(__file__).parent.resolve()

if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"""

import numpy as np
import wandb

import wandb
from poli.core.black_box_information import BlackBoxInformation
from poli.core.util.abstract_observer import AbstractObserver

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
from pathlib import Path

import numpy as np
from mlflow_observer import MlFlowObserver

from poli import objective_factory

from mlflow_observer import MlFlowObserver

THIS_DIR = Path(__file__).parent.resolve()

if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

from pathlib import Path

import mlflow
import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
of how to instantiate it after registration.
"""

from poli.core.registry import register_observer

from print_observer import SimplePrintObserver

from poli.core.registry import register_observer

if __name__ == "__main__":
register_observer(
observer=SimplePrintObserver(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
"""

import numpy as np

from poli.core.registry import DEFAULT_OBSERVER_NAME
from print_observer import SimplePrintObserver
from poli import objective_factory

from poli import objective_factory
from poli.core.registry import DEFAULT_OBSERVER_NAME

if __name__ == "__main__":
# Instantiate the objective
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import numpy as np
import pandas as pd

from poli.core.util.proteins.defaults import AMINO_ACIDS
from poli import objective_factory
from poli.core.util.proteins.defaults import AMINO_ACIDS

THIS_DIR = Path(__file__).parent.resolve()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import numpy as np

from poli.objective_repository import QEDBlackBox, LogPBlackBox
from poli.objective_repository import LogPBlackBox, QEDBlackBox

THIS_DIR = Path(__file__).parent.resolve()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
the initial point, and its first evaluation.
"""

from typing import Tuple
from string import ascii_uppercase
from typing import Tuple

import numpy as np

Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ Homepage = "https://github.com/MachineLearningLifeScience/poli"
[tool.pytest.ini_options]
markers = [
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
]
]

[tool.isort]
profile = "black"
3 changes: 2 additions & 1 deletion src/poli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""poli, a library for discrete black-box objective functions."""

__author__ = "Simon Bartels & Miguel González-Duque (MLLS)"
from .core.util.isolation.instancing import instance_function_as_isolated_process

# from .core import get_problems
from .objective_factory import create
from .core.util.isolation.instancing import instance_function_as_isolated_process
from .objective_repository import get_problems
6 changes: 3 additions & 3 deletions src/poli/benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .guacamol import GuacaMolGoalDirectedBenchmark
from .pmo import PMOBenchmark
from .toy_continuous_functions_benchmark import (
ToyContinuousFunctionsBenchmark,
EmbeddedBranin2D,
EmbeddedHartmann6D,
ToyContinuousFunctionsBenchmark,
)
from .guacamol import GuacaMolGoalDirectedBenchmark
from .pmo import PMOBenchmark
9 changes: 4 additions & 5 deletions src/poli/benchmarks/guacamol.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
[2] Huang, Kexin, Tianfan Fu, Wenhao Gao, Yue Zhao, Yusuf Roohani, Jure Leskovec,
Connor W Coley, Cao Xiao, Jimeng Sun, and Marinka Zitnik.
“Therapeutics Data Commons: Machine Learning Datasets and Tasks for Drug Discovery and Development.”
Proceedings of Neural Information Processing Systems, NeurIPS Datasets and Benchmarks, 2021.
Proceedings of Neural Information Processing Systems, NeurIPS Datasets and Benchmarks, 2021.
"""

from typing import Literal, Union

from poli.core.problem import Problem
from poli.core.abstract_benchmark import AbstractBenchmark

from poli.core.problem import Problem
from poli.objective_repository import (
AlbuterolSimilarityProblemFactory,
AmlodipineMPOProblemFactory,
Expand All @@ -36,14 +35,14 @@
FexofenadineMPOProblemFactory,
IsomerC7H8N2O2ProblemFactory,
IsomerC9H10N2O2PF2ClProblemFactory,
LogPProblemFactory,
Median1ProblemFactory,
Median2ProblemFactory,
MestranolSimilarityProblemFactory,
OsimetrinibMPOProblemFactory,
PerindoprilMPOProblemFactory,
RanolazineMPOProblemFactory,
LogPProblemFactory,
QEDProblemFactory,
RanolazineMPOProblemFactory,
SAProblemFactory,
ScaffoldHopProblemFactory,
SitagliptinMPOProblemFactory,
Expand Down
4 changes: 2 additions & 2 deletions src/poli/benchmarks/pmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
[3] Huang, Kexin, Tianfan Fu, Wenhao Gao, Yue Zhao, Yusuf Roohani, Jure Leskovec,
Connor W Coley, Cao Xiao, Jimeng Sun, and Marinka Zitnik.
“Therapeutics Data Commons: Machine Learning Datasets and Tasks for Drug Discovery and Development.”
Proceedings of Neural Information Processing Systems, NeurIPS Datasets and Benchmarks, 2021.
Proceedings of Neural Information Processing Systems, NeurIPS Datasets and Benchmarks, 2021.
"""

from typing import Literal, Union

from poli.objective_repository import (
DRD2ProblemFactory,
JNK3ProblemFactory,
GSK3BetaProblemFactory,
JNK3ProblemFactory,
)

from .guacamol import GuacaMolGoalDirectedBenchmark
Expand Down
6 changes: 3 additions & 3 deletions src/poli/benchmarks/toy_continuous_functions_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
https://www.sfu.ca/~ssurjano/optimization.html.
"""

from typing import Union, List
from typing import List, Union

from poli.core.abstract_benchmark import AbstractBenchmark
from poli.core.problem import Problem

from poli.objective_repository import ToyContinuousProblemFactory
from poli.objective_repository.toy_continuous_problem.toy_continuous_problem import (
POSSIBLE_FUNCTIONS,
TWO_DIMENSIONAL_PROBLEMS,
SIX_DIMENSIONAL_PROBLEMS,
TWO_DIMENSIONAL_PROBLEMS,
)


Expand Down
7 changes: 3 additions & 4 deletions src/poli/core/abstract_black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
all objective functions should inherit.
"""

from multiprocessing import Pool, cpu_count
from warnings import warn

import numpy as np
from multiprocessing import Pool, cpu_count

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.batch import batched
from poli.core.util.alignment import is_aligned_input
from poli.core.exceptions import BudgetExhaustedException
from poli.core.util.batch import batched


class AbstractBlackBox:
Expand Down
2 changes: 1 addition & 1 deletion src/poli/core/benchmark_information.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Literal
from typing import Literal, Union


class BenchmarkInformation:
Expand Down
2 changes: 1 addition & 1 deletion src/poli/core/black_box_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- The alphabet of allowed characters.
"""

from typing import Union, Literal
from typing import Literal, Union


class BlackBoxInformation:
Expand Down
1 change: 0 additions & 1 deletion src/poli/core/chemistry/tdc_black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import numpy as np

from poli.core.abstract_black_box import AbstractBlackBox

from poli.core.util.isolation.instancing import get_inner_function


Expand Down
2 changes: 0 additions & 2 deletions src/poli/core/chemistry/tdc_isolated_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
"""

import numpy as np

from tdc import Oracle

from poli.core.abstract_isolated_function import AbstractIsolatedFunction

from poli.core.util.chemistry.string_to_molecule import translate_selfies_to_smiles


Expand Down
2 changes: 1 addition & 1 deletion src/poli/core/multi_objective_black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import numpy as np

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


class MultiObjectiveBlackBox(AbstractBlackBox):
Expand Down
7 changes: 3 additions & 4 deletions src/poli/core/proteins/foldx_black_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@
33(suppl_2), W382-W388.
"""

from typing import Union, List
from multiprocessing import cpu_count
from pathlib import Path
from time import time
from typing import List, Union
from uuid import uuid4
from multiprocessing import cpu_count

from poli.core.abstract_black_box import AbstractBlackBox
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,
parse_pdb_as_residues,
)
from poli.core.util.proteins.foldx import FoldxInterface

# This is the folder where all the files
# generated by FoldX will be stored.
Expand Down
7 changes: 3 additions & 4 deletions src/poli/core/proteins/foldx_isolated_function.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
from typing import Union, List
from multiprocessing import cpu_count
from pathlib import Path
from time import time
from typing import List, Union
from uuid import uuid4
from multiprocessing import cpu_count

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,
parse_pdb_as_residues,
)
from poli.core.util.proteins.foldx import FoldxInterface

# This is the folder where all the files
# generated by FoldX will be stored.
Expand Down
13 changes: 6 additions & 7 deletions src/poli/core/registry.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
"""This module contains utilities for registering problems and observers.
"""

from typing import List, Union, Dict, Type
import configparser
from pathlib import Path
import warnings
import subprocess
import warnings
from pathlib import Path
from typing import Dict, List, Type, Union

from poli.core.abstract_isolated_function import AbstractIsolatedFunction
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.abstract_observer import AbstractObserver
from poli.core.util.objective_management.make_run_script import (
make_run_script,
make_observer_script,
make_isolated_function_script,
make_observer_script,
make_run_script,
)

# from poli.objective_repository import AVAILABLE_PROBLEM_FACTORIES, AVAILABLE_OBJECTIVES
Expand Down
2 changes: 1 addition & 1 deletion src/poli/core/util/batch/batch_input.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""This module implements a batched input generator."""

from typing import Iterable
from itertools import islice
from typing import Iterable


def batched(iterable: Iterable, chunk_size: int):
Expand Down
3 changes: 1 addition & 2 deletions src/poli/core/util/chemistry/string_to_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

from typing import List

from rdkit import Chem

import selfies as sf
from rdkit import Chem


def translate_smiles_to_selfies(
Expand Down
Loading

0 comments on commit 7d531bd

Please sign in to comment.