Skip to content

Commit

Permalink
code clean up + add notes to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
danrgll committed Jun 18, 2024
1 parent 285b993 commit 4417942
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions docs/reference/declarative_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
### Configuring with YAML
Configure your experiments using a YAML file, which serves as a central reference for setting up your project.
This approach simplifies sharing, reproducing and modifying configurations.

!!! note
You can partially define arguments in the YAML file and partially provide the arguments directly to `neps.run`.
However, double referencing is not allowed. You cannot define the same argument in both places.

#### Simple YAML Example
Below is a straightforward YAML configuration example for NePS covering the required arguments.
=== "config.yaml"
Expand Down Expand Up @@ -72,6 +77,11 @@ through `neps.run`. For a detailed list of integrated optimizers, see [here](opt
### Customizing NePS optimizer
Customize an internal NePS optimizer by specifying its parameters directly under the key `searcher` in the
`config.yaml` file.

!!! note
For `searcher_kwargs` of `neps.run`, the optimizer arguments passed via the YAML file and those passed directly via
`neps.run` will be merged. In this special case, if the same argument is referenced in both places,
`searcher_kwargs` will be prioritized and set for this argument.
=== "config.yaml"
```yaml
--8<-- "docs/doc_yamls/customizing_neps_optimizer.yaml"
Expand Down
2 changes: 1 addition & 1 deletion neps/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def run(

if isinstance(searcher, BaseOptimizer):
searcher_instance = searcher
searcher_info["searcher_name"] = "baseoptimizer"
searcher_info["searcher_name"] = "custom-baseoptimizer"
searcher_info["searcher_alg"] = searcher.whoami()
searcher_info["searcher_selection"] = "user-instantiation"
searcher_info["neps_decision_tree"] = False
Expand Down
2 changes: 1 addition & 1 deletion neps/search_spaces/search_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def pipeline_space_from_yaml( # noqa: C901, PLR0912
pipeline_space[name] = CategoricalParameter(**formatted_details)
elif param_type == "const":
# Constant parameter
formatted_details = formatting_const(details)
formatted_details = formatting_const(details) # type: ignore
pipeline_space[name] = ConstantParameter(formatted_details)
else:
# Handle unknown parameter type
Expand Down
8 changes: 4 additions & 4 deletions neps/search_spaces/yaml_search_space_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def deduce_param_type(name: str, details: dict[str, int | str | float]) -> str:
return param_type


def formatting_int(name: str, details: dict[str, str | int | float]):
def formatting_int(name: str, details: dict[str, str | int | float]) -> dict:
"""
Converts scientific notation values to integers.
Expand Down Expand Up @@ -243,7 +243,7 @@ def formatting_int(name: str, details: dict[str, str | int | float]):
return details


def formatting_float(name: str, details: dict[str, str | int | float]):
def formatting_float(name: str, details: dict[str, str | int | float]) -> dict:
"""
Converts scientific notation values to floats.
Expand Down Expand Up @@ -284,7 +284,7 @@ def formatting_float(name: str, details: dict[str, str | int | float]):
return details


def formatting_cat(name: str, details: dict[str, str | int | float]):
def formatting_cat(name: str, details: dict[str, str | int | float]) -> dict:
"""
This function ensures that the 'choices' key in the details is a list and attempts
to convert any elements expressed in scientific notation to floats. It also handles
Expand Down Expand Up @@ -328,7 +328,7 @@ def formatting_cat(name: str, details: dict[str, str | int | float]):
return details


def formatting_const(details: str | int | float):
def formatting_const(details: str | int | float) -> str | int | float:
"""
Validates and converts a constant parameter.
Expand Down

0 comments on commit 4417942

Please sign in to comment.