Skip to documentation
SLOP

tiny.pluck.toplevel.config

Reference tiny.pluck toplevel config

Defined in toplevel.

API (15)

Actions

Public operations.

Types and contracts

Public types and contracts.

No direct callersNo direct callstoplevelconfig
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsNo direct callsprivate sourcelib.pluck.src.toplevel.configapplyOptionaltoplevel.configOptionalField
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallstest sourcelib.pluck.src.toplevel.configtest: config patch sets and clears em...test sourcelib.pluck.src.toplevel.configtest: config patch validates bounded ...test sourcelib.pluck.src.toplevel.configtest: toplevel config defaults to the...toplevel.configpatchedtoplevel.configapplyPatch
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsprivate sourcelib.pluck.src.toplevel.configapplyPatchInPlacetoplevel.configapplyVarOrderSetting
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstoplevel.configapplyPatchprivate sourcelib.pluck.src.toplevel.configapplyPatchInPlacetoplevel.configpatched
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/pluck/src/toplevel/config.zig

zig
const std = @import("std");const pluck = @import("../root.zig");const evaluator = pluck.evaluator;const LazyKCConfig = evaluator.LazyKCConfig;const LimitReason = evaluator.LimitReason;const def_order = pluck.definition_order;const DefinitionOrderMode = def_order.DefinitionOrderMode;const limits = pluck.limits;pub const ConfigError = error{    InvalidTimeLimit,    InvalidFallbackK,    InvalidAdaptiveKMax,    InvalidWorkerCount,};pub const ToplevelConfig = struct {    max_depth: ?u32 = null,    ite_limit: ?u64 = limits.default_agent_ite_limit,    time_limit: ?f64 = null,    sample_after_max_depth: bool = false,    use_strict_order: bool = true,    use_reverse_order: bool = false,    var_order_fallback: bool = false,    definition_order_mode: DefinitionOrderMode = .none,    parallel_wmc: bool = false,    verbose: bool = false,    rng_seed: ?u64 = null,    lpsmc_rng_seed: ?u64 = null,    lpsmc_adaptive_k: bool = false,    lpsmc_adaptive_k_max: usize = 64,    lpsmc_workers: usize = 1,    factor_max_branches: usize = 64,    weight_dd_max_nodes: usize = 0,    fallback_mode: evaluator.FallbackMode = .@"error",    fallback_lpsmc_k: usize = 10,};pub fn OptionalField(comptime T: type) type {    return union(enum) {        keep,        set: T,        clear,    };}pub const VarOrderSetting = enum {    strict,    reverse,    creation,    topo,    min_fill,    auto,};pub const ToplevelConfigPatch = struct {    max_depth: OptionalField(u32) = .keep,    ite_limit: OptionalField(u64) = .keep,    time_limit: OptionalField(f64) = .keep,    sample_after_max_depth: ?bool = null,    var_order: ?VarOrderSetting = null,    parallel_wmc: ?bool = null,    verbose: ?bool = null,    rng_seed: OptionalField(u64) = .keep,    lpsmc_rng_seed: OptionalField(u64) = .keep,    lpsmc_adaptive_k: ?bool = null,    lpsmc_adaptive_k_max: ?usize = null,    lpsmc_workers: ?usize = null,    factor_max_branches: ?usize = null,    weight_dd_max_nodes: ?usize = null,    fallback_mode: ?evaluator.FallbackMode = null,    fallback_lpsmc_k: ?usize = null,};pub fn patched(base: ToplevelConfig, patch: ToplevelConfigPatch) ConfigError!ToplevelConfig {    var next = base;    try applyPatchInPlace(&next, patch);    return next;}pub fn applyPatch(config: *ToplevelConfig, patch: ToplevelConfigPatch) ConfigError!void {    config.* = try patched(config.*, patch);}fn applyPatchInPlace(config: *ToplevelConfig, patch: ToplevelConfigPatch) ConfigError!void {    applyOptional(u32, &config.max_depth, patch.max_depth);    applyOptional(u64, &config.ite_limit, patch.ite_limit);    switch (patch.time_limit) {        .keep => {},        .clear => config.time_limit = null,        .set => |seconds| {            if (!std.math.isFinite(seconds) or seconds < 0) return ConfigError.InvalidTimeLimit;            config.time_limit = seconds;        },    }    if (patch.sample_after_max_depth) |value| config.sample_after_max_depth = value;    if (patch.var_order) |setting| applyVarOrderSetting(config, setting);    if (patch.parallel_wmc) |value| config.parallel_wmc = value;    if (patch.verbose) |value| config.verbose = value;    applyOptional(u64, &config.rng_seed, patch.rng_seed);    applyOptional(u64, &config.lpsmc_rng_seed, patch.lpsmc_rng_seed);    if (patch.lpsmc_adaptive_k) |value| config.lpsmc_adaptive_k = value;    if (patch.lpsmc_adaptive_k_max) |value| {        if (value == 0) return ConfigError.InvalidAdaptiveKMax;        config.lpsmc_adaptive_k_max = value;    }    if (patch.lpsmc_workers) |value| {        if (value == 0) return ConfigError.InvalidWorkerCount;        config.lpsmc_workers = value;    }    if (patch.factor_max_branches) |value| config.factor_max_branches = value;    if (patch.weight_dd_max_nodes) |value| config.weight_dd_max_nodes = value;    if (patch.fallback_mode) |value| config.fallback_mode = value;    if (patch.fallback_lpsmc_k) |value| {        if (value == 0) return ConfigError.InvalidFallbackK;        config.fallback_lpsmc_k = value;    }}fn applyOptional(comptime T: type, target: *?T, patch: OptionalField(T)) void {    switch (patch) {        .keep => {},        .clear => target.* = null,        .set => |value| target.* = value,    }}pub fn applyVarOrderSetting(config: *ToplevelConfig, setting: VarOrderSetting) void {    switch (setting) {        .strict => {            config.use_strict_order = true;            config.use_reverse_order = false;            config.var_order_fallback = false;            config.definition_order_mode = .none;        },        .reverse => {            config.use_strict_order = true;            config.use_reverse_order = true;            config.var_order_fallback = false;            config.definition_order_mode = .none;        },        .creation => {            config.use_strict_order = false;            config.use_reverse_order = false;            config.var_order_fallback = false;            config.definition_order_mode = .none;        },        .topo => {            config.use_strict_order = true;            config.use_reverse_order = false;            config.var_order_fallback = false;            config.definition_order_mode = .topological;        },        .min_fill => {            config.use_strict_order = true;            config.use_reverse_order = false;            config.var_order_fallback = false;            config.definition_order_mode = .min_fill;        },        .auto => {            config.use_strict_order = true;            config.use_reverse_order = false;            config.var_order_fallback = true;            config.definition_order_mode = .none;        },    }}pub const VarOrderMode = enum {    strict,    reverse,    creation,};pub const VarOrderCandidates = struct {    modes: [3]VarOrderMode,    len: u8,};pub fn varOrderModeFromConfig(config: ToplevelConfig) VarOrderMode {    if (!config.use_strict_order) return .creation;    return if (config.use_reverse_order) .reverse else .strict;}pub fn applyVarOrder(cfg: *LazyKCConfig, mode: VarOrderMode) void {    switch (mode) {        .strict => {            cfg.use_strict_order = true;            cfg.use_reverse_order = false;        },        .reverse => {            cfg.use_strict_order = true;            cfg.use_reverse_order = true;        },        .creation => {            cfg.use_strict_order = false;            cfg.use_reverse_order = false;        },    }}pub fn buildVarOrderCandidates(current: VarOrderMode, enable_fallback: bool) VarOrderCandidates {    var candidates = VarOrderCandidates{        .modes = .{ current, .strict, .strict },        .len = 1,    };    if (!enable_fallback) return candidates;    switch (current) {        .strict => {            candidates.modes[1] = .reverse;            candidates.modes[2] = .creation;        },        .reverse => {            candidates.modes[1] = .strict;            candidates.modes[2] = .creation;        },        .creation => {            candidates.modes[1] = .strict;            candidates.modes[2] = .reverse;        },    }    candidates.len = 3;    return candidates;}pub fn buildAdaptiveKPolicy(config: ToplevelConfig, base_k: usize) evaluator.AdaptiveKPolicy {    var policy = evaluator.AdaptiveKPolicy{};    policy.enabled = config.lpsmc_adaptive_k;    if (policy.enabled) {        policy.min_k = @max(base_k, 1);    }    policy.max_k = @max(policy.min_k, config.lpsmc_adaptive_k_max);    return policy;}pub fn shouldFallbackVarOrder(reason: LimitReason) bool {    return reason == .time_limit or reason == .ite_limit;}test "toplevel config defaults to the agent BDD quota and can clear it" {    var cfg = ToplevelConfig{};    try std.testing.expectEqual(@as(?u64, limits.default_agent_ite_limit), cfg.ite_limit);    try applyPatch(&cfg, .{ .ite_limit = .clear });    try std.testing.expect(cfg.ite_limit == null);}test "config patch sets and clears embedding fields" {    var cfg = ToplevelConfig{};    try applyPatch(&cfg, .{        .max_depth = .{ .set = 12 },        .time_limit = .{ .set = 0.25 },        .rng_seed = .{ .set = 42 },        .var_order = .min_fill,        .fallback_mode = .lpsmc,        .fallback_lpsmc_k = 7,    });    try std.testing.expectEqual(@as(?u32, 12), cfg.max_depth);    try std.testing.expectEqual(@as(?f64, 0.25), cfg.time_limit);    try std.testing.expectEqual(@as(?u64, 42), cfg.rng_seed);    try std.testing.expect(cfg.use_strict_order);    try std.testing.expect(!cfg.use_reverse_order);    try std.testing.expect(!cfg.var_order_fallback);    try std.testing.expectEqual(DefinitionOrderMode.min_fill, cfg.definition_order_mode);    try std.testing.expectEqual(evaluator.FallbackMode.lpsmc, cfg.fallback_mode);    try std.testing.expectEqual(@as(usize, 7), cfg.fallback_lpsmc_k);    try applyPatch(&cfg, .{        .max_depth = .clear,        .time_limit = .clear,        .rng_seed = .clear,        .var_order = .creation,    });    try std.testing.expect(cfg.max_depth == null);    try std.testing.expect(cfg.time_limit == null);    try std.testing.expect(cfg.rng_seed == null);    try std.testing.expect(!cfg.use_strict_order);    try std.testing.expect(!cfg.use_reverse_order);}test "config patch validates bounded fields" {    var cfg = ToplevelConfig{};    cfg.max_depth = 9;    try std.testing.expectError(ConfigError.InvalidTimeLimit, applyPatch(&cfg, .{ .time_limit = .{ .set = -1 } }));    try std.testing.expectEqual(@as(?u32, 9), cfg.max_depth);    try std.testing.expectError(ConfigError.InvalidFallbackK, applyPatch(&cfg, .{ .fallback_lpsmc_k = 0 }));    try std.testing.expectError(ConfigError.InvalidAdaptiveKMax, applyPatch(&cfg, .{ .lpsmc_adaptive_k_max = 0 }));    try std.testing.expectError(ConfigError.InvalidWorkerCount, applyPatch(&cfg, .{ .lpsmc_workers = 0 }));}

Source: lib/pluck/src/toplevel/root.zig:4

zig
pub const config = @import("config.zig");

Audit

Definitions16
Public names20
Members50
Version26.7.0
Revisiondaab053ee433