File size: 6,796 Bytes
3f15e9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import rhg_paths
from pathlib import Path
import json,os,subprocess,sys,time,traceback,hashlib
TREE=Path(__file__).resolve().parents[1];ROOT=TREE.parent;E=ROOT/'results';M=json.loads((E/'experiment.json').read_text());TRIAL=sys.argv[2] if len(sys.argv)>2 else ''; PREFIX=('r'+TRIAL+'_') if TRIAL else ''; CASE=Path(M['case']+('_r'+TRIAL if TRIAL else ''))
C=json.loads(Path(rhg_paths.resolve(os.environ.get('RHG_COMPARISON_CONFIG', '${RHG_WORKSPACE_ROOT}/current_vs_v31_20261031/COMPARISON_CONFIG.json'))).read_text())
P=json.loads(Path(rhg_paths.resolve(os.environ.get('RHG_READY_POOL', '${RHG_WORKSPACE_ROOT}/current_vs_v31_20261031/rebuild_current_pool_v2/ready.json'))).read_text())
I=json.loads(Path(rhg_paths.resolve(os.environ.get('RHG_MATCHED_COHORT', '${RHG_WORKSPACE_ROOT}/codex_stability_hardening_20261110/codex_candidate14_20261111/results/cohorts/matched.json'))).read_text())
BLENDER=rhg_paths.resolve('${RHG_BLENDER}')
def save(path,data):
 path.parent.mkdir(parents=True,exist_ok=True);tmp=path.with_suffix('.tmp');tmp.write_text(json.dumps(data,indent=2,ensure_ascii=False,allow_nan=False));tmp.replace(path)
def env():
 e={k:os.environ[k] for k in ('PATH','LANG','LC_ALL','TZ','HOME') if k in os.environ}
 e.update(PYTHONDONTWRITEBYTECODE='1',OMP_NUM_THREADS='4',OPENBLAS_NUM_THREADS='4',MKL_NUM_THREADS='4',NUMEXPR_NUM_THREADS='4',CUDA_VISIBLE_DEVICES='',RHG_BLENDER=BLENDER,PYTHONPATH=':'.join(str(TREE/p) for p in ('engine/supervisor_site','engine','.')),RHG_RPLAN_SEEDS=str(ROOT/'inputs/selected_floorplan.json'),RHG_ATTRIBUTE_INDEX_CACHE=str(ROOT/'attribute_index_cache'))
 e.update({k:v for k,v in os.environ.items() if k in rhg_paths.LEGACY_DEFAULTS or k in ('RHG_PATHS_LEGACY_DEFAULTS','RHG_REPO_ROOT')})
 e.update(I.get('extra_env',{}))
 for k in ('TMPDIR','XDG_CACHE_HOME','CUDA_CACHE_PATH','TORCH_HOME'):
  d=ROOT/'isolated'/k;d.mkdir(parents=True,exist_ok=True);e[k]=str(d)
 return e
def stage(name,command,seconds,cpus='176-179'):
 name=PREFIX+name; logdir=E/'stages';logdir.mkdir(exist_ok=True)
 receipt=logdir/(name+'.json')
 if receipt.exists():raise RuntimeError('Stage already exists '+name)
 wrapped=['/usr/bin/taskset','-c',cpus,'/usr/bin/nice','-n','10','/usr/bin/bwrap','--ro-bind','/','/','--bind',str(ROOT),str(ROOT),'--proc','/proc','--dev','/dev','--tmpfs','/tmp','--unshare-net','--unshare-pid','--die-with-parent','--chdir',str(TREE),'--','/usr/bin/timeout','-k','30',str(seconds),*command]
 row=dict(stage=name,command=command,wrapped_command=wrapped,started_at=time.time(),timeout_s=seconds,cpu_affinity=cpus,status='running');save(receipt,row)
 with (logdir/(name+'.log')).open('w') as log:
  proc=subprocess.Popen(wrapped,cwd=TREE,env=env(),stdin=subprocess.DEVNULL,stdout=log,stderr=subprocess.STDOUT);row['pid']=proc.pid;save(receipt,row);code=proc.wait()
 row.update(returncode=code,ended_at=time.time(),elapsed_s=time.time()-row['started_at'],status='completed' if code==0 else 'failed');save(receipt,row);print(json.dumps(row),flush=True);return code
