Skip to content

Add tiled camera scene to model build benchmark - #3812

Open
StafaH wants to merge 5 commits into
newton-physics:mainfrom
StafaH:mh/model_build_bench
Open

Add tiled camera scene to model build benchmark#3812
StafaH wants to merge 5 commits into
newton-physics:mainfrom
StafaH:mh/model_build_bench

Conversation

@StafaH

@StafaH StafaH commented Aug 6, 2026

Copy link
Copy Markdown
Member

Description

Add two additional scenes for model initialization benchmarks that include a tiled camera sensor and collision handling.

Checklist

  • New or existing tests cover these changes
  • The documentation is up to date with these changes
  • For user-facing changes, a fragment has been added by following the
    changelog fragment instructions

Summary by CodeRabbit

  • New Features
    • Added benchmark coverage for initializing tiled-camera simulation scenes.
    • Added KPI and fast benchmark variants for Franka cabinet and quadruped scenes, supporting 4,096 and 256 simulated worlds.
    • Benchmarks now measure initialization and finalization separately, including warmup and cleanup steps.
    • Added benchmark command-line entries for running both performance tiers consistently.
    • Included synchronized timing to improve the reliability and consistency of performance results.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: c29d87de-535d-4811-88c8-2b361412ae62

📥 Commits

Reviewing files that changed from the base of the PR and between 9eb9219 and 1f5ed45.

📒 Files selected for processing (1)
  • asv/benchmarks/setup/bench_model.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • asv/benchmarks/setup/bench_model.py

📝 Walkthrough

Walkthrough

The benchmark setup adds tiled-camera model initialization benchmarks. The shared implementation measures replication, initialization, and finalization for replicated scenes. KPI and fast variants use different world counts and are registered in the benchmark CLI.

Changes

Tiled-camera model initialization benchmarks

Layer / File(s) Summary
Tiled-camera benchmark implementation
asv/benchmarks/setup/bench_model.py
The benchmark imports tiled-camera scene definitions and Newton, builds and replicates scenes, warms up finalization, measures initialization and finalization separately with CUDA synchronization, and cleans up state.
Benchmark variants and CLI registration
asv/benchmarks/setup/bench_model.py
The KPI variant uses 4096 worlds with a 3600-second timeout. The fast variant uses 256 worlds. Both variants are registered in the benchmark command map.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TiledCameraBenchmark
  participant SensorTiledCamera
  participant Newton
  participant CUDA
  TiledCameraBenchmark->>SensorTiledCamera: Build and finalize tiled-camera scenes
  TiledCameraBenchmark->>Newton: Replicate and initialize model
  TiledCameraBenchmark->>Newton: Finalize model
  Newton->>CUDA: Execute timed operations
  CUDA-->>TiledCameraBenchmark: Return synchronized timings
  TiledCameraBenchmark->>Newton: Release replicated builder and scene state
Loading

