Skip to content

Improves the timer so that it can track var + mean - #4498

Merged
kellyguo11 merged 4 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/better_timer
Jan 30, 2026
Merged

kellyguo11 merged 4 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/better_timer

Conversation

@AntoineRichard

Copy link
Copy Markdown
Collaborator

Description

Modified the timer so that it can track var + mean

Type of change

  • New feature (non-breaking change which adds functionality)
  • Documentation update

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Jan 30, 2026
@greptile-apps

greptile-apps Bot commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Enhanced Timer class to track mean and standard deviation of elapsed times across multiple measurements using Welford's online algorithm.

Key Changes:

  • Modified timing_info from storing single float values to dictionaries containing last, mean, std, m2, and n
  • Implemented _update_welford() method for numerically stable statistical computation with Bessel's correction (n-1 for sample std)
  • Added get_timer_statistics() method to retrieve full statistics
  • Maintained backward compatibility: get_timer_info() still returns last elapsed time as float

Testing:

  • Added comprehensive test coverage for Welford's algorithm correctness
  • Verified backward compatibility of get_timer_info()
  • Tested multiple timer instances sharing the same name
  • Validated error handling for non-existent timers

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Implementation is mathematically correct with proper Bessel's correction for sample standard deviation. Comprehensive test coverage validates both new functionality and backward compatibility. Documentation and version updates are complete.
  • No files require special attention

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/utils/timer.py Enhanced Timer class to track mean and variance using Welford's algorithm, maintains backward compatibility
source/isaaclab/test/utils/test_timer.py Added comprehensive tests for Welford statistics and backward compatibility

Sequence Diagram

sequenceDiagram
    participant User
    participant Timer1 as Timer Instance 1
    participant Timer2 as Timer Instance 2
    participant Global as Timer.timing_info (Global Dict)

    User->>Timer1: Timer(name="my_timer")
    User->>Timer1: start()
    Timer1->>Timer1: _start_time = perf_counter()
    
    Note over User,Timer1: Some operation runs
    
    User->>Timer1: stop()
    Timer1->>Timer1: Calculate _elapsed_time
    Timer1->>Timer1: _update_welford(_elapsed_time)
    Timer1->>Global: Check if "my_timer" exists (KeyError)
    Global-->>Timer1: Not found
    Timer1->>Timer1: Initialize: _n=1, _mean=value, _m2=0, _std=0
    Timer1->>Global: Store {last, m2, mean, std, n}
    
    Note over User,Global: Second timing with same name
    
    User->>Timer2: Timer(name="my_timer")
    User->>Timer2: start() / stop()
    Timer2->>Timer2: _update_welford(_elapsed_time)
    Timer2->>Global: Retrieve existing "my_timer" stats
    Global-->>Timer2: {mean, m2, n, ...}
    Timer2->>Timer2: _n = n + 1
    Timer2->>Timer2: delta = value - mean
    Timer2->>Timer2: _mean = mean + delta/_n
    Timer2->>Timer2: delta2 = value - _mean
    Timer2->>Timer2: _m2 = m2 + delta*delta2
    Timer2->>Timer2: _std = sqrt(_m2/(_n-1))
    Timer2->>Global: Update {last, m2, mean, std, n}
    
    User->>Global: get_timer_info("my_timer")
    Global-->>User: Return last elapsed time (backward compatible)
    
    User->>Global: get_timer_statistics("my_timer")
    Global-->>User: Return {mean, std, n, last}
Loading

@greptile-apps greptile-apps 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.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread source/isaaclab/isaaclab/utils/timer.py Resolved
@AntoineRichard

Copy link
Copy Markdown
Collaborator Author

@greptile could you review again?

@greptile-apps greptile-apps 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.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@kellyguo11 kellyguo11 changed the title Improved the timer so that it can track var + mean Improves the timer so that it can track var + mean Jan 30, 2026
@kellyguo11
kellyguo11 merged commit b722ffb into isaac-sim:develop Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants