Python experiment script protocol helpers for Research Lab runtime tasks.
Project description
myexp
myexp is the maintained Python protocol package for repository experiment scripts.
Version 0.2.0 keeps the runtime contract from 0.1.0 while making the public API smaller and better diagnosed.
Runtime Model
One script supports both local debug and distributed runtime execution:
- local debug mode uses defaults embedded in the script;
- runtime mode uses the JSON object passed as the first command-line argument;
- runtime JSON is authoritative and never merged under local defaults.
Use myexp.params(local_defaults) to load parameters. If runtime JSON is present it is returned. If no runtime JSON is present, a deep copy of local_defaults is returned. Invalid JSON and non-object JSON raise ParameterError with phase, source, path, and recovery guidance.
Preferred API
New scripts should import only myexp and prefer these names:
myexp.params(local_defaults)andmyexp.in_runtime()myexp.emit(result)myexp.run_experiment(func, local_defaults=...)myexp.ExperimentTemplatefor YAML-backed lifecycle scriptsmyexp.config_name(__file__)myexp.load_config(...),myexp.nest_params(...),myexp.unpack_params(...)myexp.filter_kwargs(func, args)
Compatibility names remain available for existing scripts:
ExpTemplate,getParams,printResult,isExpEnvgetYamlConfName,parseFuncParams,unpackAggrParamconvParam2Setting,loadSettingFromYaml,removeNoneSetting
Minimal Script
import myexp
LOCAL_DEFAULTS = {"pid": 0, "metric": 1}
def main(param):
return {"metric": int(param["metric"]) + 1, "params": param}
if __name__ == "__main__":
myexp.run_experiment(main, local_defaults=LOCAL_DEFAULTS)
Lifecycle Script
Use ExperimentTemplate when the script needs bgConfig.yaml, a task config file, option/reference parsing, pid document selection, execution gating, or parameter normalization.
import myexp
class Experiment(myexp.ExperimentTemplate):
def normalize_params(self, param):
param["metric"] = int(param["metric"]) + 1
return param
def execute(self, config):
return {"metric": config["metric"], "params": config}
if __name__ == "__main__":
Experiment(
workSpaceDir=".",
taskConfigName=myexp.config_name(__file__),
local_defaults={"pid": 0, "metric": 1},
).run()
Config Behavior
Config loading is deterministic:
- load the selected background YAML document;
- merge the selected task YAML document;
- merge parameter overrides after converting
a__btoa.b; - parse option blocks using
$selectors with exact match, one regex match, ordefault; - resolve
?path.to.keyreferences; - raise
ConfigErrorfor missing config files, missing reference paths, ambiguous options, cycles, unsupported YAML document shapes, or invalidpid/document indices.
Results are sidecar-first. When RESEARCH_LAB_RESULT_JSON is set, myexp.emit() writes JSON there. Otherwise it emits the legacy stdout markers ==>**ResultJson**<== and ==>**End**<==.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file myexp-0.2.0.tar.gz.
File metadata
- Download URL: myexp-0.2.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c979e83d9904b3ff55ed37740fb64f3c6eab4091fafe9f33cd0303067cff2cfe
|
|
| MD5 |
c12579dd2af055c910a9457b894374c7
|
|
| BLAKE2b-256 |
ed63576e9ecedacc1a95f1ffdc4f582a89fc0e48f918ff30a6127371204722e8
|
File details
Details for the file myexp-0.2.0-py3-none-any.whl.
File metadata
- Download URL: myexp-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f1da0ba038e4bb1ad16ffdd6f4177e27d2a249c1706880af3e6ee70d2e3641a
|
|
| MD5 |
bd3a4bd1b16504eebc35337a69478f32
|
|
| BLAKE2b-256 |
d4724c57bc3f7bfa436e5e102c5444c0f5048abea1a6cfccadae924ebce84088
|