Parameter sweeps
Compose parameter combinations, iterate experiments, and save or reload configurations. Start with Sweep; piter builds parameter iterators. The proxy and iterator classes below describe the supporting objects.
See hyperparameter sweeps for complete examples.
API index
| Name | Kind | Defined in |
|---|---|---|
BaseProxy | class | params_proto.hyper.proxies |
ClassProxy | class | params_proto.hyper.proxies |
FuncProxy | class | params_proto.hyper.proxies |
PrefixProxy | class | params_proto.hyper.proxies |
ParameterIterator | class | params_proto.hyper.sweep |
PiterFactory | class | params_proto.hyper.sweep |
dot_join | function | params_proto.hyper.sweep |
key_items | function | params_proto.hyper.sweep |
flatten_items | function | params_proto.hyper.sweep |
SweepProxy | class | params_proto.hyper.sweep |
Sweep | class | params_proto.hyper.sweep |
piter | singleton | params_proto.hyper.sweep |
params_proto.hyper
Hyperparameter sweep module for params-proto v3.
Public imports
These symbols are available from this module. Their definitions are documented in the linked modules.
ParameterIterator—params_proto.hyper.sweep.ParameterIteratorSweep—params_proto.hyper.sweep.Sweeppiter—params_proto.hyper.sweep.piter
params_proto.hyper.proxies
Proxy classes for Sweep integration with v3 proto decorators.
BaseProxy
BaseProxy(proto_obj)Base proxy providing common Sweep interface.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
proto_obj | —required | — |
BaseProxy.__init__
BaseProxy.__init__(proto_obj)Wrap a proto object.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
proto_obj | —required | — |
ClassProxy
class ClassProxy(BaseProxy)Proxy for @proto decorated classes (non-prefix).
Inherited members
__init__— fromparams_proto.hyper.proxies.BaseProxy
FuncProxy
class FuncProxy(BaseProxy)Proxy for @proto.cli decorated functions (non-prefix).
Inherited members
__init__— fromparams_proto.hyper.proxies.BaseProxy
PrefixProxy
class PrefixProxy(BaseProxy)Proxy for @proto.prefix decorated classes/functions.
Inherited members
__init__— fromparams_proto.hyper.proxies.BaseProxy
Public imports
These symbols are available from this module. Their definitions are documented in the linked modules.
ProtoWrapper—params_proto.proto.ProtoWrapper
params_proto.hyper.sweep
v3 hyperparameter sweep implementation.
ParameterIterator
ParameterIterator(iterator, protos = None)Lazy iterator over parameter configurations.
Supports operations like product (*), override (%), and power (**).
Parameters
| Parameter | Type / default | Description |
|---|---|---|
iterator | —required | Generator or iterable of config dicts |
protos | —= None | Optional dict of proto objects for context |
ParameterIterator.__init__
ParameterIterator.__init__(iterator, protos = None)Initialize parameter iterator.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
iterator | —required | Generator or iterable of config dicts |
protos | —= None | Optional dict of proto objects for context |
ParameterIterator.list
ParameterIterator.listMaterialize all configs into a list.
ParameterIterator.to_list
ParameterIterator.to_list()Materialize all configs into a list (alias for .list).
ParameterIterator.save
ParameterIterator.save(filename = 'sweep.jsonl', overwrite = True, verbose = True)Save parameter configurations to JSONL file.
Example
Parameters
| Parameter | Type / default | Description |
|---|---|---|
filename | —= 'sweep.jsonl' | Path to output file (str or PathLike) |
overwrite | —= True | If True, overwrite existing file; if False, append |
verbose | —= True | If True, print save confirmation |
ParameterIterator.load
ParameterIterator.load(filename = 'sweep.jsonl')Load parameter configurations from JSONL file.
Example
Parameters
| Parameter | Type / default | Description |
|---|---|---|
filename | —= 'sweep.jsonl' | Path to input file (str or PathLike) |
Returns
ParameterIterator with loaded configurations
PiterFactory
class PiterFactoryFactory for creating parameter iterators.
Supports both function-call syntax and @ operator syntax:
The @ operator enables clean chaining:
dot_join
dot_join(*keys)Remove Nones from the keys, but not empty strings.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
*keys | —variadic | — |
key_items
key_items(d, prefix = None)Takes in tuples of [key, value], or [None, [[key, value], ...]]. Yields items with optional prefix.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
d | —required | — |
prefix | —= None | — |
flatten_items
flatten_items(row) → Iterable[Item]Recursively flatten nested items.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
row | —required | — |
Returns
Iterable[Item]
SweepProxy
SweepProxy(proto_obj)Proxy that switches between normal delegation and sweep interception.
When not in sweep context: delegates all access directly to wrapped ptype class When in sweep context: intercepts setattr to record sweep configurations
Parameters
| Parameter | Type / default | Description |
|---|---|---|
proto_obj | —required | The actual proto class (ptype instance) or ProtoWrapper |
SweepProxy.__init__
SweepProxy.__init__(proto_obj)Wrap a ptype class or ProtoWrapper.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
proto_obj | —required | The actual proto class (ptype instance) or ProtoWrapper |
Sweep
Sweep(*protos)Hyperparameter sweep for v3 @proto decorated classes and functions.
Supports product, zip, chain, and set operations for combining parameter configurations.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
*protos | —variadic | ProtoWrapper instances or metaclass-based proto classes |
Sweep.__init__
Sweep.__init__(*protos)Initialize Sweep with proto objects.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
*protos | —variadic | ProtoWrapper instances or metaclass-based proto classes |
Sweep.items
Sweep.items()Return enumerated sweep configurations.
Sweep.list
Sweep.listConvert sweep to list of configuration dicts.
Sweep.to_list
Sweep.to_list()Convert sweep to list of configuration dicts (alias for .list).
Sweep.dataframe
Sweep.dataframeConvert sweep to pandas DataFrame.
Sweep.noot
Sweep.nootReturn deep copy of root protos.
Sweep.snack
Sweep.snackReturn deep copy of stack.
Sweep.original
Sweep.originalGet original parameter values for each proto.
Sweep.set_param
Sweep.set_param(name, params, prefix = None)Add parameter to current sweep stack.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
name | —required | — |
params | —required | — |
prefix | —= None | — |
Sweep.product
Sweep.product: ContextManager[None]Context manager for Cartesian product of parameters.
Type
ContextManager[None]
Sweep.zip
Sweep.zip: ContextManager[None]Context manager for element-wise zip of parameters.
Type
ContextManager[None]
Sweep.set
Sweep.set: ContextManager[None]Context manager for setting fixed parameter values.
Type
ContextManager[None]
Sweep.chain
Sweep.chain: ContextManager[None]Context manager for chaining multiple sweep configurations.
Type
ContextManager[None]
Sweep.each
Sweep.each(fn)Register a function to be called for each configuration.
Useful for setting values that dynamically depend on other sweep values.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
fn | —required | — |
Sweep.save
Sweep.save(filename = 'sweep.jsonl', overwrite = True, verbose = True)Save sweep configurations to JSONL file.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
filename | —= 'sweep.jsonl' | Path to output file (str or PathLike) |
overwrite | —= True | If True, overwrite existing file; if False, append |
verbose | —= True | If True, print save confirmation |
Sweep.log
Sweep.log(deps, filename)Append single config to JSONL file.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
deps | —required | — |
filename | —required | — |
Sweep.read
Sweep.read(filename)Read JSONL file into list of dicts.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
filename | —required | — |
Sweep.load
Sweep.load(file: Union[str, 'os.PathLike[str]', List[Dict[str, Any]], 'pd.DataFrame'] = 'sweep.jsonl', strict: bool = True, silent: bool = False)Load sweep configurations from JSONL file or list.
Parameters
| Parameter | Type / default | Description |
|---|---|---|
file | Union[str, 'os.PathLike[str]', List[Dict[str, Any]], 'pd.DataFrame']= 'sweep.jsonl' | Filename (str or PathLike), list of dicts, or pandas DataFrame |
strict | bool= True | Raise error on missing attributes (default True) |
silent | bool= False | Suppress warnings about missing attributes (default False) |
Returns
self for chaining
piter
piter = PiterFactory()Factory for creating parameter iterators.
Supports both function-call syntax and @ operator syntax:
The @ operator enables clean chaining:
piter.__call__
piter.__call__(spec)Create parameter iterator (function-call syntax).
Parameters
| Parameter | Type / default | Description |
|---|---|---|
spec | —required | — |
piter.__matmul__
piter.__matmul__(spec)Create parameter iterator (@ operator syntax).
Parameters
| Parameter | Type / default | Description |
|---|---|---|
spec | —required | — |
Public imports
These symbols are available from this module. Their definitions are documented in the linked modules.
ProtoWrapper—params_proto.proto.ProtoWrapperptype—params_proto.proto.ptype