image.domain\self_evolve\schedule.mbt

86.4% · 19 / 22 points · 142 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/schedule
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 演化调度引擎 — 调度并执行自动演化周期
  7. 7// Evolution schedule engine: schedule and execute automatic evolution cycles
  8. 8//
  9. 9// Phase 9 v301: 将演化从"手动"推向"自动调度" — 创建调度→执行→报告。
  10. 10
  11. 11///|
  12. 12/// 调度状态。
  13. 13/// 调度 Schedule status.
  14. 14/// `#non_exhaustive` 表示未来可能添加新构造器
  15. 15#derive(Eq, @debug.Debug)
  16. 16#non_exhaustive
  17. 17pub(all) enum ScheduleStatus {
  18. 18 Pending
  19. 19 Running
  20. 20 Completed
  21. 21 Failed
  22. 22}
  23. 23
  24. 24///|
  25. 25pub extend ScheduleStatus with @debug.Debug::{to_repr}
  26. 26
  27. 27///|
  28. 28pub extend ScheduleStatus with Eq::{not_equal, equal}
  29. 29
  30. 30///|
  31. 31/// 演化调度计划。
  32. 32/// 描述 Evolution schedule plan.
  33. 33#derive(Eq, @debug.Debug)
  34. 34pub(all) struct EvolutionSchedule {
  35. 35 schedule_id : String
  36. 36 ops_count : Int32
  37. 37 status : ScheduleStatus
  38. 38 description : String
  39. 39}
  40. 40
  41. 41///|
  42. 42pub extend EvolutionSchedule with @debug.Debug::{to_repr}
  43. 43
  44. 44///|
  45. 45pub extend EvolutionSchedule with Eq::{not_equal, equal}
  46. 46
  47. 47///|
  48. 48/// 调度执行结果。
  49. 49/// 调度 Schedule execution result.
  50. 50#derive(Eq, @debug.Debug)
  51. 51pub(all) struct ScheduleResult {
  52. 52 schedule : EvolutionSchedule
  53. 53 evolved_count : Int32
  54. 54 fixed_count : Int32
  55. 55 remaining_count : Int32
  56. 56 summary : String
  57. 57}
  58. 58
  59. 59///|
  60. 60pub extend ScheduleResult with @debug.Debug::{to_repr}
  61. 61
  62. 62///|
  63. 63pub extend ScheduleResult with Eq::{not_equal, equal}
  64. 64
  65. 65///|
  66. 66/// 为给定算子列表创建演化调度。
  67. 67/// 创建 Create evolution schedule for given ops.
  68. 68pub fn create_schedule(ops : Array[@imgir.IROp]) -> EvolutionSchedule {
  69. 69● let count = ops.length()
  70. 70● let id = "sched-" + count.to_string() + "-ops"
  71. 71 {
  72. 72 schedule_id: id,
  73. 73 ops_count: count,
  74. 74 status: Pending,
  75. 75● description: "调度 " + count.to_string() + " 个算子的演化周期",
  76. 76 }
  77. 77}
  78. 78
  79. 79///|
  80. 80/// 执行演化调度。
  81. 81/// 执行 Execute evolution schedule.
  82. 82pub fn run_schedule(schedule : EvolutionSchedule) -> ScheduleResult {
  83. 83● let running_schedule = {
  84. 84 schedule_id: schedule.schedule_id,
  85. 85 ops_count: schedule.ops_count,
  86. 86 status: Running,
  87. 87 description: schedule.description,
  88. 88 }
  89. 89● let ops = all_ops()
  90. 90 let mut evolved = 0
  91. 91 let mut fixed = 0
  92. 92 let mut remaining = 0
  93. 93 for op in ops {
  94. 94● let degs = detect_degradation(op)
  95. 95● let rec = recommend_next(op)
  96. 96● if degs.length() > 0 {
  97. 97○ evolved = evolved + 1
  98. 98 if rec.action is FixDegradation {
  99. 99○ fixed = fixed + 1
  100. 100 } else {
  101. 101○ remaining = remaining + 1
  102. 102 }
  103. 103 } else {
  104. 104● evolved = evolved + 1
  105. 105 }
  106. 106 }
  107. 107 let completed_schedule = {
  108. 108 schedule_id: running_schedule.schedule_id,
  109. 109 ops_count: running_schedule.ops_count,
  110. 110 status: Completed,
  111. 111 description: running_schedule.description,
  112. 112 }
  113. 113 let summary = "调度执行完成: " +
  114. 114● evolved.to_string() +
  115. 115 " 算子已演化, " +
  116. 116● fixed.to_string() +
  117. 117 " 退化已修复, " +
  118. 118● remaining.to_string() +
  119. 119 " 退化待修复"
  120. 120 {
  121. 121 schedule: completed_schedule,
  122. 122 evolved_count: evolved,
  123. 123 fixed_count: fixed,
  124. 124 remaining_count: remaining,
  125. 125 summary,
  126. 126 }
  127. 127}
  128. 128
  129. 129///|
  130. 130/// 运行全量演化周期(所有算子)。
  131. 131/// 运行 Run full evolution cycle (all ops).
  132. 132pub fn run_full_evolution() -> ScheduleResult {
  133. 133● let schedule = create_schedule(all_ops())
  134. 134● run_schedule(schedule)
  135. 135}
  136. 136
  137. 137///|
  138. 138/// 调度结果是否成功(无剩余退化)。
  139. 139/// 描述 Whether schedule result is successful (no remaining degradations).
  140. 140pub fn ScheduleResult::is_successful(self : ScheduleResult) -> Bool {
  141. 141● self.schedule.status is Completed && self.remaining_count == 0
  142. 142}