image.domain\self_evolve\meta_evolve.mbt

84.6% · 33 / 39 points · 191 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/meta_evolve
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 自演化 Meta — 元演化(演化演化本身)
  7. 7// Meta evolution: evolve the evolution process itself
  8. 8//
  9. 9// Phase 11 v314: 将演化从"质量评估"推向"元演化" — 演化演化本身。
  10. 10
  11. 11///|
  12. 12/// 元演化策略。
  13. 13/// 描述 Meta evolution strategy.
  14. 14/// `#non_exhaustive` 表示未来可能添加新构造器
  15. 15#derive(Eq, @debug.Debug)
  16. 16#non_exhaustive
  17. 17pub(all) enum MetaStrategy {
  18. 18 TightenThresholds // 收紧阈值
  19. 19 LoosenThresholds // 放宽阈值
  20. 20 AddTestCategory // 增加测试类别
  21. 21 RemoveRedundancy // 消除冗余
  22. 22 IncreaseCoverage // 提升覆盖
  23. 23}
  24. 24
  25. 25///|
  26. 26pub extend MetaStrategy with @debug.Debug::{to_repr}
  27. 27
  28. 28///|
  29. 29pub extend MetaStrategy with Eq::{not_equal, equal}
  30. 30
  31. 31///|
  32. 32/// 元演化动作。
  33. 33/// 描述 Meta evolution action.
  34. 34#derive(Eq, @debug.Debug)
  35. 35pub(all) struct MetaAction {
  36. 36 strategy : MetaStrategy
  37. 37 target_param : String
  38. 38 current_value : Int32
  39. 39 new_value : Int32
  40. 40 rationale : String
  41. 41}
  42. 42
  43. 43///|
  44. 44pub extend MetaAction with @debug.Debug::{to_repr}
  45. 45
  46. 46///|
  47. 47pub extend MetaAction with Eq::{not_equal, equal}
  48. 48
  49. 49///|
  50. 50/// 元演化报告。
  51. 51/// 描述 Meta evolution report.
  52. 52#derive(Eq, @debug.Debug)
  53. 53pub(all) struct MetaReport {
  54. 54 actions : Array[MetaAction]
  55. 55 total_strategies : Int32
  56. 56 applied_count : Int32
  57. 57 summary : String
  58. 58}
  59. 59
  60. 60///|
  61. 61pub extend MetaReport with @debug.Debug::{to_repr}
  62. 62
  63. 63///|
  64. 64pub extend MetaReport with Eq::{not_equal, equal}
  65. 65
  66. 66///|
  67. 67/// 对单个算子进行元演化。
  68. 68/// 性能 Perform meta evolution for a single op.
  69. 69pub fn meta_evolve_op(op : @imgir.IROp) -> MetaReport {
  70. 70● let tag = op.tag()
  71. 71● let quality = eval_quality_op(op)
  72. 72 let actions : Array[MetaAction] = []
  73. 73 for qs in quality.scores {
  74. 74● match qs.dimension {
  75. 75 TestCoverage =>
  76. 76● if qs.score < 80 {
  77. 77● actions.push({
  78. 78 strategy: IncreaseCoverage,
  79. 79 target_param: "coverage_threshold",
  80. 80 current_value: 80,
  81. 81 new_value: 70,
  82. 82 rationale: tag +
  83. 83 " 覆盖 " +
  84. 84● qs.score.to_string() +
  85. 85 "% → 降低阈值加速演化",
  86. 86 })
  87. 87 }
  88. 88 DegradationRate =>
  89. 89● if qs.score < 100 {
  90. 90● actions.push({
  91. 91 strategy: TightenThresholds,
  92. 92 target_param: "degradation_tolerance",
  93. 93 current_value: 3,
  94. 94 new_value: 2,
  95. 95 rationale: tag +
  96. 96 " 退化评分 " +
  97. 97● qs.score.to_string() +
  98. 98 " → 收紧容忍",
  99. 99 })
  100. 100 }
  101. 101 PerformanceGain =>
  102. 102● if qs.score > 80 {
  103. 103○ actions.push({
  104. 104 strategy: RemoveRedundancy,
  105. 105 target_param: "redundant_tests",
  106. 106 current_value: 5,
  107. 107 new_value: 3,
  108. 108 rationale: tag +
  109. 109 " 评分 " +
  110. 110○ qs.score.to_string() +
  111. 111 " → 消除冗余测试",
  112. 112 })
  113. 113 }
  114. 114 CodeStability =>
  115. 115● if qs.score < 70 {
  116. 116● actions.push({
  117. 117 strategy: AddTestCategory,
  118. 118 target_param: "test_categories",
  119. 119 current_value: 3,
  120. 120 new_value: 4,
  121. 121 rationale: tag +
  122. 122 " 稳定性 " +
  123. 123● qs.score.to_string() +
  124. 124 " → 增加边界测试",
  125. 125 })
  126. 126 }
  127. 127 ApiCompatibility =>
  128. 128● if quality.overall_score > 90 {
  129. 129○ actions.push({
  130. 130 strategy: LoosenThresholds,
  131. 131 target_param: "evolve_threshold",
  132. 132 current_value: 60,
  133. 133 new_value: 50,
  134. 134 rationale: tag +
  135. 135 " 总分 " +
  136. 136○ quality.overall_score.to_string() +
  137. 137 " → 放宽阈值加速",
  138. 138 })
  139. 139 }
  140. 140 }
  141. 141 }
  142. 142● let applied = actions.length()
  143. 143 let total_strategies = 5
  144. 144 let summary = "元演化[" +
  145. 145 tag +
  146. 146 "]: " +
  147. 147● applied.to_string() +
  148. 148 " 动作, 总分 " +
  149. 149● quality.overall_score.to_string()
  150. 150 { actions, total_strategies, applied_count: applied, summary, }
  151. 151}
  152. 152
  153. 153///|
  154. 154/// 对所有算子进行元演化。
  155. 155/// 性能 Perform meta evolution for all ops.
  156. 156pub fn meta_evolve_all() -> MetaReport {
  157. 157● let all_actions : Array[MetaAction] = []
  158. 158 let mut total_applied = 0
  159. 159● for op in all_ops() {
  160. 160● let report = meta_evolve_op(op)
  161. 161 for a in report.actions {
  162. 162● all_actions.push(a)
  163. 163 }
  164. 164 total_applied = total_applied + report.applied_count
  165. 165 }
  166. 166 let summary = "全量元演化: " +
  167. 167● all_actions.length().to_string() +
  168. 168 " 动作, " +
  169. 169● total_applied.to_string() +
  170. 170 " 已应用"
  171. 171 {
  172. 172 actions: all_actions,
  173. 173 total_strategies: 5,
  174. 174 applied_count: total_applied,
  175. 175 summary,
  176. 176 }
  177. 177}
  178. 178
  179. 179///|
  180. 180/// 元演化报告是否有变更。
  181. 181/// 描述 Whether meta report has changes.
  182. 182pub fn MetaReport::has_changes(self : MetaReport) -> Bool {
  183. 183● self.applied_count > 0
  184. 184}
  185. 185
  186. 186///|
  187. 187/// 元演化报告策略数。
  188. 188/// 描述 Strategy count.
  189. 189pub fn MetaReport::strategy_count(self : MetaReport) -> Int32 {
  190. 190● self.total_strategies
  191. 191}