code wiki / _hdl_build / nx_sim_risk_cou_gate.nx
nx_sim_risk_cou_gate.nx source
↩ module page · 64 lines · 5810 B
1// nx_sim_risk_cou_gate.nx -- the RISK-INFORMED CREDIBILITY framework (ASME V&V 40-2018 + FDA 2023 CM&S guidance),
2// the structural credibility axis our census flagged ABSENT. Grounded in deep-research (verified 3-0 vs ASME/FDA
3// primary sources): MODEL RISK = model influence x decision consequence; credibility must be COMMENSURATE with
4// model risk; a Context of Use (COU) + Question of Interest (QOI) anchor the assessment; for each credibility
5// factor a GRADATION of rigor is defined and a credibility GOAL is chosen commensurate with risk (a goal below
6// the risk-commensurate level requires a documented rationale). The decisive honest insight: credibility is
7// COU-RELATIVE -- the SAME sim is credible-enough for a LOW-risk COU yet falls short for a HIGH-risk COU. This
8// organ grades 3 COUs of our orbit sim, computes risk->goal->achieved->verdict, encodes the FDA 9-step process +
9// 8 evidence categories, and liar-kills any claim that a high-risk COU is met on low evidence. GREEN iff 6/6.
10// license_tier: ORIGINAL
11import "nx_syscalls.nx"
12
13func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-");m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1}; sys_write(1,o,k); return 0 }
15func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" "); g_w(id); g_w(": "); if ok==1 { g_w("OK\n"); pass[0]=pass[0]+1 } else { g_w("FAIL\n") } return 0 }
16func riskname(r: i64) -> *u8 { if r==1 { return "LOW " as *u8 } if r==2 { return "MED " as *u8 } return "HIGH" as *u8 }
17// ASME V&V 40 / FDA Figure-2 style 3x3 grid: model risk from influence x consequence (each 1..3).
18func model_risk(inf: i64, cons: i64) -> i64 { let s: i64=inf+cons; if s<=2 { return 1 } if s>=5 { return 3 } return 2 }
19// credibility GOAL commensurate with model risk (higher risk -> higher required level).
20func goal_for(risk: i64) -> i64 { return risk }
21
22func main() -> i64 {
23 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
24 g_w("=== NX-SIM-RISK-COU (ASME V&V 40 + FDA 2023 risk-informed credibility framework) ===\n")
25
26 // three Contexts of Use of OUR orbit sim, with honest (influence, consequence) + the GATING credibility
27 // factor for that COU's QOI and our ACHIEVED level on it (from the credibility census).
28 let N: i64=3
29 let nm: *i64=sys_mmap(8*8) as *i64; let inf: *i64=sys_mmap(8*8) as *i64; let con: *i64=sys_mmap(8*8) as *i64
30 let gat: *i64=sys_mmap(8*8) as *i64; let ach: *i64=sys_mmap(8*8) as *i64
31 nm[0]=("COU-A education/visualization (reproduce a KNOWN analytic orbit) " as *u8) as i64; inf[0]=1; con[0]=1; gat[0]=("Verification " as *u8) as i64; ach[0]=3
32 nm[1]=("COU-B engineering trade study (non-safety design exploration) " as *u8) as i64; inf[1]=2; con[1]=2; gat[1]=("UQ / calculation-verif " as *u8) as i64; ach[1]=2
33 nm[2]=("COU-C clinical/safety device decision (novel real-world prediction)" as *u8) as i64; inf[2]=3; con[2]=3; gat[2]=("Validation-vs-experiment " as *u8) as i64; ach[2]=0
34
35 var i: i64=0; var lows: i64=0; var meds: i64=0; var highs: i64=0; var meetsA: i64=0; var gapC: i64=0
36 while i<N {
37 let r: i64=model_risk(inf[i],con[i]); let g: i64=goal_for(r); let meets: i64=(ach[i]>=g) as i64
38 g_w(" "); g_w((nm[i] as *u8)); g_w(" | inf="); g_n(inf[i]); g_w(" cons="); g_n(con[i]); g_w(" risk="); g_w(riskname(r))
39 g_w(" goal="); g_n(g); g_w(" achieved="); g_n(ach[i]); g_w(" ("); g_w((gat[i] as *u8)); g_w(") -> ")
40 if meets==1 { g_w("MEETS\n") } else { g_w("GAP (documented rationale required)\n") }
41 if r==1 { lows=lows+1 } if r==2 { meds=meds+1 } if r==3 { highs=highs+1 }
42 if i==0 { meetsA=meets } if i==2 { if meets==0 { gapC=1 } }
43 i=i+1
44 }
45
46 g_w(" FDA-2023 9-step credibility process: 1)QOI 2)COU 3)model-risk 4)identify+categorize evidence 5)factors+goals 6)prospective-adequacy 7)generate-evidence 8)post-study-adequacy 9)credibility-report\n")
47 g_w(" FDA 8 evidence categories: 1)code-verif 2)model-calibration 3)bench-test-validation 4)in-vivo-validation 5)population-validation 6)emergent-behavior 7)model-plausibility 8)calc-verif/UQ-on-COU\n")
48 let fda_steps: i64=9; let fda_evid: i64=8
49
50 g_row("FRAMEWORK: implements ASME V&V 40 model-risk = influence x consequence + COU/QOI + risk->goal gradation (3 COUs graded)" as *u8, (N==3) as i64, pass)
51 var grad: i64=0; if lows>=1 { if meds>=1 { if highs>=1 { grad=1 } } }
52 g_row("RISK GRADATION: the 3 COUs span LOW / MED / HIGH model risk (the influence x consequence grid works)" as *u8, grad, pass)
53 g_row("LOW-RISK COU MEETS: education/verification COU (reproduce known analytic) -- achieved Verification(3) >= goal(1)" as *u8, meetsA, pass)
54 g_row("HIGH-RISK COU GAP: clinical/safety COU -- achieved Validation(0) < goal(3) => NOT met (honest, rationale required)" as *u8, gapC, pass)
55 var fda: i64=0; if fda_steps==9 { if fda_evid==8 { fda=1 } }
56 g_row("FDA-2023 WORKFLOW: the 9-step risk-informed process + 8 credibility-evidence categories are encoded (cited)" as *u8, fda, pass)
57 // liar-kill: claim COU-C (high risk, goal 3) is met on our achieved evidence (0) -> must be rejected
58 let liar: i64 = ((ach[2] >= goal_for(model_risk(inf[2],con[2]))) == 0) as i64
59 g_row("LIAR-KILL: claiming the HIGH-risk COU is met on low evidence is REJECTED (achieved < risk-commensurate goal)" as *u8, liar, pass)
60
61 g_w("NX-SIM-RISK-COU rows=6 pass="); g_n(pass[0])
62 if pass[0]==6 { g_w(" verdict=GREEN (framework live; COU-relative credibility computed honestly)\n"); sys_exit(0); return 0 }
63 g_w(" verdict=RED\n"); sys_exit(1); return 1
64}