Skip to content

planner_study.planner_verify

planner_verify

External path-optimality verification for the distilled L2 planners. Loads a planner .eqx, builds field() on maps from generators OUTSIDE our env generator, greedy value-ascent, compares to BFS optimum. Metrics = GPPN/VIN standard (%Success, %Optimal).

rollout

rollout(V, wall, start, goal, cap)

greedy value-ascent; returns (reached, steps).

Source code in experiments/planner_study/planner_verify.py
34
35
36
37
38
39
40
41
42
43
44
45
46
def rollout(V, wall, start, goal, cap):
    """greedy value-ascent; returns (reached, steps)."""
    H,W = wall.shape; cr,cc = start; steps = 0; seen = set()
    while (cr,cc) != goal:
        if steps > cap or (cr,cc) in seen: return False, steps
        seen.add((cr,cc)); best=None; bv=-1e18
        for dr,dc in DIRS4:
            nr,nc = cr+dr,cc+dc
            if 0<=nr<H and 0<=nc<W and not wall[nr,nc] and V[nr,nc] > bv:
                bv = V[nr,nc]; best = (nr,nc)
        if best is None: return False, steps
        cr,cc = best; steps += 1
    return True, steps

eval_map

eval_map(Vfn, wall, goal, dstar)

Vfn: (wall,goal)->V. returns dict of counts + per-distance-bin success/optimal + action-acc.

Source code in experiments/planner_study/planner_verify.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def eval_map(Vfn, wall, goal, dstar):
    """Vfn: (wall,goal)->V. returns dict of counts + per-distance-bin success/optimal + action-acc."""
    H,W = wall.shape; V = Vfn(wall, goal)
    reach = (dstar < (1<<30)) & (~wall); cap = 4*H*W
    tot=succ=opt=acc=accn=0; bins={"d<=16":[0,0,0],"16<d<=32":[0,0,0],"d>32":[0,0,0]}
    for r in range(H):
        for c in range(W):
            if not reach[r,c] or (r,c)==goal: continue
            tot += 1; dd = int(dstar[r,c])
            # per-cell action accuracy: does argmax-V neighbour reduce d* by 1?
            best=None; bv=-1e18
            for dr,dc in DIRS4:
                nr,nc=r+dr,c+dc
                if 0<=nr<H and 0<=nc<W and not wall[nr,nc] and V[nr,nc]>bv: bv=V[nr,nc]; best=(nr,nc)
            accn += 1
            if best is not None and dstar[best] == dd-1: acc += 1
            ok, st = rollout(V, wall, (r,c), goal, cap)
            b = "d<=16" if dd<=16 else ("16<d<=32" if dd<=32 else "d>32")
            bins[b][2]+=1
            if ok:
                succ += 1; bins[b][0]+=1
                if st == dd: opt += 1; bins[b][1]+=1
    return dict(tot=tot, succ=succ, opt=opt, acc=acc, accn=accn, bins=bins)

maze_backtracker

maze_backtracker(H, W, seed)

recursive-backtracker perfect maze; walls=True, corridors width 1.

Source code in experiments/planner_study/planner_verify.py
74
75
76
77
78
79
80
81
82
83
84
85
86
def maze_backtracker(H, W, seed):
    """recursive-backtracker perfect maze; walls=True, corridors width 1."""
    r = rng(seed); h = (H//2)*2+1; w = (W//2)*2+1; g = np.ones((h,w), bool)  # all wall
    sr,sc = 0,0; stack=[(0,0)]; g[1,1]=False; cur=(1,1); stack=[cur]
    while stack:
        cr,cc = stack[-1]; nbrs=[]
        for dr,dc in ((-2,0),(2,0),(0,-2),(0,2)):
            nr,nc=cr+dr,cc+dc
            if 1<=nr<h-1 and 1<=nc<w-1 and g[nr,nc]: nbrs.append((nr,nc,dr,dc))
        if not nbrs: stack.pop(); continue
        nr,nc,dr,dc = nbrs[r.integers(len(nbrs))]
        g[cr+dr//2, cc+dc//2]=False; g[nr,nc]=False; stack.append((nr,nc))
    return g[:H,:W]

rollout_true

rollout_true(V, truewall, start, goal, cap)

greedy value-ascent on V but MOVEMENT restricted to TRUE-free cells (plan on belief, execute on truth). Stuck at an unknown wall / loop -> fail.

Source code in experiments/planner_study/planner_verify.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def rollout_true(V, truewall, start, goal, cap):
    """greedy value-ascent on V but MOVEMENT restricted to TRUE-free cells (plan on belief,
    execute on truth). Stuck at an unknown wall / loop -> fail."""
    H,W = truewall.shape; cr,cc = start; steps=0; seen=set()
    while (cr,cc) != goal:
        if steps>cap or (cr,cc) in seen: return False
        seen.add((cr,cc)); best=None; bv=-1e18
        for dr,dc in DIRS4:
            nr,nc = cr+dr,cc+dc
            if 0<=nr<H and 0<=nc<W and not truewall[nr,nc] and V[nr,nc] > bv:
                bv = V[nr,nc]; best = (nr,nc)
        if best is None: return False
        cr,cc = best; steps += 1
    return True