Repository navigation
nav: scatter_free picks the same cells on every standard library - #1114
Merged
Merged
Conversation
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.
This was referenced Nov 10, 2026
Merged
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NavSimWorldAgents.EachPolicyDrivesItsOwnAgentsfailed onpackage-macos / libcvc-debug(run 42673768122, PR #1086's branch) withpd.pos[2] == po.pos[2] == -5.26315784, on every retry.Why
sim_world::scatter_freedrew its cells withstd::uniform_int_distribution, and each standard library chooses its own mapping. I checked the real libraries on one box:mt19937draw to[0, n)bySo 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_belowwrites 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 staystd::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:ScatterFreePicksTheSameCellsOnEveryStandardLibrarypins 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
nav_sim_world_test5/5,nav_sim_world_agents_test17/17,nav_test64/64,nav_potential_test17/17,nav_coef_train_test30/30.pick_belowbuilt with emscripten's libc++ gives the same stream as libstdc++'sstd::uniform_int_distribution, colour draws included. libc++'s ownstdstream differs.package-macosjobs, which are not required checks.Not in this PR
The same issue remains in
coef_train.cpp'ssample_starts_goals, whose macOS-specific divergence the nav_dyn_bike tests' comments describe, and infrom_occupancy's clusteredstd::shuffle, whose algorithm is also unspecified.