File size: 3,764 Bytes
92f480e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""v0.5 fractional functional RLVR; faults never become learner zeroes."""
import hashlib,json,os,subprocess
from pathlib import Path
from rlvr_metrics import combine,VERSION

OUT=Path(os.environ.get('T19_OUTPUT_DIR','/logs/verifier'))
ROOT=Path(os.environ.get('T19_SUBMISSION_DIR','/root/rig'))
BLENDER=os.environ.get('BLENDER_BIN','/opt/blender/blender')
HERE=Path(__file__).resolve().parent

def sha(path):return hashlib.sha256(Path(path).read_bytes()).hexdigest()

def evaluate():
    OUT.mkdir(parents=True,exist_ok=True)
    for name in ('reward.txt','reward.json'): (OUT/name).unlink(missing_ok=True)
    if not Path(BLENDER).is_file():raise RuntimeError('Blender runtime missing')
    version=subprocess.run([BLENDER,'--version'],capture_output=True,text=True,timeout=30)
    if version.returncode or not version.stdout.startswith('Blender 5.0.1'):raise RuntimeError('Pinned Blender 5.0.1 required')
    profile=json.loads((HERE/'quality-profile.json').read_text())
    if profile.get('status')!='calibrated_native_controls':raise RuntimeError('Quality profile not calibrated')
    candidates=[]
    for kind in ('straight','curved'):
        file=ROOT/(kind+'.blend')
        if not file.is_file():continue
        digest=sha(file);evidence=OUT/(kind+'.native.json');evidence.unlink(missing_ok=True)
        # Known invalid data is learner output failure; a recognizable native
        # format that the pinned loader cannot open needs review, not a zero.
        with file.open('rb') as source:
            header=source.read(16)
        if not header.startswith((b'BLENDER',b'\x28\xb5\x2f\xfd')):
            candidates.append({'kind':kind,'file':str(file),'sha256':digest,'status':'invalid_native'});continue
        run=subprocess.run([BLENDER,'-b','-Y',str(file),'--python-exit-code','1','--python',str(HERE/'sample_rig_rlvr.py'),'--',str(evidence)],capture_output=True,text=True,timeout=300,
                           env={**os.environ,'HOME':'/tmp/t19-rlvr-verifier-home'})
        (OUT/(kind+'.blender.log')).write_text(run.stdout+'\n'+run.stderr)
        if run.returncode or not evidence.is_file():raise RuntimeError(kind+' native extraction failed; review required')
        if sha(file)!=digest:raise RuntimeError('Candidate mutated during inspection')
        sample=json.loads(evidence.read_text())
        candidates.append({'kind':kind,'file':str(file),'sha256':digest,'sample':sample})
    result=combine(candidates,profile)
    result['provenance']={'scorer_sha256':sha(HERE/'rlvr_metrics.py'),'extractor_sha256':sha(HERE/'sample_rig_rlvr.py'),'quality_profile_sha256':sha(HERE/'quality-profile.json'),'blender_version':version.stdout.splitlines()[0]}
    from recording_audit import audit
    try:recordings=audit(ROOT)
    except Exception as error:recordings={'status':'recording_verifier_error','error':str(error),'reward_effect':'none; separate ungraded requirement'}
    (OUT/'recording-diagnostics.json').write_text(json.dumps(recordings,indent=2)+'\n')
    (OUT/'score-v05.json').write_text(json.dumps(result,indent=2)+'\n')
    (OUT/'reward.json').write_text(json.dumps({'reward':result['reward'],'version':VERSION,'stages':result['stages']},indent=2)+'\n')
    (OUT/'reward.txt').write_text(f"{result['reward']:.6f}\n")
    return result

def test_rlvr():
    try:
        result=evaluate()
        print(json.dumps({'reward':result['reward'],'stages':result['stages']},indent=2))
        assert 0<=result['reward']<=1
    except Exception as error:
        OUT.mkdir(parents=True,exist_ok=True)
        for name in ('reward.txt','reward.json'):(OUT/name).unlink(missing_ok=True)
        (OUT/'evaluation-error.json').write_text(json.dumps({'version':VERSION,'status':'verifier_error','error':str(error)})+'\n')
        raise