Repository navigation
Remove quadratic scratch from native island discovery - #3396
copybara-service[bot] merged 10 commits into
Conversation
|
I see what you're doing and I think I like it, but I want to do it a bit differently and also measure perf and various things that won't be fun over GH review. Is attribution important to you? If not and it's ok with you, I prefer to do it myself using this PR as a reference. |
|
I see what you're doing and I think I like it, but I want to do it a bit differently and also measure perf and various things that won't be fun over GH review. Is attribution important to you? prefer to do it myself using this PR as a reference. However, if that kind of collaboration isn't possible right now, I completely understand. I would still love to see this feature integrated using this PR as a reference , even without any credits other then reference I will understand . Thank you for your time and the feedback Hope I can catch your eyes few more times hahah !! @yuvaltassa |
|
Ha! Okay I buy that. Let's do a substantive review and I'll do the cosmetic nits myself later.
|
|
I should also add that I expect both implementations to be extremely fast in any reasonable scenario. This is for completeness. But unit test coverage is definitely necessary. |
I’ve settled on a deterministic S²–Vietoris–Rips corpus for the benchmark. |
|
I tried to address both points carefully:
The full island test suite passes 30/30 tests in a fresh WSL2 Release build. This includes empty inputs, activation, path compression, redundant and reversed edges, inactive trees, adversarial chains, deterministic assignment, a 2,000-seed differential test, and the new flex-stiffness island test. For the graph corpus, I used six deterministic S²–Vietoris–Rips families. They represent sparse stable islands, critical bridges, dense components, grounded/static incidences, repeated constraints, and large near-critical graphs. Corpus generation and the independent connected-component oracle are outside the timed region.
Both implementations produced the same independently verified component checksum for every corpus. I also rebased onto the latest branch state and adapted the new flex-stiffness coupling to the DSU union pass. I kept the topology-generation machinery out of the production binary; only the small reproducible corpus generator is part of the benchmark target. I hope this is closer to the level of coverage and evidence you had in mind. I’d appreciate any further corrections or suggestions. |
|
Nice! The benchmark did its job, DSU is not slower. Now that it has convinced us, let's delete it, we don't want to maintain a benchmark comparing production code to an algorithm it no longer uses. Leave mj_floodFill and its existing tests in place. Remaining nits, then I think we're done:
Optionally, the PR description could be much shorter. The memory-scaling table and the bounded-arena test are the whole argument. But I don't care much about that. |
|
I have tried to follow the instructions perfectly hoping we can proceed to merge |
yuvaltassa
left a comment
There was a problem hiding this comment.
will pull this in, perhaps with some minot edits shortly. thanks!
should I now work on the warp implementation of same? |
|
mmm copybara is not happy, I think you need to rebase to head? |
d71edfa to
290513c
Compare
hope this time the Copybara doesnt get angry |
|
should I make a fresh PR with shorter commit using commit290513 with shorter PR description as well cause Copybara import errors are not visible to me |
|
sorry lots of change today, can you try again? |
|
I can edit the commit description, don't worry about it, we just need to make copybara succeed once |
I have no idea how the capybara works :/ what should I do now? |
|
complicated and not interesting, don't worry about it, some sort of code import bot, for our purposes |
|
just rebase on head |
On it boss 🦭 |
Signed-off-by: teerthsharma <teerths57@gmail.com>
Signed-off-by: teerthsharma <teerths57@gmail.com>
Store island topology in `mjData` so repeated island solves can reuse stable connect/weld equality partitions. Add cache invalidation checks for active equality changes and cover the fast path with an island regression test. Signed-off-by: teerthsharma <teerths57@gmail.com>
Signed-off-by: teerthsharma <teerths57@gmail.com>
Signed-off-by: teerthsharma <teerths57@gmail.com>
Signed-off-by: teerthsharma <teerths57@gmail.com>
Signed-off-by: teerthsharma <teerths57@gmail.com>
Signed-off-by: teerthsharma <teerths57@gmail.com>
Signed-off-by: teerthsharma <teerths57@gmail.com>
Signed-off-by: teerthsharma <teerths57@gmail.com>
290513c to
57faf5f
Compare
|
it went through !! anything left which I can help to make sure this merges? |
|
All good. Note I needed to make some minor fixes. You would have caught this if you ran the tests under ASAN. Do you understand what this fixes? |
Yes I do and I won't repeat the mistake again a little rusty with C/cpp |
|
@yuvaltassa thanks for the feedback time and effort it was fun collaborating 🦭 |
Summary
mj_islandcurrently materializes anntree x ntreebyte adjacency matrix and an uncompressedntree x ntreeinteger column array before flood fill. This change computes the same connected-component (H0) partition directly from constraint/tree incidence with a file-local disjoint-set forest.The canonical representative is always the minimum tree index, so island IDs remain deterministic and ascending. Repeated scalar rows retain the existing reuse behavior, flex equality rows are rescanned because their incidence can differ, and
mj_floodFillremains unchanged.This removes the quadratic allocations and the
O(nefc)first-tree scratch from the production path. There is no public API, documented-semantics, persistent-cache, or MuJoCo Warp change.Memory scaling
For the generated singleton family used in #3388, peak
mj_islandstack use changes from5*ntree^2 + 36*ntree + 32bytes to16*ntree + 32bytes:ntreeThe formulas reproduce every measured size exactly. The regression test reverse-validates the failure mode: a 1,024-tree model fails on the dense path in a 2 MiB arena when the 4,194,304-byte column array is requested, and passes unchanged with direct incidence.
Validation
Fresh verification was run from PR head
218b07d7on currentmainat4a03a617in pinned Ubuntu 24.04 containers:libmujoco.so;mjDatachanges.The native parity harness passed 59/59 checks, including 10,000 deterministic generated hypergraphs. Exact island arrays and trajectories matched on 18/18 generated and shipped models; maximum recorded relative error in
qpos,qvel, andqaccwas 0.Native benchmark evidence
The complete paired matrix reported in #3388 used four generated topology families, four tree counts, three scopes, five warmup pairs, and 30 measured pairs per cell. Baseline and candidate benchmark sources were byte-identical, each measured pair had matching complete-output checksums, and intervals use 20,000 deterministic paired-bootstrap resamples at 99% confidence:
mj_islandmj_fwdPositionmj_stepAn independent Callgrind profile at 4,096 trees measured a 6.39x instruction-count ratio in favor of direct incidence. Dense adjacency clearing accounted for 86.7% of current-path instructions in that profile, providing a mechanistic check independent of wall-clock timing.
The timing matrix is synthetic. The direct-stage and scratch-scaling claims are supported; the full-step result is reported as measured context, not as a universal MuJoCo or Warp speedup claim.
Fixes #3388.