Download make_runners.py from Ki-Asif/obsnode-table2-reproduction: direct link, hf CLI and curl.
- Browser
- Download file 3.21 kB
-
https://huggingface.co/datasets/Ki-Asif/obsnode-table2-reproduction/resolve/main/make_runners.py
- Command line
-
hf download hf://datasets/Ki-Asif/obsnode-table2-reproduction/make_runners.py
-
curl -L -o make_runners.py https://huggingface.co/datasets/Ki-Asif/obsnode-table2-reproduction/resolve/main/make_runners.py
3.21 kB
| """Recreate the path-patched runner scripts from the author repo. | |
| Run from a clone of JenniferJaschob/ObsNODE at commit 62dd3e0b: | |
| python make_runners.py /path/to/ObsNODE /path/to/training_pickles_dir | |
| The patches are path-only: hard-coded /Users/jaschob paths replaced, the | |
| os.chdir into the vendored torchdiffeq stubbed around the utils import, | |
| NODE checkpoint path redirected to the committed dim2 location, seed set | |
| to a parameter, and the seed-aggregation tail truncated (aggregation is | |
| reimplemented in analyze_table2.py). Model/data logic is untouched. | |
| """ | |
| import re | |
| import sys | |
| REPO = sys.argv[1] if len(sys.argv) > 1 else "/work/ObsNODE" | |
| DATA = sys.argv[2] if len(sys.argv) > 2 else "/work/data" | |
| SEED = int(sys.argv[3]) if len(sys.argv) > 3 else 1 | |
| CFDIR = REPO + "/Code/Counterfactual/CF_data_cancer/dataset_cancer_cf" | |
| OUTDIR = "/work/run" | |
| OBSUTIL = REPO + "/Code/Model_observableNODE" | |
| NODUTIL = REPO + "/Code/Model_NODE" | |
| def patch(src_name, out_name, util_dir, util_module, extra=None): | |
| src = open(REPO + "/Code/Counterfactual/" + src_name).read() | |
| stub = (f"import sys\n" | |
| f"sys.path.insert(0, '{util_dir}/torchdiffeq')\n" | |
| f"sys.path.insert(0, '{util_dir}')\n") | |
| s = re.sub(r"os\.chdir\('[^']*'\)", stub, src, count=1) | |
| s = re.sub(r"path_data = '[^']*'", | |
| f"path_data = '{CFDIR}/'", s, count=1) | |
| s = re.sub(r"path_data2 = '[^']*'[^\n]*", f"path_data2 = '{DATA}/'", s, count=1) | |
| s = re.sub(r"num_seed_i = \d+", f"num_seed_i = {SEED}", s, count=1) | |
| if extra: | |
| for old, new in extra: | |
| s = s.replace(old, new) | |
| # stub the library's own os.chdir around the utils import | |
| marker = f"from {util_module} import" | |
| idx = s.index(marker) | |
| chdir_stub = (f"_real_chdir = os.chdir\n" | |
| f"os.chdir = lambda _p: _real_chdir('{util_dir}/torchdiffeq')\n") | |
| s = s[:idx] + chdir_stub + s[idx:] | |
| # truncate at the seed-aggregation loop (needs all 5 seeds) | |
| s = s.split("for cf in range(1, 6):")[0] | |
| s = s.split("for num_seed_i in range(1, 6):")[0] | |
| assert "/Users/" not in s.replace("#", ""), "unreplaced hard-coded path" | |
| open(out_name, "w").write(s) | |
| print("wrote", out_name) | |
| patch("Pred_ObsNODE_CF_cancer_0.py", f"{OUTDIR}/Pred_ObsNODE_CF_cancer_1seed.py", | |
| OBSUTIL, "utils_observableNODE", | |
| extra=[("/work/ObsNODE/Code/Model_observableNODE/out/out_cancer/" | |
| "model_state_dict_seed_", | |
| f"{REPO}/Code/Model_observableNODE/out/out_cancer/" | |
| f"model_state_dict_seed_"), | |
| ("'/Users/jaschob/Documents/GitHub/Promotion_Jennifer/" | |
| "Cancer_data_CF/Pred_CF_cancer/obsNODE/'", | |
| "'/work/eval_out/obsNODE/'")]) | |
| patch("Pred_NODE_CF_cancer_0.py", f"{OUTDIR}/Pred_NODE_CF_cancer_1seed.py", | |
| NODUTIL, "utils_NODE", | |
| extra=[("read_path = '/Users/jaschob/Desktop/Out_NODE/" | |
| "model_state_dict_seed_'", | |
| f"read_path = '{REPO}/Code/Model_NODE/Out_NODE/cancer/dim2/" | |
| f"model_state_dict_seed_'"), | |
| ("'/Users/jaschob/Documents/GitHub/Promotion_Jennifer/" | |
| "Cancer_data_CF/Pred_CF_cancer/NODE/'", | |
| "'/work/eval_out/NODE/'")]) | |