Skip to content
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
5 changes: 5 additions & 0 deletions autofit/non_linear/search/mle/drawer/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def __init__(
An SQLalchemy session instance so the results of the model-fit are written to an SQLite database.
"""

# Drawer is single-core only; drop any saved number_of_cores so a
# round-tripped search.json (which records the resolved value) can be
# deserialized without colliding with the hardcoded kwarg below.
kwargs.pop("number_of_cores", None)

super().__init__(
name=name,
path_prefix=path_prefix,
Expand Down
15 changes: 15 additions & 0 deletions test_autofit/non_linear/search/optimize/test_drawer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

import autofit as af
from autoconf.dictable import from_dict, to_dict

pytestmark = pytest.mark.filterwarnings("ignore::FutureWarning")

Expand All @@ -21,3 +22,17 @@ def test__explicit_params():

assert search.total_draws == 50
assert isinstance(search.initializer, af.InitializerBall)


def test__dict_round_trip_with_number_of_cores():
# A round-tripped Drawer.search.json carries `number_of_cores` at the top
# level (the resolved value, always 1). Before the fix, this collided with
# the hardcoded super().__init__(number_of_cores=1, **kwargs) call and
# raised `TypeError: got multiple values for keyword argument`.
dictionary = to_dict(af.Drawer(total_draws=3))
assert "number_of_cores" in dictionary["arguments"]

restored = from_dict(dictionary)
assert isinstance(restored, af.Drawer)
assert restored.total_draws == 3
assert restored.number_of_cores == 1
Loading