Skip to content

Commit 0b2e7ad

Browse files
wmaynerclaude
andcommitted
Use shared provenance path helpers in benchmark scripts
The cross-generation harness keeps a local fallback copy of unique_path for the pre-refactor generation, which has no pyphi.provenance module. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PEAxNzhDCaTrntX3o1JqMV
1 parent 497932f commit 0b2e7ad

3 files changed

Lines changed: 26 additions & 30 deletions

File tree

benchmarks/b18_dispatch_gate.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666

6767
import numpy as np
6868

69+
from pyphi.provenance import unique_path
70+
6971
RESULTS_DIR = Path(__file__).parent / "b18_dispatch_gate_results"
7072

7173
# Workload sizes as fractions of the level's chunksize. Sizes at or below
@@ -642,15 +644,6 @@ def run_level(name: str, seed: int, trials: int) -> dict:
642644
}
643645

644646

645-
def unique_path(directory: Path, stem: str, suffix: str) -> Path:
646-
path = directory / f"{stem}{suffix}"
647-
version = 2
648-
while path.exists():
649-
path = directory / f"{stem}_v{version}{suffix}"
650-
version += 1
651-
return path
652-
653-
654647
def main() -> None:
655648
parser = argparse.ArgumentParser(description=__doc__)
656649
parser.add_argument("--seed", type=int, default=1810)

benchmarks/iit_3_vs_4/harness.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -507,18 +507,22 @@ def extract_phase_times(pstats_path: Path) -> dict[str, float]:
507507
return out
508508

509509

510-
def unique_path(directory: Path, stem: str, suffix: str) -> Path:
511-
"""Return a non-clobbering path: stem.suffix, then stem_v2.suffix, ..."""
512-
directory.mkdir(parents=True, exist_ok=True)
513-
base = directory / f"{stem}{suffix}"
514-
if not base.exists():
515-
return base
516-
n = 2
517-
while True:
518-
candidate = directory / f"{stem}_v{n}{suffix}"
519-
if not candidate.exists():
520-
return candidate
521-
n += 1
510+
try:
511+
from pyphi.provenance import unique_path
512+
except ImportError:
513+
# The pre-refactor generation has no pyphi.provenance; keep a local copy.
514+
def unique_path(directory: Path, stem: str, suffix: str) -> Path:
515+
"""Return a non-clobbering path: stem.suffix, then stem_v2.suffix, ..."""
516+
directory.mkdir(parents=True, exist_ok=True)
517+
base = directory / f"{stem}{suffix}"
518+
if not base.exists():
519+
return base
520+
n = 2
521+
while True:
522+
candidate = directory / f"{stem}_v{n}{suffix}"
523+
if not candidate.exists():
524+
return candidate
525+
n += 1
522526

523527

524528
def write_record(record: dict[str, Any]) -> Path:

benchmarks/iit_3_vs_4/p18_inversion_share.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
import numpy as np
3737

38+
from pyphi.provenance import format_stem
39+
from pyphi.provenance import unique_path
40+
3841
CORE_N = 6
3942
CORE_DENSITY = 0.35
4043
COUPLING_MEAN = 1.0
@@ -112,15 +115,11 @@ def _profile_sia(system) -> dict:
112115

113116
def _output_path(seed: int, run_label: str | None) -> Path:
114117
results_dir = Path(__file__).parent / "results"
115-
results_dir.mkdir(exist_ok=True)
116-
label = f"_{run_label}" if run_label else ""
117-
base = f"p18_inversion_share_seed{seed}{label}"
118-
path = results_dir / f"{base}.json"
119-
version = 2
120-
while path.exists():
121-
path = results_dir / f"{base}_v{version}.json"
122-
version += 1
123-
return path
118+
return unique_path(
119+
results_dir,
120+
format_stem("p18_inversion_share", {"seed": seed}, run_label),
121+
".json",
122+
)
124123

125124

126125
def main() -> None:

0 commit comments

Comments
 (0)