Constraint Shield for Learned Interaction Dynamics / verification_report.py

Mechanism failed

Raw ⬇ ZIP
 1import json
 2from pathlib import Path
 3
 4x = json.loads(Path('results.json').read_text())
 5checks = x['math_checks']
 6target_rows = [r for r in x['rows'] if r['sweep'] == 'target']
 7stiff_rows = [r for r in x['rows'] if r['sweep'] == 'stiffness']
 8
 9obs_cross = next(r['target'] for r in target_rows if r['baseline']['violation_rate'] > 0)
10pred_cross = checks['nominal_crossing_target_predicted']
11max_shield_violation = max(r['idea']['violation_rate'] for r in x['rows'])
12max_shield_peak = max(r['idea']['peak_force'] for r in x['rows'])
13scale_errors = [abs(r['baseline']['peak_force'] - r['k'] * .20) for r in stiff_rows]
14
15report = {
16    'predictions': [
17        {
18            'claim': 'static force boundary penetration = F_safe / stiffness',
19            'predicted': checks['predicted_boundary_penetrations'],
20            'observed': checks['observed_boundary_penetrations'],
21            'max_abs_error': checks['force_boundary_max_abs_error'],
22            'pass': checks['force_boundary_max_abs_error'] < 1e-10,
23        },
24        {
25            'claim': 'nominal violation starts near target = F_safe / stiffness',
26            'predicted': pred_cross,
27            'observed_grid_first_violation': obs_cross,
28            'absolute_error': abs(obs_cross - pred_cross),
29            'pass': abs(obs_cross - pred_cross) <= .01,
30        },
31        {
32            'claim': 'shield keeps predicted/actual force below safety level when feasible',
33            'safety_level_with_margin': .48,
34            'max_observed_shield_peak_force': max_shield_peak,
35            'max_shield_violation_rate': max_shield_violation,
36            'pass': max_shield_violation == 0.0,
37        },
38        {
39            'claim': 'unshielded peak force scales as stiffness times target penetration',
40            'max_abs_scaling_error': max(scale_errors),
41            'pass': max(scale_errors) <= 1e-10,
42        },
43    ],
44    'summary': {
45        'baseline_target_high_force_violation_rates': {
46            str(r['target']): r['baseline']['violation_rate'] for r in target_rows if r['target'] >= .08
47        },
48        'shield_target_high_force_violation_rates': {
49            str(r['target']): r['idea']['violation_rate'] for r in target_rows if r['target'] >= .08
50        },
51        'shield_feasible_rate_min': min(r['idea']['feasible_rate'] for r in x['rows']),
52    },
53}
54Path('verification_report.json').write_text(json.dumps(report, indent=2))
55print(json.dumps(report, indent=2))