nw.experiment#
Experiment helpers — clone projects, apply operations across siblings.
Replaces the bash glue from the muvid_project run:
cp -r the_bells the_bells_v1_lipsync; cp -r the_bells the_bells_v2_…becomesclone_project()calls in a Python loop, with typed control over what’s preserved vs. reset.for v in v1 v2 v3 v4; do muvid script-apply …; donebecomesapply_to_projects().
The “compare four interpretations” workflow is now a first-class feature rather than a shell pipeline.
Functions
|
Apply |
|
Clone an nw project to a new root. |
|
Convenience: return a |
- nw.experiment.apply_to_projects(roots, fn, *, parallel=False)[source]#
Apply
fnto each project atrootsand collect the results.- Parameters:
roots (
Iterable[str|Path]) – Iterable of project roots. Each must point to an existing nw project.fn (
Callable[[Project],TypeVar(T)]) – Callable taking aProjectand returning anything. Use this for per-project operations: parsing a script, estimating cost, rendering, gathering reports.parallel (
bool) – When True, runfnin a thread pool. Useful whenfnis I/O- or API-bound (e.g. a render). When False (default), runs sequentially in submission order — the safest semantics.
- Return type:
- Returns:
A list of
fn(project)results in the same order asroots.
Examples
>>> # Estimate cost of all four sibling experiments without rendering: >>> # totals = apply_to_projects(roots, lambda p: estimate_render_cost(p)) >>> # Apply the same script to all of them after a refactor: >>> # apply_to_projects(roots, lambda p: parse_script(p))
- nw.experiment.clone_project(src_root, dst_root, *, preserve=('song', 'lyrics', 'characters'), reset=('script', 'shots', 'output', '.nw'), title=None, force=False)[source]#
Clone an nw project to a new root.
- Parameters:
src_root (
str|Path) – Path to an existing nw project (must containproject.json).dst_root (
str|Path) – Destination path. Must not exist (or passforce=Trueto overwrite).preserve (
Iterable[str]) – Subtrees ofsrc_rootto copy verbatim intodst_root. Default:("song", "lyrics", "characters").reset (
Iterable[str]) – Subtrees ofdst_rootto (re)create as empty after copying. Default:("script", "shots", "output", ".nw").title (
Optional[str]) – New title for the cloned project. Defaults todst_root’s folder name.force (
bool) – When True, overwrite an existingdst_root(refuses by default to avoid clobbering work).
- Return type:
- Returns:
ProjectSummaryof the cloned project.