From 2be738f557d985250bcbfad63f51735a069f799e Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 16 Oct 2026 08:33:45 +0200 Subject: [PATCH] battery.py on Windows: relative site-config paths from the config's directory, a copied pdb_cache usable as is, Windows hardware info From the Windows laptop's timing runs (2026-10-16), where every set failed until the site config's paths were made absolute and the copied pdb_cache's .json files deleted: - a relative runs root, lock file, cache or data root is taken relative to the site config's own directory (the manifest stays relative to tools/battery/), so rugnux finds it from its work dir; - model_check.deposition uses the coordinates where the cache now is, not the path its json recorded when the entry was first fetched; - hardware info for the manifest on Windows (PowerShell CIM: CPU, cores, threads, memory); - report.run_state does not probe the run's pid with os.kill on Windows, where that terminates it; - a crash with a Windows NTSTATUS exit code is named as an exception. The docs no longer tell people to work around the first two by hand. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PXc1zD1yxHqaR1DGdCTHL4 --- docs/RUGNUX_BENCHMARKING.md | 13 ++++------- tools/battery/README.md | 8 +++---- tools/battery/battery.py | 44 ++++++++++++++++++++++++++++++++---- tools/battery/model_check.py | 3 ++- tools/battery/report.py | 3 ++- tools/battery/score.py | 2 ++ 6 files changed, 54 insertions(+), 19 deletions(-) diff --git a/docs/RUGNUX_BENCHMARKING.md b/docs/RUGNUX_BENCHMARKING.md index 594261eca..bb68ce1f2 100644 --- a/docs/RUGNUX_BENCHMARKING.md +++ b/docs/RUGNUX_BENCHMARKING.md @@ -44,15 +44,10 @@ so it goes **before** the subcommand: python3 tools/battery/battery.py --site /path/to/site.json run --rugnux build/rugnux/rugnux --tier smoke ``` -Two things trip people up when they copy a setup from another machine: - -- **Use absolute paths in the site config.** `rugnux` runs inside each set's work directory, and a - relative `data_root`, `runs_root` or `pdb_cache` is not found from there: every set then fails - with `Cannot open/create data HDF5 file`. -- **A copied `pdb_cache` remembers where it was made.** Each `.json` in it stores the - absolute path of its coordinate file. If the cache was copied from another machine, delete the - `.json` files (the runner writes them again from the `.cif.gz` beside them), or the sets that - need a model fail. +A relative path in the site config (data roots, runs root, lock file, caches) is taken relative to +the site config's own directory, so a config shipped beside its data works wherever it is unpacked. +A `pdb_cache` copied from another machine can be used as it is: the coordinates are looked up where +the cache now is, not where its `.json` files say they were first fetched. The data layout (`//...`) and where to get each arm's data are in the README's *Getting the data*. The open arm is public (each dataset's DOI is in diff --git a/tools/battery/README.md b/tools/battery/README.md index db64310df..ccb66a94d 100644 --- a/tools/battery/README.md +++ b/tools/battery/README.md @@ -232,7 +232,8 @@ export `JFJOCH_BATTERY_SITE=/data/battery/site.json`. } ``` -A relative `manifest` path is resolved against `tools/battery/`. `gpulock` is a command that +A relative `manifest` path is resolved against `tools/battery/`; every other relative path (runs root, +lock file, caches, data roots) against the site config's own directory. `gpulock` is a command that `rugnux` is prefixed with under `--gpulock`. At PSI it is a wrapper script that queues for one of the shared GPU slots. Set it to `null` if you have no such wrapper. `pdb_cache` (optional) is where the deposited models and their metadata are cached for `--model` and the REFMAC check. `baseline_timing` @@ -410,9 +411,8 @@ whose data roots hold the three directories and whose `gpulock` is `null`, and t macOS runs it as Linux does. Windows has no process groups and no `flock`, which a timing run does not need; run it as `python -X utf8 tools\battery\battery.py ...` (the report and the console table are UTF-8), with `--rugnux` naming `rugnux.exe` (the run directory keeps its own copy, so any DLL it needs -must be found on `PATH`). Both have been run (2026-10-16); on both the site config needs absolute -paths, and a `pdb_cache` copied from another machine needs its `.json` files deleted, since -they record the absolute path of the coordinates where they were first fetched +must be found on `PATH`). Both have been run (2026-10-16). Relative paths in the site config are +taken from the config's own directory, and a `pdb_cache` copied from another machine works as it is ([Measuring Rugnux](../../docs/RUGNUX_BENCHMARKING.md#setting-up-a-machine)). Measured on the workstation (RTX 5080, rc175): myoglobin 10 s, cytochrome c 13 s, 4NWV 106 s diff --git a/tools/battery/battery.py b/tools/battery/battery.py index b04a8a029..4c0d254d8 100644 --- a/tools/battery/battery.py +++ b/tools/battery/battery.py @@ -114,8 +114,16 @@ def load_site(path): f"{LOCAL_SITE} (or anywhere, and point JFJOCH_BATTERY_SITE or --site at it) and " "fill in this machine's paths") site = json.load(open(path)) + # a relative path is relative to the site config itself, so one shipped beside its data works + # wherever it is unpacked and whatever directory rugnux runs in; an absolute path stays as it is + base = os.path.dirname(os.path.abspath(path)) + for k in ("runs_root", "lock_file", "pdb_cache", "cod_cache"): + if site.get(k): + site[k] = os.path.join(base, site[k]) for arm in site["arms"].values(): - arm["manifest"] = os.path.join(HERE, arm["manifest"]) # an absolute path stays as it is + arm["manifest"] = os.path.join(HERE, arm["manifest"]) # relative to tools/battery/ + if arm.get("data_root"): + arm["data_root"] = os.path.join(base, arm["data_root"]) return site @@ -268,6 +276,32 @@ def linux_hardware(): "gpus": gpu_hardware()} +def windows_hardware(): + """From WMI through PowerShell (wmic is gone from current Windows). Win32_Processor has one + entry per socket; its MaxClockSpeed is the nominal clock, not the boost.""" + def cim(query): + r = subprocess.run(["powershell", "-NoProfile", "-Command", query + " | ConvertTo-Json"], + capture_output=True, text=True, errors="replace", timeout=60) + out = json.loads(r.stdout) if r.returncode == 0 and r.stdout.strip() else [] + return out if isinstance(out, list) else [out] + + cpus = cim("Get-CimInstance Win32_Processor | " + "Select-Object Name, NumberOfCores, NumberOfLogicalProcessors, MaxClockSpeed") + mem = cim("(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory") + model = cpus[0]["Name"].strip() if cpus else None + freq_ghz, freq_source = None, "unknown" + m = re.search(r"@\s*([\d.]+)\s*GHz", model or "") + if m: + freq_ghz, freq_source = float(m.group(1)), "model name" + elif cpus and cpus[0].get("MaxClockSpeed"): + freq_ghz, freq_source = cpus[0]["MaxClockSpeed"] / 1000, "Win32_Processor.MaxClockSpeed" + return {"cpu_model": model or "unknown", "cpu_base_ghz": freq_ghz, "cpu_base_source": freq_source, + "cpu_max_boost_ghz": None, "sockets": len(cpus) or None, + "physical_cores": sum(c.get("NumberOfCores") or 0 for c in cpus) or None, + "threads": sum(c.get("NumberOfLogicalProcessors") or 0 for c in cpus) or os.cpu_count(), + "memory_gib": int(mem[0]) / 1024 ** 3 if mem else None, "gpus": gpu_hardware()} + + def macos_hardware(): def sysctl(key): r = subprocess.run(["sysctl", "-n", key], capture_output=True, text=True) @@ -292,14 +326,16 @@ def macos_hardware(): def hardware_info(): """The run host's hardware, for the manifest: CPU model, nominal/base frequency (and where it came from) plus max boost frequency separately, physical cores, threads, sockets, memory, GPUs. - Linux is detailed; macOS is a short best-effort; anywhere else this is just empty, and the - report says so.""" + Linux is detailed; macOS and Windows are a short best-effort; anywhere else this is just empty, + and the report says so.""" try: if sys.platform == "darwin": return macos_hardware() if sys.platform.startswith("linux"): return linux_hardware() - except OSError: + if sys.platform == "win32": + return windows_hardware() + except (OSError, ValueError, subprocess.TimeoutExpired): pass return {} diff --git a/tools/battery/model_check.py b/tools/battery/model_check.py index 5212c5c8f..206bfb8ac 100644 --- a/tools/battery/model_check.py +++ b/tools/battery/model_check.py @@ -85,7 +85,8 @@ def deposition(pdb_id, cache_dir): if xyz is None: return None if os.path.exists(meta_path): - return json.load(open(meta_path)) + # the coordinates where this cache is now: a cache copied elsewhere keeps the old path in its json + return dict(json.load(open(meta_path)), xyz=xyz) meta = refinement_record(pdb_id, xyz) json.dump(meta, open(meta_path, "w"), indent=1) return meta diff --git a/tools/battery/report.py b/tools/battery/report.py index 97d9f5406..06ea151bf 100644 --- a/tools/battery/report.py +++ b/tools/battery/report.py @@ -46,7 +46,8 @@ def run_state(man): return "complete" if man.get("aborted"): return "aborted" - if man.get("pid") and man.get("host") == socket.gethostname(): + # (not on Windows, where os.kill does not probe: it terminates the process, or sends it Ctrl-C) + if man.get("pid") and man.get("host") == socket.gethostname() and os.name != "nt": try: os.kill(man["pid"], 0) return "running" diff --git a/tools/battery/score.py b/tools/battery/score.py index 0dd4dec7f..822fb24e2 100644 --- a/tools/battery/score.py +++ b/tools/battery/score.py @@ -75,6 +75,8 @@ def crash_note(exit_code, wd): return "" if exit_code < 0: return f"killed by signal {-exit_code}" + if exit_code >= 0xC0000000: # Windows: an unhandled exception's NTSTATUS (0xC0000005 access violation) + return f"killed by exception 0x{exit_code:08X}" for name in ("p_log.txt", "run.log"): try: for line in open(os.path.join(wd, name), errors="replace"):