Minor fixes to viewer diagnostics

- When `mjData.nefc` was 0 (solver not run at all), we were plotting the stale diagnostics from the last run; now fixed.
- In the case where islands were used, the semantic of the plotted diagnostic `sqrt_nnz` (square root of Hessian nonzeros) is changed. It used to be the sum of square roots of solver nonzeros per island, it is now the square root of the sum of all nonzeros in all islands. The semantic `sqrt(sum(nnz_i))` was found to be more consistent than `sum(sqrt(nnz_i))`, in the sense that switching islanding on/off leads to smaller changes and is more in line with the interpretation of islanding as [block-diagonalization](https://mujoco.readthedocs.io/en/3.3.7/computation/#constraint-islands).

PiperOrigin-RevId: 827624908
Change-Id: I5fc86364ead585a4752a6d44823fb75cf6c7c318
This commit is contained in:
Yuval Tassa
2025-11-03 13:21:59 -08:00
committed by Copybara-Service
parent 501e561563
commit abc02b736e
2 changed files with 8 additions and 6 deletions
+3 -2
View File
@@ -299,7 +299,7 @@ void UpdateProfiler(mj::Simulate* sim, const mjModel* m, const mjData* d) {
memset(sim->figcost.linepnt, 0, mjMAXLINE*sizeof(int));
// number of islands that have diagnostics
int nisland = mjMAX(1, mjMIN(d->nisland, mjNISLAND));
int nisland = d->nefc ? mjMAX(1, mjMIN(d->nisland, mjNISLAND)) : 0;
// iterate over islands
for (int k=0; k < nisland; k++) {
@@ -403,9 +403,10 @@ void UpdateProfiler(mj::Simulate* sim, const mjModel* m, const mjData* d) {
mjtNum sqrt_nnz = 0;
int solver_niter = 0;
for (int island=0; island < nisland; island++) {
sqrt_nnz += mju_sqrt(d->solver_nnz[island]);
sqrt_nnz += d->solver_nnz[island];
solver_niter += d->solver_niter[island];
}
sqrt_nnz = mju_sqrt(sqrt_nnz);
// get sizes: nv, nbody, nefc, sqrt(nnz), ncont, iter
float sdata[6] = {