moonsmith-engine

    Deterministic campaign, oracle, and reduction algorithms for MoonSmith

    Download zip
    Author
    Version
    0.0.1
    License
    GPL-3.0-only
    Last updated
    7 hours ago
    Downloads
    8

    #MoonSmith Engine

    本模块当前提供语言无关的结果判定与有预算归约搜索,仅依赖共享契约。 Engine 的职责及术语定义 由提案维护;下文说明现有 API,不把当前算法作为统一设计要求。

    #判断与失败保持

    reference_assessment 比较参考输出与各配置的执行观察,保留全部配置的结果。 每个配置分别记录编译和执行检查;编译成功即表明原编译失败不再保持,已知编译失败时执行检查不适用。 编译证据不足时,执行检查也保持不可判定。 Assessment 同时表达异常、不适用和证据不足;findings 列出可选择的失败条件, match_failure 按 Oracle、配置、阶段与异常类别判断所选条件是否保持。 缺失或重复的结果不能证明失败保持。judge 和 summarize 仅为原型报告提供一个主结论, 完整性及其他判断仍以 Assessment 为准。

    #归约会话

    ReductionSession[P] 管理原程序、当前搜索位置、最佳结果及其证据。构造时传入初始证据、 失败判据、合法性检查、接受规则、最佳结果排序和候选预算;初始程序与失败条件必须有效。 具体策略自行选择候选,通过 offer 提交。会话检查合法性和接受资格后返回带标识的 ReductionRequest[P];调用方取得该候选自己的证据,再用同一个标识调用 observe。 只有判据得到保留的候选才能改变搜索状态,最佳结果排序独立于中间步骤的接受规则。

    一个会话最多等待一项候选执行。过期、重复或属于其他会话的响应不能推进状态。 每个实际提交的候选都消耗预算,包括非法或不满足接受规则的候选;等待期间重复调用 offer 不消耗预算。最后一个候选可完成评估,之后停止。切换策略继续使用同一会话与剩余预算。 停止原因区分预算耗尽、取消与策略结束;策略结束不声明局部或全局最小性。

    events 返回追加式内存记录的快照,保留初始程序和证据,并关联候选、反馈、证据和停止原因。 调用方提供唯一会话标识,保证程序值在会话中不被修改,并使用纯且确定的回调; 相同初值、候选序列及反馈产生相同决定。取消会话会忽略后续响应,实际进程回收由 Host 负责。 原程序和已取得的证据保留在会话中;应用层保存差分归约的执行记录和摘要,不支持搜索恢复。

    Reducer[P] 连接语言操作、局部枚举和固定调度:operations 是按顺序提供候选数组的回调, Enumeration[P] 只管理一项操作内的枚举游标,OperationSchedule[P] 只管理操作顺序与重启。 接受候选后丢弃旧枚举,从新程序重新开始固定操作顺序;切换操作不创建新会话或重置预算。 每项操作在轮到它时才构造候选数组,但数组内部仍是一次性构造,候选预算不限制其构造工作。

    构造函数要求初始证据、失败判据、合法性检查和 better(candidate, incumbent) 比较函数。 同一比较函数用于严格改善的接受规则和最佳结果排序,Engine 不解释成本的具体分量。 旧参考路径按节点数比较;差分路径由 MoonBit 适配器提供多分量成本。 next 返回候选及标识,observe 接收标识和 Assessment;等待时重复 next 返回同一请求。

    正式设计和验收条件见 FP-0004。本模块实现其基础切片; 其他局部搜索、范围遍历、复杂关系判据、可配置确认策略与跨案例编排尚待实现。 差分 CLI 已通过应用层使用结构缩减和 Int 简化两项操作, 参考判断仍是独立库能力。测试使用独立整数模型验证策略替换、失败保持及共享预算。

    #差分比较

    compare 对至少两个不同配置的正常结果进行差分比较,使用语言适配器传入的观察协议检查与 规范化输出,返回 Consistent、Difference(配置一, 配置二) 或 Incomplete。只有所有计划 配置完整且相同时才返回一致;已取得的有效分歧不会被其他配置的缺失、超时或失败掩盖。 分歧只标识结果不同的两个配置,不判断哪个配置错误。调用方保留完整原始观察。

    comparable_results 提取全部有效配置及规范化结果,与 compare 共用有效性规则。 应用层据此提供摘要,不在报告包重复判定;发现分歧之后的有效配置仍保留在摘要中。

    differential_assessment 保留每对计划配置的判断。Oracle 标识 differential:<基准配置> 和被比较配置共同标识配置对;difference_predicate 从首次分歧选择固定的身份。 两个有效值不同为违反、相同为满足,缺失或无效输出为证据不足。归约允许候选改变具体输出, 但不能换成另一对配置的分歧或其他失败类别。未完成的第三个配置不掩盖选中配置对的有效证据。

    测试使用可控观察验证差分边界;当前 CLI 通过应用层调用差分 API。

    CandidateId

    pub(all) struct CandidateId {
    session : String
    attempt : Int
    } derive(Eq,
    Debug
    )

    CandidateId::equal

    fn CandidateId::equal(CandidateId, CandidateId) -> Bool

    CandidateId::not_equal

    fn CandidateId::not_equal(x : CandidateId, y : CandidateId) -> Bool

    CandidateOutcome

    pub(all) enum CandidateOutcome {
    Accepted
    Invalid
    Disallowed
    Rejected(
    PredicateStatus
    )
    } derive(Eq,
    Debug
    )

    CandidateOutcome::equal

    CandidateOutcome::not_equal

    fn CandidateOutcome::not_equal(x : CandidateOutcome, y : CandidateOutcome) -> Bool

    Enumeration

    pub struct Enumeration[P] {
    // private fields
    }

    Enumeration::new

    fn[P] Enumeration::new(candidates : Array[P]) -> Enumeration[P]

    Enumeration::next

    fn[P] Enumeration::next(self : Enumeration[P]) -> P?

    Offer

    pub(all) enum Offer[P] {
    Evaluate(ReductionRequest[P])
    Declined(CandidateOutcome)
    Pending
    Stopped(ReductionStop)
    }

    OperationSchedule

    pub struct OperationSchedule[P] {
    // private fields
    }

    Fixed operation order; accepted programs restart the schedule.

    OperationSchedule::new

    fn[P] OperationSchedule::new(operations : Array[(P) -> Array[P]]) -> OperationSchedule[P]

    OperationSchedule::next

    fn[P] OperationSchedule::next(self : OperationSchedule[P]) -> (P) -> Array[P]?

    OperationSchedule::restart

    fn[P] OperationSchedule::restart(self : OperationSchedule[P]) -> Unit

    Reducer

    pub struct Reducer[P] {
    // private fields
    }

    Connects language operations, enumeration, and scheduling to one session.

    Reducer::attempts

    fn[P] Reducer::attempts(self : Reducer[P]) -> Int

    Reducer::new

    fn[P] Reducer::new(initial : P, evidence :
    Assessment
    , predicate :
    FailurePredicate
    , id~ : String, limit~ : Int, better~ : (P, P) -> Bool, valid~ : (P) -> Bool, operations~ : Array[(P) -> Array[P]]) -> Result[Reducer[P], ReductionStartError]

    better(candidate, incumbent) orders programs without interpreting their cost.

    Reducer::next

    fn[P] Reducer::next(self : Reducer[P]) -> ReductionRequest[P]?

    Reducer::observe

    fn[P] Reducer::observe(self : Reducer[P], id : CandidateId, evidence :
    Assessment
    ) -> Bool

    Reducer::result

    fn[P] Reducer::result(self : Reducer[P]) -> P

    Reducer::stop_reason

    fn[P] Reducer::stop_reason(self : Reducer[P]) -> ReductionStop?

    ReductionRequest

    pub(all) struct ReductionRequest[P] {
    id : CandidateId
    program : P
    }

    ReductionSession

    pub struct ReductionSession[P] {
    // private fields
    }

    Strategies own candidate selection; the session owns validation and acceptance.

    ReductionSession::attempts

    fn[P] ReductionSession::attempts(self : ReductionSession[P]) -> Int

    ReductionSession::cancel

    fn[P] ReductionSession::cancel(self : ReductionSession[P]) -> Unit

    ReductionSession::current

    fn[P] ReductionSession::current(self : ReductionSession[P]) -> P

    ReductionSession::events

    fn[P] ReductionSession::events(self : ReductionSession[P]) -> Array[ReductionEvent[P]]

    ReductionSession::evidence

    ReductionSession::finish

    fn[P] ReductionSession::finish(self : ReductionSession[P]) -> Bool

    ReductionSession::new

    fn[P] ReductionSession::new(initial : P, evidence :
    Assessment
    , id~ : String, limit~ : Int, valid~ : (P) -> Bool, accepts~ : (P, P) -> Bool, better~ : (P, P) -> Bool, predicate~ : (
    Assessment
    ) ->
    PredicateStatus
    ) -> Result[ReductionSession[P], ReductionStartError]

    Program values stay immutable; callbacks are pure and deterministic. The caller supplies a unique session id and associates evidence with each request.

    ReductionSession::observe

    Unrelated, duplicate, and cancelled responses cannot consume the pending request.

    ReductionSession::offer

    fn[P] ReductionSession::offer(self : ReductionSession[P], program : P) -> Offer[P]

    ReductionSession::original

    fn[P] ReductionSession::original(self : ReductionSession[P]) -> P

    ReductionSession::pending

    fn[P] ReductionSession::pending(self : ReductionSession[P]) -> ReductionRequest[P]?

    ReductionSession::result

    fn[P] ReductionSession::result(self : ReductionSession[P]) -> P

    ReductionSession::stop_reason

    fn[P] ReductionSession::stop_reason(self : ReductionSession[P]) -> ReductionStop?

    ReductionStartError

    pub(all) enum ReductionStartError {
    InvalidBudget
    InvalidInitial
    UnestablishedFailure(
    PredicateStatus
    )
    } derive(Eq,
    Debug
    )

    ReductionStartError::equal

    ReductionStartError::not_equal

    ReductionStop

    pub(all) enum ReductionStop {
    BudgetExhausted
    Cancelled
    SearchComplete
    } derive(Eq,
    Debug
    )

    ReductionStop::equal

    ReductionStop::not_equal

    fn ReductionStop::not_equal(x : ReductionStop, y : ReductionStop) -> Bool

    comparable_results

    fn comparable_results(configurations : Array[String], observations : Array[
    Observation
    ], normalize~ : (String) -> String?) -> Array[(String, String)]

    Returns every valid normalized result, including those after the first difference.

    compare

    fn compare(configurations : Array[String], observations : Array[
    Observation
    ], normalize~ : (String) -> String?) ->
    Comparison

    Compare successful observations using a language-owned observation protocol. Incomplete configurations cannot hide a difference between valid results.

    difference_predicate

    fn difference_predicate(first : String, second : String) ->
    FailurePredicate

    The oracle identifies the baseline; the configuration identifies its peer.

    differential_assessment

    fn differential_assessment(configurations : Array[String], observations : Array[
    Observation
    ], normalize~ : (String) -> String?) ->
    Assessment

    Retain every planned pair so a different disagreement cannot replace the selected one.

    judge

    fn judge(expected : String, configurations : Array[String], observations : Array[
    Observation
    ]) ->
    Verdict

    A primary verdict for the prototype's report; use reference_assessment for all results.

    reference_assessment

    fn reference_assessment(expected : String, configurations : Array[String], observations : Array[
    Observation
    ]) ->
    Assessment

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io