Suggested reviewers: adenzler-nvidia

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding a tiled camera scene to the model build benchmark.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@asv/benchmarks/setup/bench_model.py`:
- Around line 123-125: Update the warmup model construction around
newton.ModelBuilder and the warmup replication call to use the same
_replicate(1) path as the timed benchmark variations, ensuring the global ground
plane is included before finalize().
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 88c51276-7888-4cc0-879b-e2748714f4bf

📥 Commits

Reviewing files that changed from the base of the PR and between 05ca05a and bfcc505.

📒 Files selected for processing (1)
  • asv/benchmarks/setup/bench_model.py

Comment thread asv/benchmarks/setup/bench_model.py Outdated
Comment on lines +123 to +125
warmup = newton.ModelBuilder()
warmup.replicate(self.world, 1)
warmup.finalize()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 8 'def finalize\(|add_ground_plane|shape.*plane|collision' newton/_src/sim/builder.py
rg -n -C 6 'warmup|_replicate|add_ground_plane|time_initialize_model|time_finalize_model' \
  asv/benchmarks/setup/bench_model.py

Repository: newton-physics/newton

Length of output: 50378


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the ASV benchmark file around the relevant methods.
rg -n -C 12 'class TiledCamera|_replicate|warmup|add_ground_plane|def run|TWO|FAST' asv/benchmarks/setup/bench_model.py

# Look at ModelBuilder.finalize implementation and ground-plane shape model fields without outputting the whole file.
rg -n -C 16 'def finalize\(|def add_ground_plane|_add_body|shape_.*plane|plane.*shape|ground_plane|contact' newton/_src/sim/builder.py | sed -n '1,260p'

Repository: newton-physics/newton

Length of output: 15778


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the exact finalize and add_ground_plane implementations.
rg -n 'def finalize\(|def add_ground_plane\(' newton/_src/sim/builder.py
finalize_line=$(rg -n 'def finalize\(' newton/_src/sim/builder.py | head -n1 | cut -d: -f1)
ground_line=$(rg -n 'def add_ground_plane\(' newton/_src/sim/builder.py | head -n1 | cut -d: -f1)

if [ ${finalize_line:-0} -gt 0 ]; then
  start=$((finalize_line - 20))
  [ "$start" -lt 1 ] && start=1
  end=$((finalize_line + 120))
  sed -n "${start},${end}p" newton/_src/sim/builder.py | cat -n | sed 's/^/builder.py:/'
fi

if [ ${ground_line:-0} -gt 0 ]; then
  start=$((ground_line - 10))
  [ "$start" -lt 1 ] && start=1
  end=$((ground_line + 60))
  sed -n "${start},${end}p" newton/_src/sim/builder.py | cat -n | sed 's/^/builder.py:/'
fi

# Check whether finalize creates/adds plane-specific arrays/arrays backed by model attributes.
rg -n 'ground|plane.*array|array\(|compute_ground|plane_collision|plane.*body|shape.*plane' newton/_src/sim/builder.py newton/_src -g '*.py' | head -n 200

Repository: newton-physics/newton

Length of output: 36353


Warm up the complete benchmark model.

The warmup model omits the global ground plane that both timed variations add before finalization. Build the warmup through _replicate(1) so it matches the model configuration used in the timed runs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@asv/benchmarks/setup/bench_model.py` around lines 123 - 125, Update the
warmup model construction around newton.ModelBuilder and the warmup replication
call to use the same _replicate(1) path as the timed benchmark variations,
ensuring the global ground plane is included before finalize().

@StafaH StafaH changed the title Add tiled camera scene to model build Add tiled camera scene to model build benchmark Aug 6, 2026
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@jcarius-nv
jcarius-nv self-requested a review August 6, 2026 07:53

@jcarius-nv jcarius-nv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks good. The Fast/KPI split is appropriate, and the new Fast cases appear suitable for PR coverage. Thanks, Mustafa, for the contribution and for expanding the model-building regression coverage!

Comment thread asv/benchmarks/setup/bench_model.py Outdated
warmup = newton.ModelBuilder()
warmup.replicate(self.world, 1)
warmup.finalize()
self.replicated = self._replicate(world_count)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename this to self.replicated_builder? The value is a mutable ModelBuilder, rather than a completed replicated model, and the more explicit name would make the distinction clear.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread asv/benchmarks/setup/bench_model.py Outdated


class _InitializeModelTiledCamera:
"""Replicate + finalize scenes with tiled camera and collision handling enabled."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we clarify this wording? The benchmark reuses scenes from the tiled-camera benchmark, but it does not instantiate or measure a SensorTiledCamera; collision handling remains enabled. If the intent is model-building coverage for tiled-camera scenes, the docstring and PR description should say that explicitly.

@StafaH StafaH Aug 8, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I added initialization of sensor tiled camera, so that we can measure that as well.

del self.world


class KpiInitializeModelTiledCamera(_InitializeModelTiledCamera):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was KpiInitializeModelTiledCamera exercised by the full nightly ASV suite? The PR workflow only selects Fast*.time_*, so it cannot validate that the 4,096-world variants complete within their runtime and memory budget.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it does not get picked up, I just followed the convention that the other tests in this file go though, leaving this Kpi for manual runs, and a Fast variant for the CI.

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.

2 participants