Skip to content

nav: scatter_free picks the same cells on every standard library - #1114

Merged
transfix merged 1 commit into
masterfrom
fix/nav-policy-test-macos
Nov 10, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/nav-policy-test-macos

Conversation

@transfix

Copy link
Copy Markdown
Owner

NavSimWorldAgents.EachPolicyDrivesItsOwnAgents failed on package-macos / libcvc-debug (run 42673768122, PR #1086's branch) with pd.pos[2] == po.pos[2] == -5.26315784, on every retry.

Why

sim_world::scatter_free drew its cells with std::uniform_int_distribution, and each standard library chooses its own mapping. I checked the real libraries on one box:

library maps a 32-bit mt19937 draw to [0, n) by
libstdc++ (gcc 13), Linux CI Lemire's multiply-and-reject
MSVC STL 19.44, Windows CI Lemire's multiply-and-reject (identical picks)
libc++ (macOS, and emscripten's for wasm) the low ceil(log2 n) bits, rejected while >= n

So seed 11 built one scene on Linux and Windows and a different one on macOS. With libc++'s draw, agent 1 starts at column 45 and its goal is in column 45 too. It drives straight along -y, so its x stays at exactly -5.2631578 under both policies. Only y differs (5.24 vs 6.50 after 80 ticks). I reproduced this on Windows by emulating libc++'s mapping, and the emulation matches real libc++ draw for draw.

On master, #1095 had already loosened the check to compare every agent's position. That passes on macOS, but it hides the different scene instead of fixing it.

Change

  • sim_world.cpp: pick_below writes out Lemire's mapping, so a seed gives the same scene on every platform. Linux and Windows draws stay bit for bit what they were; macOS and wasm now draw the same scene. The colours stay std::uniform_real_distribution, which takes exactly one draw on all three libraries, so the picks after a colour stay in step.
  • nav_sim_world_test: ScatterFreePicksTheSameCellsOnEveryStandardLibrary pins seed 11's cells on an open 60 x 50 field. libc++'s own draw fails it.
  • nav_sim_world_agents_test: the two policies must now drive agents 1 and 3 to different points, not just make the worlds differ somewhere. The check compares whole points rather than one coordinate, because an agent driving along a column keeps its x.

Tested

  • Windows (MSVC, RelWithDebInfo): nav_sim_world_test 5/5, nav_sim_world_agents_test 17/17, nav_test 64/64, nav_potential_test 17/17, nav_coef_train_test 30/30.
  • pick_below built with emscripten's libc++ gives the same stream as libstdc++'s std::uniform_int_distribution, colour draws included. libc++'s own std stream differs.
  • macOS: this PR's package-macos jobs, which are not required checks.

Not in this PR

The same issue remains in coef_train.cpp's sample_starts_goals, whose macOS-specific divergence the nav_dyn_bike tests' comments describe, and in from_occupancy's clustered std::shuffle, whose algorithm is also unspecified.

NavSimWorldAgents.EachPolicyDrivesItsOwnAgents failed on package-macos with
pd.pos[2] == po.pos[2] == -5.26315784. scatter_free drew its cells with
std::uniform_int_distribution, whose mapping each standard library picks for
itself. libstdc++ and MSVC both use Lemire's multiply-and-reject on a 32-bit
draw, so they agree. libc++ masks the low ceil(log2 n) bits and rejects. With
seed 11, libc++ gave agent 1 a start and a goal in one column (45), so it drove
straight along -y and its x stayed at -5.2631578 under both policies. Only y
differed. #1095 loosened the check to the whole world's positions, which hid
the different scene rather than fixing it.

- sim_world.cpp: pick_below writes out Lemire's mapping, so a seed is one scene
  on every platform: the one Linux and Windows always drew. Their worlds are
  unchanged bit for bit; macOS and wasm (libc++) now draw them too. The colours
  stay std::uniform_real_distribution: it takes one draw on each library, so
  the picks after it stay in step.
- nav_sim_world_test: ScatterFreePicksTheSameCellsOnEveryStandardLibrary pins
  seed 11's cells on an open field.
- nav_sim_world_agents_test: the policies must drive agents 1 and 3 to
  different points, not merely to different whole worlds. A point, not one
  coordinate, since an agent driving along a column keeps its x.
@transfix
transfix merged commit 44ff113 into master Nov 10, 2026
30 checks passed
@transfix
transfix deleted the fix/nav-policy-test-macos branch November 10, 2026 07:16
transfix added a commit that referenced this pull request Nov 10, 2026
#1114 landed as 44ff113. Its scatter_free hunk and the test after
ScatterFreePicksTheSameCellsOnEveryStandardLibrary conflicted with this
branch, which moves pick_below into detail/seeded_draw.h: kept this
branch's side and dropped the local pick_below the merge brought back.
transfix added a commit that referenced this pull request Nov 10, 2026
The two conflicts (sim_world.cpp's scatter_free picks, nav_sim_world_test.cpp's tests after
ScatterFreePicksTheSameCellsOnEveryStandardLibrary) are #1114's lines against #1118's rewrite of
them. #1114's squash is its commit 79e05d4 unchanged, so they keep #1118's side.
transfix added a commit that referenced this pull request Nov 10, 2026
…rary (#1114), seabed damping (#1127)

One conflict, in ci.yml's sanitizer test list: this branch's stream_test,
net_ws_client_test and ariadne_host_test, and master's param_table_test, all
kept.
transfix added a commit that referenced this pull request Nov 11, 2026
…every standard library (#1118)

* nav: scatter_free picks the same cells on every standard library

NavSimWorldAgents.EachPolicyDrivesItsOwnAgents failed on package-macos with
pd.pos[2] == po.pos[2] == -5.26315784. scatter_free drew its cells with
std::uniform_int_distribution, whose mapping each standard library picks for
itself. libstdc++ and MSVC both use Lemire's multiply-and-reject on a 32-bit
draw, so they agree. libc++ masks the low ceil(log2 n) bits and rejects. With
seed 11, libc++ gave agent 1 a start and a goal in one column (45), so it drove
straight along -y and its x stayed at -5.2631578 under both policies. Only y
differed. #1095 loosened the check to the whole world's positions, which hid
the different scene rather than fixing it.

- sim_world.cpp: pick_below writes out Lemire's mapping, so a seed is one scene
  on every platform: the one Linux and Windows always drew. Their worlds are
  unchanged bit for bit; macOS and wasm (libc++) now draw them too. The colours
  stay std::uniform_real_distribution: it takes one draw on each library, so
  the picks after it stay in step.
- nav_sim_world_test: ScatterFreePicksTheSameCellsOnEveryStandardLibrary pins
  seed 11's cells on an open field.
- nav_sim_world_agents_test: the policies must drive agents 1 and 3 to
  different points, not merely to different whole worlds. A point, not one
  coordinate, since an agent driving along a column keeps its x.

* nav: sample_starts_goals and from_occupancy's groups are the same on every standard library

The rest of cvc::nav's seeded draws, written out the way #1114 wrote out scatter_free's.

- detail/seeded_draw.h: pick_below (#1114's Lemire multiply and reject, moved out of
  sim_world.cpp and shared) and seeded_shuffle.
- training_scene::sample_starts_goals: its three picks (goals anywhere, starts with a clearance,
  local goals) are pick_below. libstdc++ and MSVC map a 32-bit draw this way already, so Linux and
  Windows draw the routes they always drew; macOS and wasm (libc++, low bits and reject) now draw
  them too.
- sim_world::from_occupancy, clustered: the k-means centres come from seeded_shuffle instead of
  std::shuffle. The three libraries all shuffle differently: libstdc++ takes two swaps from one
  Lemire draw while n * n fits in 32 bits, MSVC's std::shuffle maps each draw by its remainder
  (its older _Rng_from_urng, not uniform_int_distribution's Lemire), and libc++ swaps from the
  other end. seeded_shuffle is libstdc++'s written out, so Linux keeps its groups and Windows,
  macOS and wasm change: on the pinned field (twelve agents, three groups) MSVC's shuffle gave 34
  of 40 seeds other groups.

Checked against the libraries themselves with one program built by MSVC 19.44, g++ 13.2
(libstdc++) and em++ 21 (libc++, run under node): pick_below matches uniform_int_distribution<int>
on libstdc++ and MSVC for every case (230000 picks, n from 1 to INT_MAX, the draw streams in
step), seeded_shuffle matches libstdc++'s std::shuffle for every case (n up to 70001), and the
written-out draws hash the same under all three.

Tests:
- NavCoefTrain.StartsAndGoalsAreTheSameOnEveryStandardLibrary pins seed 7's cells in each of the
  three ways on a 40 x 30 field with a wall. libc++'s own draw began {19, 4, 31, 13}. The clearance
  and the goal range sit at least 0.019 from every cell's square-root distance, so rounding moves
  no cell in or out.
- NavSimWorld.ClusteredGroupsAreTheSameOnEveryStandardLibrary pins seed 20's groups of twelve;
  each agent is at least 15% nearer (squared) its own centre than the next at every step.
- NavSimWorld.SeededShuffleIsTheSameOnEveryStandardLibrary pins odd, even and past-paired lengths.

The gates loosened because macOS drew other routes:
- DynBike.KinematicLimitFollowsBikeStep: the open-loop gap is gated at 0.1 rr again (#717 had
  moved it to 0.2 rr because each library drew other routes). It is 0.0107 on these routes, the
  same with the test compiled /fp:contract /arch:AVX2, which contracts its arithmetic to about
  1260 fused multiply-adds as clang does on arm64. The closed-loop worst agent stays reported, not
  gated: on these same routes it parts by 1.80 normally and by 0.017 with the fused arithmetic,
  while the medians barely move (0.00045 / 0.17% against 0.00032 / 0.13%).
- DiffExtForce / DiffExtRollout and the four-wheel ext checks keep their switch filter and
  quotas: the shared draws still put one to five cases on a switch, and the quotas were set over
  100 swept seeds, not per library. Their comments, and NAV_TRAINING.md, no longer say the draws
  differ by library.

Windows (MSVC, RelWithDebInfo): nav_sim_world 7/7, nav_sim_world_agents 17/17, nav_coef_train
31/31, nav_dyn_bike 23/23, nav_dyn_4w 23/23, nav_potential 17/17, nav 64/64. Every pre-existing
test's output is identical to the base commit's, number for number.

* ci: room_calls.cpp's process-wide objects on the writable-data scan's allowlist

#1122 (room-call) added src/cvc/ariadne/conference/room_calls.cpp to
libcvc. Its CI ran on a base from before #1107, so the scan never saw it,
and every PR based on master now fails the package-linux scan step on its
seven objects: the per-app client map clients() and its mutex, the
once-per-app list in register_room_call_intrinsics and its mutex, and the
message counter g_messages (like room_lane.cpp's g_lane_messages).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant