My analysis lived in a 400-cell notebook with out-of-order execution, hardcoded paths from my laptop, and df reused for six different frames. It ran on my machine and nowhere else. I needed a clean CLI script a colleague could actually run.
The prompt that worked makes the model reconstruct the true dependency order first, then parameterize every hardcoded path/constant, add a fixed random seed, and pin the environment. Asking it to list assumptions it's making about hidden notebook state caught two cells that depended on a variable defined 200 cells earlier.
How do you get it to preserve intermediate-result caching (expensive cells) without the notebook's implicit global state? I've been using an explicit on-disk cache with a --no-cache flag.
Convert the following Jupyter notebook into a single reproducible Python script runnable as `python analyze.py --input ... --output ...`. The notebook has out-of-order cells and hidden global state.
Do this in order:
1. First, reconstruct the true execution dependency order (which cell's outputs feed which). List any cell that relies on state defined much earlier, and state each assumption you are making about that hidden state. If a dependency is ambiguous, flag it rather than guessing silently.
2. Refactor into named functions with explicit inputs/outputs. No reused throwaway variable names, no reliance on execution order.
3. Parameterize: every hardcoded path, constant, threshold, and date becomes an argparse arg or a config constant at the top. No absolute `/Users/...` paths.
4. Reproducibility: set and log a fixed random seed for every RNG used (python `random`, numpy, framework). Pin exact package versions in a `requirements.txt` block from the imports.
5. Caching: expensive steps write intermediate results to `{CACHE_DIR}` keyed by a hash of their inputs; a `--no-cache` flag forces recompute. Cache must be correct, not just fast (invalidate when inputs change).
6. Structure: `def main(argv=None)`, logging not print, and a `--dry-run` that reports the plan.
At the end, list exactly what a colleague must install and run to reproduce your numbers on a fresh machine, and note any result that could differ across platforms and why.