Skip to content

Commit

Permalink
Fix handling of quoted strings with the nevergrad sweeper (facebookre…
Browse files Browse the repository at this point in the history
…search#2613)

This also changes the type of non-sweep variables, that all become
strings in the eye of nevergrad, while in the past they could also be
for instance int or float. This should not be an issue since nevergrad
is not supposed to touch them.
  • Loading branch information
odelalleau authored Mar 20, 2023
1 parent ff8c3bd commit 4802c40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create_nevergrad_param_from_config(
def create_nevergrad_parameter_from_override(override: Override) -> Any:
val = override.value()
if not override.is_sweep_override():
return val
return override.get_value_element_as_str()
if override.is_choice_sweep():
assert isinstance(val, ChoiceSweep)
vals = [x for x in override.sweep_iterator(transformer=Transformer.encode)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def assert_ng_param_equals(expected: Any, actual: Any) -> None:
elif isinstance(actual, ng.p.Log) or isinstance(actual, ng.p.Scalar):
assert expected.bounds == actual.bounds
assert expected.integer == actual.integer
elif isinstance(actual, str):
assert expected == actual
else:
assert False, f"Unexpected type: {type(actual)}"

Expand Down Expand Up @@ -95,6 +97,13 @@ def test_create_nevergrad_parameter_from_config(
"key=tag(log, int(interval(1,12)))",
get_scalar_with_integer_bounds(lower=1, upper=12, type=ng.p.Log),
),
("key=abc", "abc"),
("key='a&c'", "'a&c'"),
("key='${f:${x}}'", "'${f:${x}}'"),
(r"key=$\{f\:$\{x\}\}", r"$\{f\:$\{x\}\}"),
("key=0", "0"),
("key=true", "True"),
("key=null", "null"),
],
)
def test_create_nevergrad_parameter_from_override(
Expand Down

0 comments on commit 4802c40

Please sign in to comment.