exp+fix: 候选塌缩定案(steps=2 把K条候选抹平35倍)+z_scale反例;补 n_plans/brake_rate 核算§9.2刹停率;记录我在链式作业排队期间改库导致两臂未跑的事故

This commit is contained in:
cbb
2026-10-20 22:48:51 +08:00
parent 4597569dd8
commit b30c271896
5 changed files with 130 additions and 1 deletions
+4 -1
View File
@@ -54,6 +54,9 @@ def run(model, kin, tasks, device, bs=256, **kw):
out.update({'reverse_p50': median(rr), 'reverse_mean': rr.mean().item(),
'reverse_moving_p50': median(flat['reverse_rate_moving']), # 只在动了的步上算,不被刹停稀释
'moving_share_p50': median(flat['moving_share'])}) # 活动窗内动了的步占比(=1−站住比例)
if 'brake_rate' in flat: # §9.2 判据是"刹停 <2% 推理周期",所以要按规划次数归一,不能只报绝对次数
out.update({'brake_rate_mean': flat['brake_rate'].mean().item(), 'brake_rate_p50': median(flat['brake_rate']),
'n_plans_mean': flat['n_plans'].mean().item()})
if 'backoff' in flat and flat['backoff'].any(): # backoff=缩步顶上的次数;brakes 现在只记连最小档都不安全的
out['backoff_mean'] = flat['backoff'].mean().item() # ⇒ 原来的"全拒"事件数 = 两者之和
out['reject_all_mean'] = (flat['backoff'] + flat['brakes']).mean().item()
@@ -139,7 +142,7 @@ def main():
Path(a.out).write_text(json.dumps(json_finite(result), indent=2, ensure_ascii=False, allow_nan=False) + '\n', encoding='utf-8')
if a.dump:
rows = []
keys = ['done', 'ok', 't_done', 'limit', 'col', 'brakes', 'err', 'first_hit', 'dls_it', 'goal_ratio_2s']
keys = ['done', 'ok', 't_done', 'limit', 'col', 'brakes', 'err', 'first_hit', 'dls_it', 'goal_ratio_2s', 'brake_rate', 'n_plans']
flat = {k: torch.cat([p[k] for _, p, _ in pers]).tolist() for k in keys}
for i, t in enumerate(tasks):
rows.append({**t, 'i': i, **{k: flat[k][i] for k in keys}})
+3
View File
@@ -204,6 +204,7 @@ def rollout(model, kin, tasks, device, K=8, safety=False, seed=0, max_sec=None,
vratio = torch.zeros(B, device=device); aratio = torch.zeros(B, device=device); prev_exec = torch.zeros(B, 6, device=device)
rev = torch.zeros(B, device=device); nact = torch.zeros(B, device=device); prev_sgn = torch.zeros(B, 6, device=device)
nmov = torch.zeros(B, device=device)
nplan = torch.zeros(B, device=device) # 每题规划次数 = 推理周期数(§9.2 的"刹停 <2% 推理周期"要这个分母)
traj = [q.clone()] if return_traj else None
plans = {k: [] for k in ('it', 'r', 'qe', 'commit', 'points', 'midpoints', 'gaps', 'certified')} if return_traj else None
n_start = int(round(0.5 / DT)); moved_start = None # R2 起步失败:0.5 s 内关节总行程 < 1°
@@ -216,6 +217,7 @@ def rollout(model, kin, tasks, device, K=8, safety=False, seed=0, max_sec=None,
for it in range(nmax):
tnow = it * DT
if (queue.shape[1] <= 3) if replan == 'r3' else (queue.shape[1] == 0):
nplan += 1.0 # 验收判据要"刹停 / 推理周期"的比值,分母就是这个(批内所有行同步规划)
r = queue.shape[1]
pre = torch.zeros(B, 3, 6, device=device)
qe = q
@@ -513,6 +515,7 @@ def rollout(model, kin, tasks, device, K=8, safety=False, seed=0, max_sec=None,
side = torch.where(j1_first != 0, j1_first, torch.where(j1_max >= -j1_min, torch.ones_like(j1_max), -torch.ones_like(j1_max)))
per = {'done': done.cpu(), 'ok': ok.cpu(), 't_done': t_done.cpu(), 'limit': limit.cpu(), 'col': col.cpu(), 'travel': travel.cpu(), 'err': e_end.cpu(),
'side': side.cpu(), 'start_fail': start_fail.cpu(), 'brakes': brakes.cpu(), 'backoff': bo.cpu(), 'first_hit': first_hit.cpu(), 'dls_it': dls_it.cpu(),
'n_plans': nplan.cpu(), 'brake_rate': (brakes / nplan.clamp_min(1.0)).cpu(),
'goal_ratio_2s': ratio2.cpu(), 'speed_ratio': vratio.cpu(), 'accel_ratio': aratio.cpu(),
# 口径与离线分解一致:换向的 (步,轴) 对数 / 活动的 (步,轴) 对数 ∈ [0,1](除以 6 个轴)
'reverse_rate': (rev / (6.0 * nact.clamp_min(1.0))).cpu(),