strategies.CartesianStrategy
strategies.CartesianStrategy()Full cartesian product of all parameters (default strategy).
Generates every possible combination of parameter values. This is the traditional “grid search” approach.
For N parameters with values [v1, v2, …], generates: - Total combinations = len(v1) * len(v2) * … * len(vN)
Compound parameters are handled specially: their internal parameters are zipped together (not cartesian), but the compound as a whole participates in the cartesian product with other parameters.
Examples
>>> strategy = CartesianStrategy()
>>> config = SweepConfig(
... config_parameters=[
... ConfigSweepParameter(name="a", values=[1, 2]),
... ConfigSweepParameter(name="b", values=[10, 20]),
... ],
... strategy=strategy,
... )
>>> # Generates: [{a:1, b:10}, {a:1, b:20}, {a:2, b:10}, {a:2, b:20}]>>> # With compound parameters:
>>> config = SweepConfig(
... config_parameters=[ConfigSweepParameter(name="a", values=[1, 2])],
... compound_parameters=[
... CompoundSweepParameter(
... name="scenario",
... parameters=[
... FileSweepParameter(name="temp", paths=["t1.jshd", "t2.jshd"]),
... FileSweepParameter(name="precip", paths=["p1.jshd", "p2.jshd"]),
... ],
... labels=["low", "high"],
... ),
... ],
... )
>>> # Generates 2 * 2 = 4 combinations (a × scenario), NOT 2 * 2 * 2 = 8Attributes
| Name | Description |
|---|---|
| is_adaptive | Cartesian strategy is not adaptive - all combinations known upfront. |
Methods
| Name | Description |
|---|---|
| expand | Generate cartesian product of all parameter values. |
| from_dict | Create from dict (no additional fields). |
| to_dict | Convert to dict for serialization. |
expand
strategies.CartesianStrategy.expand(
config_params,
file_params,
compound_params=None,
)Generate cartesian product of all parameter values.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| config_params | list[ConfigSweepParameter] | Configuration parameters to sweep over. | required |
| file_params | list[FileSweepParameter] | File parameters to sweep over. | required |
| compound_params | list[CompoundSweepParameter] | None | Groups of parameters that should co-vary. | None |
Returns
| Name | Type | Description |
|---|---|---|
| Iterator[dict[str, Any]] | Iterator of dicts, one for each parameter combination. |
from_dict
strategies.CartesianStrategy.from_dict(data)Create from dict (no additional fields).
to_dict
strategies.CartesianStrategy.to_dict()Convert to dict for serialization.