Skip to content

Commit 3d4fc40

Browse files
authored
Fixes a bug in the initialization of random mutation (#66)
* Fixes a bug in the initialization of random mutation * Removes test due to space requirements * removes the test for real * Adds the ability to provide a tokenizer in random mutation solver * Bumps dev version
1 parent a0d8c86 commit 3d4fc40

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "poli-baselines"
7-
version = "1.0.2"
7+
version = "1.0.2.dev1"
88
description = "poli-baselines, a library of discrete objective optimizers"
99
readme = "README.md"
1010
authors = [{name="Miguel González-Duque", email="[email protected]"}]
@@ -94,7 +94,7 @@ markers = [
9494
profile = "black"
9595

9696
[tool.bumpversion]
97-
current_version = "1.0.2"
97+
current_version = "1.0.2.dev1"
9898
parse = """(?x)
9999
(?P<major>0|[1-9]\\d*)\\.
100100
(?P<minor>0|[1-9]\\d*)\\.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = poli_baselines
3-
version = 1.0.2
3+
version = 1.0.2.dev1
44
author_email = [email protected]
55
description = Baselines for Discrete Sequence Optimization, focusing on proteins
66
long_description = file: readme.md

src/poli_baselines/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.2"
1+
__version__ = "1.0.2.dev1"

src/poli_baselines/solvers/simple/random_mutation.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"""
1111

1212
import random
13+
import warnings
14+
from typing import Callable
1315

1416
import numpy as np
1517
from poli.core.abstract_black_box import AbstractBlackBox
@@ -28,7 +30,23 @@ def __init__(
2830
batch_size: int = 1,
2931
greedy: bool = True,
3032
alphabet: list[str] | None = None,
33+
tokenizer: Callable[[str], list[str]] | None = None,
3134
):
35+
if x0.ndim == 1:
36+
if tokenizer is None:
37+
warnings.warn(
38+
"In the initialization of the RandomMutation solver: \n"
39+
"The input is a 1D array, but no tokenizer was provided.\n"
40+
"Assuming that the input is a string that can be tokenized\n"
41+
"character by character using list(x_i)."
42+
)
43+
44+
def tokenizer(x):
45+
return list(x)
46+
47+
x0_ = [tokenizer(x_i) for x_i in x0]
48+
x0 = np.array(x0_)
49+
3250
super().__init__(black_box, x0, y0)
3351
self.alphabet = black_box.info.alphabet if alphabet is None else alphabet
3452
self.alphabet_without_empty = [s for s in self.alphabet if s != ""]

src/poli_baselines/tests/solvers/simple/test_random_mutation.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,3 @@ def test_random_mutation_in_docs():
4141
solver.solve(max_iter=100)
4242

4343
print(solver.get_best_solution())
44-
45-
46-
if __name__ == "__main__":
47-
test_random_mutation_in_docs()

0 commit comments

Comments
 (0)