image.domain\self_evolve\evolve_loop.mbt

91.7% · 33 / 36 points · 118 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

  1. 1///|
  2. 2/// # 进化 self_evolve/evolve_loop
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 自演化闭环 — 串联 test_gen + degrade + optimize + perf
  7. 7// Evolution loop: full cycle connecting all self_evolve capabilities
  8. 8
  9. 9///|
  10. 10/// 自演化闭环报告。
  11. 11/// 描述 Evolution cycle report.
  12. 12#derive(Eq, @debug.Debug)
  13. 13pub(all) struct EvolveCycleReport {
  14. 14 pipeline_desc : String
  15. 15 original_op_count : Int32
  16. 16 optimized_op_count : Int32
  17. 17 generated_tests : Array[TestCase]
  18. 18 found_degradations : Array[DegradationCase]
  19. 19 optimization_report : OptimizationReport
  20. 20 perf_regression : PerfRegression
  21. 21 cycle_summary : String
  22. 22}
  23. 23
  24. 24///|
  25. 25pub extend EvolveCycleReport with @debug.Debug::{to_repr}
  26. 26
  27. 27///|
  28. 28pub extend EvolveCycleReport with Eq::{not_equal, equal}
  29. 29
  30. 30///|
  31. 31/// 完整自演化闭环:退化发现 → 测试生成 → 管道优化 → 性能回归 → 综合报告。
  32. 32/// 描述 Full evolution cycle: degradation → test gen → optimize → perf → report.
  33. 33pub fn evolve_full_cycle(pipeline : @imgir.IRPipeline) -> EvolveCycleReport {
  34. 34● let ops = pipeline.ops
  35. 35 // 1. 退化发现
  36. 36● let degradations = scan_degradations(ops)
  37. 37 // 2. 测试生成
  38. 38● let tests = evolve_test_suite(ops)
  39. 39 // 3. 管道优化
  40. 40● let opt_report = optimize_all(pipeline)
  41. 41 // 4. 性能回归
  42. 42● let perf = perf_optimize_check(pipeline)
  43. 43 // 5. 综合报告
  44. 44 let summary = "管道 '" +
  45. 45● @imgir.ir_describe(pipeline) +
  46. 46 "': " +
  47. 47● ops.length().to_string() +
  48. 48 " 算子 → " +
  49. 49● opt_report.optimized_length.to_string() +
  50. 50 " 优化后, " +
  51. 51● tests.length().to_string() +
  52. 52 " 测试, " +
  53. 53● degradations.length().to_string() +
  54. 54 " 退化, 成本变化 " +
  55. 55● perf.delta.to_string()
  56. 56 {
  57. 57● pipeline_desc: @imgir.ir_describe(pipeline),
  58. 58● original_op_count: ops.length(),
  59. 59 optimized_op_count: opt_report.optimized_length,
  60. 60 generated_tests: tests,
  61. 61 found_degradations: degradations,
  62. 62 optimization_report: opt_report,
  63. 63 perf_regression: perf,
  64. 64 cycle_summary: summary,
  65. 65 }
  66. 66}
  67. 67
  68. 68///|
  69. 69/// 对全部 19 种算子执行自演化闭环。
  70. 70/// 运行 Run evolution cycle on all 19 op variants.
  71. 71pub fn evolve_cycle_all() -> Array[EvolveCycleReport] {
  72. 72● let reports : Array[EvolveCycleReport] = []
  73. 73● for op in all_ops() {
  74. 74● let pipe = @imgir.IRPipeline::new().add(op)
  75. 75● reports.push(evolve_full_cycle(pipe))
  76. 76 }
  77. 77 reports
  78. 78}
  79. 79
  80. 80///|
  81. 81/// 闭环是否改善了管道(算子减少且成本降低)。
  82. 82/// 描述 Whether cycle improved the pipeline (fewer ops and lower cost).
  83. 83pub fn EvolveCycleReport::is_improved(self : EvolveCycleReport) -> Bool {
  84. 84● self.optimized_op_count < self.original_op_count &&
  85. 85● self.perf_regression.is_improvement()
  86. 86}
  87. 87
  88. 88///|
  89. 89/// 闭环是否有退化风险。
  90. 90/// 描述 Whether cycle has degradation risk.
  91. 91pub fn EvolveCycleReport::has_degradation_risk(
  92. 92 self : EvolveCycleReport,
  93. 93) -> Bool {
  94. 94● self.found_degradations.length() > 0
  95. 95}
  96. 96
  97. 97///|
  98. 98/// 闭环安全度(0-100,越高越安全)。
  99. 99/// 描述 Cycle safety score (0-100, higher is safer).
  100. 100pub fn EvolveCycleReport::safety_score(self : EvolveCycleReport) -> Int32 {
  101. 101● let deg_penalty = self.found_degradations.length() * 10
  102. 102
  103. 103 let mut severe_count = 0
  104. 104 for d in self.found_degradations {
  105. 105● match d.severity {
  106. 106○ Warning => ()
  107. 107○ Critical => severe_count = severe_count + 1
  108. 108● Fatal => severe_count = severe_count + 1
  109. 109 }
  110. 110 }
  111. 111 let severe_penalty = severe_count * 20
  112. 112 let score = 100 - deg_penalty - severe_penalty
  113. 113 if score < 0 {
  114. 114○ 0
  115. 115 } else {
  116. 116● score
  117. 117 }
  118. 118}