把黎曼猜想的 Lean 证明,写成人能读懂的证明
把黎曼猜想的 Lean 证明写成数学家能读的证明文章,以及人人能看懂的证明思路
Restore verified modules and resume exact dependency checkouts
Browse files+34 −0 routes/cogito-source-provenance/prepare_dependencies.py added View file
| @@ -0,0 +1,34 @@ | ||
| 1 | +"""Resume exact dependency fetches without restaging the original source tree.""" | |
| 2 | +import argparse,hashlib,json,os,subprocess,time | |
| 3 | +from pathlib import Path | |
| 4 | +SOURCE_TREE='24df20b62d9976ccd20da819bc20b16f808f0fdd' | |
| 5 | +def main(): | |
| 6 | + p=argparse.ArgumentParser(description=__doc__);p.add_argument('--project',type=Path,required=True);p.add_argument('--report',type=Path,required=True);a=p.parse_args();root=a.project.resolve() | |
| 7 | + git=['git','-c','credential.helper=','-c','core.longpaths=true','-c','http.version=HTTP/1.1','-c','http.lowSpeedLimit=1024','-c','http.lowSpeedTime=60'] | |
| 8 | + if os.name=='nt':git+=['-c','http.sslBackend=schannel'] | |
| 9 | + tree=subprocess.check_output(git+['-C',str(root),'rev-parse','HEAD:src'],text=True).strip() | |
| 10 | + if tree!=SOURCE_TREE:raise ValueError('unexpected private source tree') | |
| 11 | + raw=(root/'lake-manifest.json').read_bytes() | |
| 12 | + if hashlib.sha256(raw).hexdigest()!='fee57ee9ed399d0a638ca955e5ad40a37a36eeb9b6dfd9f5964114fa7bbe4774':raise ValueError('dependency manifest mismatch') | |
| 13 | + manifest=json.loads(raw);records={} | |
| 14 | + for index,package in enumerate(manifest['packages'],1): | |
| 15 | + dest=root/'.lake/packages'/package['name'];revision=package['rev'] | |
| 16 | + if not (dest/'.git').exists():subprocess.run(git+['init',str(dest)],check=True) | |
| 17 | + existing=subprocess.run(git+['-C',str(dest),'remote','get-url','origin'],capture_output=True,text=True) | |
| 18 | + if existing.returncode:subprocess.run(git+['-C',str(dest),'remote','add','origin',package['url']],check=True) | |
| 19 | + elif existing.stdout.strip()!=package['url']:raise ValueError('unexpected dependency remote') | |
| 20 | + for attempt in range(5): | |
| 21 | + present=subprocess.run(git+['-C',str(dest),'cat-file','-e',revision+'^{commit}'],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL).returncode==0 | |
| 22 | + if present:break | |
| 23 | + print(f'Fetching exact dependency {package["name"]}, attempt {attempt+1}',flush=True) | |
| 24 | + r=subprocess.run(git+['-C',str(dest),'fetch','--depth=1','origin',revision]) | |
| 25 | + if r.returncode==0:break | |
| 26 | + if attempt==4:raise RuntimeError('dependency fetch failed; safe to resume') | |
| 27 | + time.sleep(3) | |
| 28 | + subprocess.run(git+['-C',str(dest),'checkout','--detach',revision],check=True) | |
| 29 | + actual=subprocess.check_output(git+['-C',str(dest),'rev-parse','HEAD'],text=True).strip() | |
| 30 | + if actual!=revision:raise ValueError('dependency revision mismatch') | |
| 31 | + records[package['name']]=actual;print(f'progress: {index}/{len(manifest["packages"])} exact dependencies ready',flush=True) | |
| 32 | + a.report.write_text(json.dumps({'source_tree':tree,'dependencies':records,'scope':'Pinned source checkouts; no proof build.'},indent=2)+'\n',encoding='utf-8') | |
| 33 | + print('Exact dependency checkouts ready.',flush=True) | |
| 34 | +if __name__=='__main__':main() | |
+8 −0 routes/cogito-source-provenance/prepare_dependencies.sbatch added View file
| @@ -0,0 +1,8 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +#SBATCH --job-name=prepare-deps | |
| 3 | +#SBATCH --time=01:00:00 | |
| 4 | +#SBATCH --cpus-per-task=2 | |
| 5 | +#SBATCH --mem=4096 | |
| 6 | +set -euo pipefail | |
| 7 | +base="$(git rev-parse --show-toplevel)/../.." | |
| 8 | +/mnt/c/Python314/python.exe prepare_dependencies.py --project "$(wslpath -w "$base/private-environment/original-source")" --report dependency-report.json | |
+48 −0 routes/cogito-source-provenance/restore_native_cache.py added View file
| @@ -0,0 +1,48 @@ | ||
| 1 | +"""Restore only the fixed manifest's hash-checked native cache into the private tree.""" | |
| 2 | +import argparse,gzip,hashlib,json,os,subprocess | |
| 3 | +from pathlib import Path | |
| 4 | +MANIFEST_SHA='292caa386a620d935cfc736b56fcceaab9fe7073086693b62e899c1ee4725f04' | |
| 5 | +SOURCE_TREE='24df20b62d9976ccd20da819bc20b16f808f0fdd' | |
| 6 | +def sha(p): | |
| 7 | + with p.open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() | |
| 8 | +def main(): | |
| 9 | + p=argparse.ArgumentParser(description=__doc__) | |
| 10 | + p.add_argument('--cache',type=Path,required=True);p.add_argument('--project',type=Path,required=True) | |
| 11 | + p.add_argument('--leantar',type=Path,required=True);p.add_argument('--report',type=Path,required=True) | |
| 12 | + p.add_argument('--sample',type=int) | |
| 13 | + a=p.parse_args();root=a.project.resolve();raw=(a.cache/'modules.jsonl.gz').read_bytes() | |
| 14 | + if hashlib.sha256(raw).hexdigest()!=MANIFEST_SHA:raise ValueError('manifest SHA-256 mismatch') | |
| 15 | + lines=gzip.decompress(raw).splitlines();header=json.loads(lines[0]);rows=[json.loads(l) for l in lines[1:]] | |
| 16 | + if len(rows)!=175187 or header['source_tree']!=SOURCE_TREE:raise ValueError('unexpected cache manifest') | |
| 17 | + tree=subprocess.check_output(['git','-C',str(root),'rev-parse','HEAD:src'],text=True).strip() | |
| 18 | + if tree!=SOURCE_TREE:raise ValueError('private source tree differs from the cache pin') | |
| 19 | + if a.sample is not None: | |
| 20 | + if not 1<=a.sample<=100:raise ValueError('invalid sample count') | |
| 21 | + rows=rows[:a.sample] | |
| 22 | + # Windows verbatim paths preserve deeply nested original module names. | |
| 23 | + fsroot=root | |
| 24 | + if os.name=='nt':fsroot=Path('\\\\?\\'+str(root)) | |
| 25 | + jobs=[] | |
| 26 | + for i,(name,dep,artifact,digest) in enumerate(rows,1): | |
| 27 | + pieces=name.split('.') | |
| 28 | + if not all(piece and all(c.isalnum() or c in "_'" for c in piece) for piece in pieces):raise ValueError('unsafe module name') | |
| 29 | + file=a.cache/'artifacts'/artifact | |
| 30 | + if sha(file)!=digest:raise ValueError('cached archive digest mismatch: '+artifact) | |
| 31 | + source=fsroot/'src'/Path(*pieces).with_suffix('.lean') | |
| 32 | + if not source.is_file():raise ValueError('missing private source module: '+name) | |
| 33 | + bases=[] | |
| 34 | + for directory in ['lib/lean','ir']: | |
| 35 | + parent=fsroot/'.lake/build'/directory/Path(*pieces[:-1]);parent.mkdir(parents=True,exist_ok=True);bases.append(str(parent)) | |
| 36 | + jobs.append({'file':str(file.resolve()),'hash':dep,'base':bases}) | |
| 37 | + if i%10000==0:print(f'progress: {i}/{len(rows)} cache archives rechecked for restore',flush=True) | |
| 38 | + version=subprocess.check_output([str(a.leantar),'--version'],text=True).strip() | |
| 39 | + if version!='leantar 0.1.20':raise ValueError('unexpected archive reader version') | |
| 40 | + subprocess.run([str(a.leantar),'--jobs','4','-x','-j','-'],input=json.dumps(jobs),text=True,cwd=root,check=True) | |
| 41 | + for name,_,_,_ in rows: | |
| 42 | + file=fsroot/'.lake/build/lib/lean'/Path(*name.split('.')).with_suffix('.olean') | |
| 43 | + if not file.is_file():raise ValueError('missing restored module '+name) | |
| 44 | + report={'source_tree':tree,'manifest_sha256':MANIFEST_SHA,'restored_modules':len(rows),'sample_only':a.sample is not None,'leantar':version, | |
| 45 | + 'scope':'Restored third-party compiled modules after archive digest checks; not an independent rebuild or kernel verification.'} | |
| 46 | + a.report.write_text(json.dumps(report,indent=2)+'\n',encoding='utf-8') | |
| 47 | + print(('Sample only: ' if a.sample else '')+f'Restored {len(rows)} hash-checked native cache modules.',flush=True) | |
| 48 | +if __name__=='__main__':main() | |
+8 −0 routes/cogito-source-provenance/restore_native_cache.sbatch added View file
| @@ -0,0 +1,8 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +#SBATCH --job-name=restore-native | |
| 3 | +#SBATCH --time=01:00:00 | |
| 4 | +#SBATCH --cpus-per-task=4 | |
| 5 | +#SBATCH --mem=4096 | |
| 6 | +set -euo pipefail | |
| 7 | +base="$(git rev-parse --show-toplevel)/../.." | |
| 8 | +/mnt/c/Python314/python.exe restore_native_cache.py --cache "$(wslpath -w "$base/private-environment/native-cache")" --project "$(wslpath -w "$base/private-environment/original-source")" --leantar "$(wslpath -w "$base/.shoal/tools/leantar.exe")" --report native-restore-report.json | |