57 lines
3.4 KiB
Python
57 lines
3.4 KiB
Python
"""Predeclare and verify old inputs before executing any alternative dynamics."""
|
|
import ast
|
|
from datetime import datetime, timezone
|
|
import importlib.metadata
|
|
import json
|
|
import platform
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from context import CFG,ROOT,EXP,MODEL,AC,digest,save,source_hashes
|
|
|
|
|
|
def frozen_integrity():
|
|
sys.path.insert(0,str(ROOT/CFG['prior_model']))
|
|
import audit_semantics as old
|
|
result=old.integrity()
|
|
for p in (ROOT/CFG['prior_model'],AC,ROOT/'registry/feedback-context-review-20260930'):
|
|
result[str(p.relative_to(ROOT))]=old.manifest_check(p,digest)
|
|
assert all(x['pass'] for x in result.values())
|
|
return result
|
|
|
|
|
|
def main():
|
|
assert (MODEL/'oracle_runner.py').is_file()
|
|
assert not (EXP/'protocol').exists(),'Refusing reused experiment protocol'
|
|
for d in ('protocol','external-resources','inputs','components','oracle','regression','audit','performance'):(EXP/d).mkdir()
|
|
source=AC/'external-resources/model.py'
|
|
assert digest(source)=='fc45837d7122c6ce2a7f3f2f23c515992e4b232aadb919efabb72337fac88e4e'
|
|
tree=ast.parse(source.read_text())
|
|
assert all(isinstance(x,(ast.Import,ast.ImportFrom,ast.Assign,ast.FunctionDef,ast.Expr)) for x in tree.body)
|
|
inputs=[source,AC/'external-resources/LICENSE',AC/'external-resources/environment_full.yml',
|
|
AC/'audit/selected-real-edges.csv',AC/'audit/selected-metadata.parquet',ROOT/CFG['prior_model']/'math_reference.py']
|
|
for name in CFG['motifs']:
|
|
inputs.extend([AC/'motifs'/f'{name}-edges.csv',AC/'motifs'/f'{name}-events.parquet',AC/'motifs'/f'{name}-state.npz'])
|
|
save(EXP/'protocol/preregistered.json',dict(config=CFG,timestamp_utc=datetime.now(timezone.utc).isoformat(),
|
|
source_hashes=source_hashes(),input_hashes=[dict(path=str(p.relative_to(ROOT)),sha256=digest(p),bytes=p.stat().st_size) for p in inputs],
|
|
parent_commit=subprocess.check_output(['git','-C',str(ROOT),'rev-parse','HEAD'],text=True).strip(),
|
|
pre_model_execution=True))
|
|
save(EXP/'regression/old-integrity-before.json',frozen_integrity())
|
|
for name in ('model.py','LICENSE','environment_full.yml'):
|
|
dst=EXP/'external-resources'/name
|
|
with (AC/'external-resources'/name).open('rb') as src,dst.open('xb') as out:shutil.copyfileobj(src,out)
|
|
assert digest(dst)==digest(AC/'external-resources'/name)
|
|
versions={n:importlib.metadata.version(n) for n in ('numpy','pandas','pyarrow','torch','scipy')}
|
|
save(EXP/'environment/frozen-scientific-environment.json',dict(python=sys.version,executable=sys.executable,
|
|
platform=platform.platform(),package_versions=versions))
|
|
save(EXP/'environment/bootstrap-notes.json',dict(isolated_venv_only=True,existing_environments_modified=False,
|
|
initial_install_failure='New venv pip22.0.2 lacks --report; upgraded ONLY new venv pip to author-pinned23.0.1 before installing',
|
|
MarkupSafe='Author-pinned1.1.1 used PyPI source distribution and legacy setup.py because no CPython3.10 wheel; other requested core packages used wheels',
|
|
author_environment='Windows conda CPython3.10.11',actual_environment='Linux CPython3.10.12; not binary-identical',
|
|
package_download_provenance='install-report.json contains HTTPS PyPI archive URLs and SHA256 for packages'))
|
|
print('PREPARED: old integrity PASS; independent model hypotheses preregistered',flush=True)
|
|
|
|
|
|
if __name__=='__main__':main()
|