image.domain\self_evolve\evolve_loop_full.mbt

97.5% · 39 / 40 points · 148 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_full
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 自演化闭环 — 完整的自主演化闭环
  7. 7// Evolution loop: complete autonomous evolution loop
  8. 8//
  9. 9// Phase 10 v309: 将演化从"参数调优"推向"闭环" — 预测→决策→策略→调优→执行→验证。
  10. 10
  11. 11///|
  12. 12/// 闭环阶段。
  13. 13/// 描述 Loop phase.
  14. 14/// `#non_exhaustive` 表示未来可能添加新构造器
  15. 15#derive(Eq, @debug.Debug)
  16. 16#non_exhaustive
  17. 17pub(all) enum LoopPhase {
  18. 18 Predict
  19. 19 Decide
  20. 20 Strategize
  21. 21 Tune
  22. 22 Execute
  23. 23 Verify
  24. 24 Done
  25. 25}
  26. 26
  27. 27///|
  28. 28pub extend LoopPhase with @debug.Debug::{to_repr}
  29. 29
  30. 30///|
  31. 31pub extend LoopPhase with Eq::{not_equal, equal}
  32. 32
  33. 33///|
  34. 34/// 单个闭环步骤。
  35. 35/// 描述 Single loop step.
  36. 36#derive(Eq, @debug.Debug)
  37. 37pub(all) struct LoopStep {
  38. 38 phase : LoopPhase
  39. 39 result_desc : String
  40. 40}
  41. 41
  42. 42///|
  43. 43pub extend LoopStep with @debug.Debug::{to_repr}
  44. 44
  45. 45///|
  46. 46pub extend LoopStep with Eq::{not_equal, equal}
  47. 47
  48. 48///|
  49. 49/// 闭环执行结果。
  50. 50/// 描述 Loop execution result.
  51. 51#derive(Eq, @debug.Debug)
  52. 52pub(all) struct LoopResult {
  53. 53 steps : Array[LoopStep]
  54. 54 total_phases : Int32
  55. 55 success : Bool
  56. 56 summary : String
  57. 57}
  58. 58
  59. 59///|
  60. 60pub extend LoopResult with @debug.Debug::{to_repr}
  61. 61
  62. 62///|
  63. 63pub extend LoopResult with Eq::{not_equal, equal}
  64. 64
  65. 65///|
  66. 66/// 为单个算子运行完整演化闭环。
  67. 67/// 运行 Run complete evolution loop for a single op.
  68. 68pub fn run_evolve_loop(op : @imgir.IROp) -> LoopResult {
  69. 69● let tag = op.tag()
  70. 70 let steps : Array[LoopStep] = []
  71. 71● let pred = predict_op(op)
  72. 72● steps.push({
  73. 73 phase: Predict,
  74. 74 result_desc: tag + " 预测: " + pred.description,
  75. 75 })
  76. 76● let decision = decide_op(op)
  77. 77● steps.push({
  78. 78 phase: Decide,
  79. 79 result_desc: tag + " 决策: " + decision.rationale,
  80. 80 })
  81. 81● let combo = combine_strategies(op)
  82. 82● steps.push({
  83. 83 phase: Strategize,
  84. 84 result_desc: tag + " 策略: " + combo.description,
  85. 85 })
  86. 86● let params = tune_params(op)
  87. 87● steps.push({
  88. 88 phase: Tune,
  89. 89● result_desc: tag + " 调优: " + params.length().to_string() + " 参数",
  90. 90 })
  91. 91● let sched = create_schedule([op])
  92. 92● let result = run_schedule(sched)
  93. 93● steps.push({
  94. 94 phase: Execute,
  95. 95 result_desc: tag + " 执行: " + result.summary,
  96. 96 })
  97. 97● let degs = detect_degradation(op)
  98. 98● let verify_desc = if degs.length() == 0 {
  99. 99● tag + " 验证: 无退化"
  100. 100 } else {
  101. 101● tag + " 验证: " + degs.length().to_string() + " 退化残留"
  102. 102 }
  103. 103● steps.push({ phase: Verify, result_desc: verify_desc, })
  104. 104● steps.push({ phase: Done, result_desc: tag + " 闭环完成", })
  105. 105● let total = steps.length()
  106. 106 let success = decision.action is EvolveNow || decision.action is SkipEvolution
  107. 107 let summary = "演化闭环[" +
  108. 108 tag +
  109. 109 "]: " +
  110. 110● total.to_string() +
  111. 111 " 阶段, " +
  112. 112● (if success { "成功" } else { "需关注" })
  113. 113 { steps, total_phases: total, success, summary, }
  114. 114}
  115. 115
  116. 116///|
  117. 117/// 为所有算子运行完整演化闭环。
  118. 118/// 运行 Run complete evolution loop for all ops.
  119. 119pub fn run_evolve_loop_all() -> LoopResult {
  120. 120● let all_steps : Array[LoopStep] = []
  121. 121 let mut all_success = true
  122. 122 let mut total_ops = 0
  123. 123● for op in all_ops() {
  124. 124● let result = run_evolve_loop(op)
  125. 125 for s in result.steps {
  126. 126● all_steps.push(s)
  127. 127 }
  128. 128 if !result.success {
  129. 129● all_success = false
  130. 130 }
  131. 131 total_ops = total_ops + 1
  132. 132 }
  133. 133● let total = all_steps.length()
  134. 134 let summary = "全量演化闭环: " +
  135. 135● total_ops.to_string() +
  136. 136 " 算子, " +
  137. 137● total.to_string() +
  138. 138 " 阶段, " +
  139. 139◐ (if all_success { "全部成功" } else { "部分需关注" })
  140. 140 { steps: all_steps, total_phases: total, success: all_success, summary, }
  141. 141}
  142. 142
  143. 143///|
  144. 144/// 闭环结果是否完整完成。
  145. 145/// 描述 Whether loop result is complete.
  146. 146pub fn LoopResult::is_complete(self : LoopResult) -> Bool {
  147. 147● self.total_phases > 0
  148. 148}