search_spaces
orchard.optimization.search_spaces
¶
Hyperparameter Search Space Definitions for Optuna.
Provides SearchSpaceRegistry, a centralized catalogue of parameter
sampling functions, and the get_search_space factory that assembles
preset search spaces (quick or full) for Optuna studies.
All bounds are read from a SearchSpaceOverrides Pydantic V2 model,
so ranges can be fully customized via YAML through
OptunaConfig.search_space_overrides without code changes. Defaults
are tuned for image classification and respect the type
constraints defined in core/config/types.py.
Key Functions
get_search_space: Factory that returns a preset search space
dict (quick or full), optionally including model
architecture selection.
Key Components
SearchSpaceRegistry: Resolution-aware registry of sampling
functions for optimization, regularization, batch size,
scheduler, and augmentation parameters.
Example
space = get_search_space("full", resolution=224, include_models=True) study.optimize(OptunaObjective(cfg, space, device), n_trials=50)
SearchSpaceRegistry(overrides=None)
¶
Centralized registry of hyperparameter search distributions.
Reads bounds from a SearchSpaceOverrides instance, enabling full YAML customization of search ranges without code changes.
Each method returns a dict of {param_name: suggest_function} where suggest_function takes a Trial object and returns a sampled value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
overrides
|
SearchSpaceOverrides | None
|
Configurable search range bounds. Uses defaults if None. |
None
|
Source code in orchard/optimization/search_spaces.py
get_optimization_space()
¶
Core optimization hyperparameters (learning rate, weight decay, etc.).
Returns:
| Type | Description |
|---|---|
Mapping[str, _SamplerFn]
|
Immutable mapping of parameter names to sampling functions |
Source code in orchard/optimization/search_spaces.py
get_loss_space()
¶
Loss function parameters (criterion type, focal gamma, label smoothing).
focal_gamma is only sampled when criterion_type == "focal",
otherwise defaults to 2.0. label_smoothing is only sampled
when criterion_type == "cross_entropy", otherwise defaults to 0.0.
Returns:
| Type | Description |
|---|---|
Mapping[str, _SamplerFn]
|
Immutable mapping of loss-related parameter samplers |
Source code in orchard/optimization/search_spaces.py
get_regularization_space()
¶
Regularization strategies (mixup, dropout).
Returns:
| Type | Description |
|---|---|
Mapping[str, _SamplerFn]
|
Immutable mapping of regularization parameter samplers |
Source code in orchard/optimization/search_spaces.py
get_batch_size_space(resolution=28)
¶
Batch size as categorical (resolution-aware).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int
|
Input image resolution (e.g. 28, 32, 64, 128, 224) |
28
|
Returns:
| Type | Description |
|---|---|
Mapping[str, _SamplerFn]
|
Immutable mapping with batch_size sampler |
Source code in orchard/optimization/search_spaces.py
get_scheduler_space()
¶
Learning rate scheduler parameters.
Returns:
| Type | Description |
|---|---|
Mapping[str, _SamplerFn]
|
Immutable mapping of scheduler-related samplers |
Source code in orchard/optimization/search_spaces.py
get_augmentation_space()
¶
Data augmentation intensity parameters.
Returns:
| Type | Description |
|---|---|
Mapping[str, _SamplerFn]
|
Immutable mapping of augmentation samplers |
Source code in orchard/optimization/search_spaces.py
get_full_space(resolution=28)
¶
Combined search space with all available parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int
|
Input image resolution for batch size calculation |
28
|
Returns:
| Type | Description |
|---|---|
Mapping[str, _SamplerFn]
|
Immutable unified mapping of all parameter samplers |
Source code in orchard/optimization/search_spaces.py
get_quick_space(resolution=28)
¶
Reduced search space for fast exploration (most impactful params).
Focuses on:
- Learning rate (most critical)
- Weight decay
- Batch size (resolution-aware)
- Dropout
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int
|
Input image resolution for batch size calculation |
28
|
Returns:
| Type | Description |
|---|---|
Mapping[str, _SamplerFn]
|
Immutable mapping of high-impact parameter samplers |
Source code in orchard/optimization/search_spaces.py
get_model_space_224()
staticmethod
¶
Search space for 224x224 architectures with weight variants.
Source code in orchard/optimization/search_spaces.py
get_model_space_28()
staticmethod
¶
Search space for 28x28 architectures.
Source code in orchard/optimization/search_spaces.py
get_search_space(preset='quick', resolution=28, include_models=False, model_pool=None, overrides=None)
¶
Factory function to retrieve a search space preset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset
|
str
|
Name of the preset ("quick", "full", etc.) |
'quick'
|
resolution
|
int
|
Input image resolution (affects batch_size choices) |
28
|
include_models
|
bool
|
If True, includes model architecture selection |
False
|
model_pool
|
list[str] | None
|
Restrict model search to these architectures. When None, uses all built-in models for the target resolution. |
None
|
overrides
|
SearchSpaceOverrides | None
|
Configurable search range bounds (uses defaults if None) |
None
|
Returns:
| Type | Description |
|---|---|
Mapping[str, Any]
|
Immutable mapping of parameter samplers keyed by parameter name |
Raises:
| Type | Description |
|---|---|
OrchardConfigError
|
If preset name not recognized |