Skip to main content

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) and myexp.in_runtime()
  • myexp.emit(result)
  • myexp.run_experiment(func, local_defaults=...)
  • myexp.ExperimentTemplate for YAML-backed lifecycle scripts
  • myexp.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, isExpEnv
  • getYamlConfName, parseFuncParams, unpackAggrParam
  • convParam2Setting, 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:

  1. load the selected background YAML document;
  2. merge the selected task YAML document;
  3. merge parameter overrides after converting a__b to a.b;
  4. parse option blocks using $ selectors with exact match, one regex match, or default;
  5. resolve ?path.to.key references;
  6. raise ConfigError for missing config files, missing reference paths, ambiguous options, cycles, unsupported YAML document shapes, or invalid pid/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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

myexp-0.2.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

myexp-0.2.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

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

Hashes for myexp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c979e83d9904b3ff55ed37740fb64f3c6eab4091fafe9f33cd0303067cff2cfe
MD5 c12579dd2af055c910a9457b894374c7
BLAKE2b-256 ed63576e9ecedacc1a95f1ffdc4f582a89fc0e48f918ff30a6127371204722e8

See more details on using hashes here.

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

Hashes for myexp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f1da0ba038e4bb1ad16ffdd6f4177e27d2a249c1706880af3e6ee70d2e3641a
MD5 bd3a4bd1b16504eebc35337a69478f32
BLAKE2b-256 d4724c57bc3f7bfa436e5e102c5444c0f5048abea1a6cfccadae924ebce84088

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page