py=['/usr/bin/python3','-B','-u',str(TREE/'scene_workflow.py')]
mode=sys.argv[1]
try:
 if mode=='shell':
  cmd=py+['build-shell','--case',str(CASE),'--rootfs',C['rootfs'],'--seed',str(M['seed']),'--blender',BLENDER,'--description','生成完整住宅场景,3室,包含客厅、餐厅、厨房、卫生间和阳台。']
  code=stage('build_shell',cmd,300)
 elif mode=='generate':
  cmd=py+['prepare','--case',str(CASE),'--seed',str(M['seed']),'--residential-profile','balanced_visual_v1']
  if TRIAL=='2':cmd+=['--retrieval-rounds','4']
  if TRIAL in ('4','5'):cmd+=['--asset-plan',str(ROOT/'inputs/verified_kitchen_pair.json')]
  if TRIAL.isdecimal() and int(TRIAL)>=6:cmd+=['--asset-plan',str(ROOT/'inputs/verified_kitchen_with_range.json')]
  for k in ('rootfs','runtime_template','collision_frame_mappings','mdl_sdk_root','mdl_sdk_python','material_artifact_index'):cmd+=['--'+k.replace('_','-'),C[k]]
  cmd+=['--attribute-release',I['inputs']['attribute_release'],'--prepared-asset-pool',P['main'],'--supplemental-prepared-pool',P['supplement'],'--prepared-cache',P['supplement'],'--retrieval-index',I['inputs']['retrieval_index'],'--appearance-index',I['inputs']['appearance_index'],'--artifact-cache-root',str(ROOT/'artifact_cache')]
  code=stage('prepare',cmd,1200)
  if code==0: code=stage('execute',py+['execute','--case',str(CASE)],1200)
 elif mode=='execute-fixed':
  code=stage('execute_source_catalog_fixed',py+['execute','--case',str(CASE),'--output',str(CASE/'execution_source_catalog_fixed')],1200)
 elif mode=='diagnostic-render':
  attempt=CASE/'execution/chain/round_01/attempt_01'
  geometry=json.loads((attempt/'geometry/result.json').read_text())
  matches=[m for m in (attempt/'generated').glob('*/composition_manifest.runtime.json') if hashlib.sha256(m.read_bytes()).hexdigest()==geometry.get('manifest_sha256')]
  if len(matches)!=1:raise RuntimeError('Need one native geometry-bound diagnostic manifest')
  manifest=matches[0];scene=manifest.parent;blend=scene/(scene.name+'.blend')
  if hashlib.sha256(blend.read_bytes()).hexdigest()!=geometry['scene_sha256']:raise RuntimeError('Diagnostic scene hash mismatch')
  save(E/(PREFIX+'diagnostic_scene.json'),dict(diagnostic_only=True,geometry_passed=geometry.get('full_geometry_passed'),generated_manifest=str(manifest),scene=str(scene),geometry=str(attempt/'geometry/result.json')))
  cmd=['bash',rhg_paths.resolve(os.environ.get('RHG_RENDER_SCRIPT', '${RHG_WORKSPACE_ROOT}/renders_20261104/run_render_cpu.sh')),str(TREE),str(CASE),str(scene),str(E/(PREFIX+'diagnostic_render')),'16']
  code=stage('diagnostic_render',cmd,1050,'176-191')
 elif mode=='render':
  recovery=json.loads((CASE/'layout_recovery_execution.json').read_text())
  candidates=[Path(recovery['final_output'])/'result.json']
  records=[(p,json.loads(p.read_text())) for p in candidates if p.is_file()]
  records=[r for r in records if r[1].get('generated_manifest')]
  if not records:raise RuntimeError('No generated manifest')
  p,result=records[-1];manifest=Path(result['generated_manifest']);scene=manifest.parent
  save(E/(PREFIX+'final_scene.json'),dict(result_path=str(p),generated_manifest=str(manifest),scene=str(scene)))
  cmd=['bash',rhg_paths.resolve(os.environ.get('RHG_RENDER_SCRIPT', '${RHG_WORKSPACE_ROOT}/renders_20261104/run_render_cpu.sh')),str(TREE),str(p.parents[1]),str(scene),str(E/(PREFIX+'render_views')),'16']
  code=stage('render',cmd,1050,'176-191')
 else:raise ValueError(mode)
 save(E/(PREFIX+mode+'_done.json'),dict(returncode=code,finished_at=time.time()))
except Exception as exc:
 save(E/(PREFIX+mode+'_error.json'),dict(error=repr(exc),traceback=traceback.format_exc(),time=time.time()));raise
sys.exit(code)