Files
NODEDC_MISSION_CORE/simulation/urban-plan-research/evaluation/qualify_systematic.py
T
DCCONSTRUCTIONS 69dc566665 feat(research): preserve urban geometry pipelines and qualification suites
Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
2026-10-29 09:10:00 +03:00

55 lines
4.2 KiB
Python

"""Freeze a candidate source closure, reserve Worker, run and collect evidence."""
from pathlib import Path
import base64,hashlib,json,subprocess,sys,uuid,ast
repo=Path(__file__).resolve().parents[3];module=repo/'simulation/urban-plan-research'
config=json.loads(Path(sys.argv[1]).read_text());session=config['session']
if not session.startswith('systematic-')or any(c not in 'abcdefghijklmnopqrstuvwxyz0123456789-'for c in session):raise ValueError('Invalid session')
root=repo/'.runtime/simulation-qualifications'/session;root.mkdir(exist_ok=False)
definition=json.loads((module/'systematic/definition.json').read_text());paths={v for g in definition['groups']for v in g['files'].values()}
paths.add('evaluation/contract_preflight.py')
paths.add('evaluation/execution_profile.py')
paths.add('evaluation/qualify_execution_reuse.py')
paths.add('evaluation/run_frozen_tail.py')
paths.add('evaluation/qualify_stroke_execution.py')
paths.add('systematic/qualify_primary_plan.py')
paths.update('pipeline/'+p for p in ['config-ortho.json','config-mv.json','worker-profile.json'])
files={}
for relative in sorted(paths):
path=module/relative
assert not path.is_symlink() and path.resolve().is_relative_to(module.resolve())
data=path.read_bytes()
if path.suffix=='.py':ast.parse(data)
files['simulation/urban-plan-research/'+relative]=dict(sha256=hashlib.sha256(data).hexdigest(),content=base64.b64encode(data).decode())
for relative in ['simulation/ai-polygon/infrastructure_containers.py','simulation/ai-polygon/infrastructure_pipeline.py']:
data=(repo/relative).read_bytes();ast.parse(data)
files[relative]=dict(sha256=hashlib.sha256(data).hexdigest(),content=base64.b64encode(data).decode())
data=(module/'systematic/definition.json').read_bytes()
files['simulation/urban-plan-research/pipeline/definition.json']=dict(sha256=hashlib.sha256(data).hexdigest(),content=base64.b64encode(data).decode())
config['files']=files
worker=Path(__file__).with_name('run_systematic_worker.py').read_bytes();config['worker_sha256']=hashlib.sha256(worker).hexdigest()
(root/'worker.py').write_bytes(worker);(root/'builder.py').write_bytes(Path(__file__).read_bytes())
(root/'config.json').write_text(json.dumps({k:v for k,v in config.items()if k!='files'},indent=2))
(root/'source-manifest.json').write_text(json.dumps({k:v['sha256']for k,v in files.items()},indent=2))
sys.path.insert(0,str(repo/'src'))
from k1link.observatory.recorded_jobs import ObservatoryRecordedJobQueue
queue=ObservatoryRecordedJobQueue(repo/'.runtime/mission-core',definitions=None);owner='airun-'+uuid.uuid4().hex
queue.reserve_simulation(owner);receipt=dict(owner=owner,state='reserved');(root/'reservation.json').write_text(json.dumps(receipt))
ssh=['ssh','-T','-o','BatchMode=yes','-o','StrictHostKeyChecking=yes','-o','ConnectTimeout=15','-o','ServerAliveInterval=15','-o','ServerAliveCountMax=8','mission-gpu','D:/NDC_MISSIONCORE/runtime/simulation/isaac-sim-6.1.0/kit/python/python.exe -u -B -']
code='import json,base64\nCONFIG=json.loads(base64.b64decode('+repr(base64.b64encode(json.dumps(config).encode()).decode())+'))\n'+worker.decode()
try:
p=subprocess.Popen(ssh,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True,errors='replace');p.stdin.write(code);p.stdin.close();info=None
with (root/'execution.log').open('w')as log:
for line in p.stdout:
log.write(line);log.flush();print(line,end='',flush=True)
if line.startswith('COLLECTION '):info=json.loads(line[11:])
if p.wait()!=0 or not info:raise RuntimeError('Candidate failed; see frozen evidence')
assert info['bytes']<30*1024**2
target=root/'summary.json';subprocess.run(['scp','-q','mission-gpu:'+info['path'].replace('\\','/'),str(target)],check=True)
assert hashlib.sha256(target.read_bytes()).hexdigest()==info['sha256']
print('COLLECTED',root,flush=True)
finally:
check=subprocess.run(ssh,input="from pathlib import Path\nprint(Path('C:/NDC_MISSIONCORE_CACHE/urban-mapping/qualifications/"+session+"/active.json').exists())",text=True,capture_output=True,timeout=30)
if check.returncode==0 and check.stdout.strip()=='False':queue.release_simulation(owner);receipt['state']='released'
else:receipt['state']='cleanup-unconfirmed'
(root/'reservation.json').write_text(json.dumps(receipt))