Skip to content

layout: same model and seed can produce different layouts #633

Closed

Description

@bpowers

Generating a layout twice for the same model with the same random seed can give two different diagrams, in one process or across runs.
The seed exists so that layout is reproducible, and auto-layout picks the best of several seeds, so production output also varied run to run.

Example

Two runs of the layout eval sweep with LAYOUT_EVAL_MODELS=teacup,sir LAYOUT_EVAL_SEEDS=8 gave a SIR median cost of 0.7348 and 0.7071.
Teacup, which is tiny, happened to be stable.

Why it matters

Layout output is not reproducible, and a quality regression gate on layout cost cannot have a stable threshold.

Fix

The suspected cause is iterating Rust HashMap/HashSet, whose order is randomized per instance, in places where order changes the result: summing floating-point positions, and assigning starting angles to auxiliaries by iteration rank.
Iterate in sorted order (or use ordered containers) at those sites, and add a test that the same model and seed give an identical view on repeated calls, for both full and incremental layout.

Pointers

  • src/simlin-engine/src/layout/mod.rs (generate_layout_with_config, the initial-placement loop over var_to_node)
  • src/simlin-engine/src/layout/sfdp.rs, annealing.rs
  • src/simlin-engine/tests/integration/layout.rs (test_layout_deterministic_per_seed, test_incremental_layout_deterministic)

Activity

  1. added 4 commits that reference this issue on May 23, 2026
    36419e4
    38afb57
    360024c
    4754e6c
  2. added
    engine
    layout
    bug
    on Jun 8, 2026
  3. changed the title [-]layout: generate_layout_with_config is nondeterministic per seed (HashMap/HashSet iteration order in force accumulation)[/-] [+]layout: same model and seed can produce different layouts[/+] on Oct 12, 2026
  4. bpowers commented on Oct 12, 2026

    @bpowers
    OwnerAuthor

    Closing: already fixed on main.

    The initial-placement and centroid loops iterate a sorted view of var_to_node (src/simlin-engine/src/layout/mod.rs:1672-1679), with the same treatment in objective.rs:97, incremental.rs:738-742 and isolated-node parking (mod.rs:1451). Pinned by test_layout_deterministic_per_seed and test_incremental_layout_deterministic (src/simlin-engine/tests/integration/layout.rs:2277, 2303), plus branching and ghost determinism tests. The remaining HashMap iterations I read in layout/ (chain.rs:432, mod.rs:1056, incremental.rs:228, 621) are order-insensitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugenginelayout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions