Skip to content

Conversation

t-reents
Copy link
Contributor

@t-reents t-reents commented Jul 4, 2025

The current version results in an infinite loop when scale_factor < 1.5 due to the rounding.

This is fixed by increasing the batch size by at least +1.

Summary by CodeRabbit

  • Refactor
    • Improved batch size scaling logic to ensure consistent increases and prevent potential infinite loops or stagnation.
    • Updated the default scaling factor for batch size determination to provide more efficient batch size progression.
  • Bug Fixes
    • Added tests to verify batch size calculation avoids infinite loops with small scaling factors.
  • Chores
    • Updated dependency specifications by removing optional features from package declarations in example scripts.

The current version results in an infinite loop when `scale_factor < 1.5` due to the rounding.
This is fixed by increasing the batch size by at least `+1`.
@cla-bot cla-bot bot added the cla-signed Contributor license agreement signed label Jul 4, 2025
Copy link

coderabbitai bot commented Jul 4, 2025

Walkthrough

The determine_max_batch_size function in torch_sim/autobatching.py was updated to use a default scale_factor of 1.6 instead of 1.3. The logic for generating the next batch size now ensures that each increment is at least one, preventing stagnation due to rounding. Two example scripts had their pymatviz dependency simplified by removing the optional export-figs feature. A new test was added to verify that determine_max_batch_size does not enter infinite loops with small scale factors.

Changes

File(s) Change Summary
torch_sim/autobatching.py Updated default scale_factor in determine_max_batch_size and improved batch size increment logic.
examples/scripts/6_Phonons/6.1_Phonons_MACE.py Removed optional export-figs from pymatviz dependency specification in header comment.
examples/scripts/6_Phonons/6.2_QuasiHarmonic_MACE.py Removed optional export-figs from pymatviz dependency specification in header comment.
tests/test_autobatching.py Added parameterized test to ensure no infinite loop occurs in determine_max_batch_size with small scale factors.

Poem

A batch of numbers, now grown with care,
No more stuck in loops, always going somewhere.
From one point three to one point six we leap,
Each batch steps forward, never falling asleep.
Rabbits rejoice—progress is neat! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6261933 and 2da557e.

📒 Files selected for processing (3)
  • examples/scripts/6_Phonons/6.1_Phonons_MACE.py (1 hunks)
  • examples/scripts/6_Phonons/6.2_QuasiHarmonic_MACE.py (1 hunks)
  • tests/test_autobatching.py (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • examples/scripts/6_Phonons/6.2_QuasiHarmonic_MACE.py
  • examples/scripts/6_Phonons/6.1_Phonons_MACE.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/test_autobatching.py (2)
tests/conftest.py (2)
  • si_sim_state (142-144)
  • lj_model (34-45)
torch_sim/autobatching.py (1)
  • determine_max_batch_size (250-307)
⏰ Context from checks skipped due to timeout of 90000ms (40)
  • GitHub Check: test-examples (examples/scripts/5_Workflow/5.1_a2c_silicon_batched.py)
  • GitHub Check: test-examples (examples/scripts/2_Structural_optimization/2.3_MACE_Gradient_Descent.py)
  • GitHub Check: test-examples (examples/scripts/2_Structural_optimization/2.7_MACE_FrechetCellFilter_FIRE.py)
  • GitHub Check: test-examples (examples/scripts/2_Structural_optimization/2.6_MACE_UnitCellFilter_FIRE.py)
  • GitHub Check: test-examples (examples/scripts/2_Structural_optimization/2.5_MACE_UnitCellFilter_Gradient_Descen...
  • GitHub Check: test-examples (examples/scripts/1_Introduction/1.2_MACE.py)
  • GitHub Check: test-examples (examples/scripts/7_Others/7.6_Compare_ASE_to_VV_FIRE.py)
  • GitHub Check: test-examples (examples/scripts/4_High_level_api/4.1_high_level_api.py)
  • GitHub Check: test-examples (examples/scripts/4_High_level_api/4.2_auto_batching_api.py)
  • GitHub Check: test-examples (examples/scripts/1_Introduction/1.3_Fairchem.py)
  • GitHub Check: test-examples (examples/scripts/3_Dynamics/3.13_MACE_NVE_non_pbc.py)
  • GitHub Check: test-examples (examples/scripts/3_Dynamics/3.5_MACE_NVT_Nose_Hoover.py)
  • GitHub Check: test-examples (examples/scripts/3_Dynamics/3.6_MACE_NVT_Nose_Hoover_temp_profile.py)
  • GitHub Check: test-examples (examples/scripts/3_Dynamics/3.4_MACE_NVT_Langevin.py)
  • GitHub Check: test-examples (examples/scripts/3_Dynamics/3.8_MACE_NPT_Nose_Hoover.py)
  • GitHub Check: test-examples (examples/scripts/6_Phonons/6.2_QuasiHarmonic_MACE.py)
  • GitHub Check: test-examples (examples/tutorials/hybrid_swap_tutorial.py)
  • GitHub Check: test-examples (examples/scripts/7_Others/7.4_Velocity_AutoCorrelation.py)
  • GitHub Check: test-examples (examples/tutorials/autobatching_tutorial.py)
  • GitHub Check: test-examples (examples/tutorials/high_level_tutorial.py)
  • GitHub Check: test-examples (examples/tutorials/low_level_tutorial.py)
  • GitHub Check: test-model (macos-14, 3.12, lowest-direct, sevenn, tests/models/test_sevennet.py)
  • GitHub Check: test-model (macos-14, 3.11, highest, mace, tests/test_optimizers_vs_ase.py)
  • GitHub Check: test-model (ubuntu-latest, 3.12, lowest-direct, sevenn, tests/models/test_sevennet.py)
  • GitHub Check: test-model (macos-14, 3.11, highest, mace, tests/test_elastic.py)
  • GitHub Check: test-model (ubuntu-latest, 3.12, lowest-direct, mattersim, tests/models/test_mattersim.py)
  • GitHub Check: test-model (macos-14, 3.11, highest, fairchem, tests/models/test_fairchem.py)
  • GitHub Check: test-model (ubuntu-latest, 3.12, lowest-direct, mace, tests/test_elastic.py)
  • GitHub Check: test-model (ubuntu-latest, 3.12, lowest-direct, orb, tests/models/test_orb.py)
  • GitHub Check: test-model (ubuntu-latest, 3.12, lowest-direct, mace, tests/test_optimizers_vs_ase.py)
  • GitHub Check: test-model (ubuntu-latest, 3.11, highest, mace, tests/test_optimizers_vs_ase.py)
  • GitHub Check: test-model (ubuntu-latest, 3.12, lowest-direct, graphpes, tests/models/test_graphpes.py)
  • GitHub Check: test-model (ubuntu-latest, 3.12, lowest-direct, fairchem, tests/models/test_fairchem.py)
  • GitHub Check: test-model (ubuntu-latest, 3.11, highest, sevenn, tests/models/test_sevennet.py)
  • GitHub Check: test-model (ubuntu-latest, 3.11, highest, mattersim, tests/models/test_mattersim.py)
  • GitHub Check: test-model (ubuntu-latest, 3.11, highest, orb, tests/models/test_orb.py)
  • GitHub Check: test-model (ubuntu-latest, 3.11, highest, mace, tests/test_elastic.py)
  • GitHub Check: test-model (ubuntu-latest, 3.11, highest, fairchem, tests/models/test_fairchem.py)
  • GitHub Check: test-core (ubuntu-latest, 3.12, lowest-direct)
  • GitHub Check: build-docs
🔇 Additional comments (2)
tests/test_autobatching.py (2)

379-379: Good test coverage for edge cases.

The parametrization with scale factors 1.1 and 1.4 effectively tests the edge cases that would have caused infinite loops in the original implementation, directly addressing the PR objectives.


380-403: Excellent test implementation for preventing infinite loops.

The test effectively verifies the fix for the infinite loop issue by:

  1. Using small scale factors that would have caused the original bug
  2. Manually constructing the expected sequence using the same logic as the actual function
  3. Verifying that the sequence is strictly increasing (key to preventing infinite loops)
  4. Confirming the returned value matches expectations

The test logic correctly mirrors the actual function implementation and provides comprehensive coverage for the bug fix.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

… does regress to infinite loop

* remove outdated pymatviz extras 'export-figs' in `6.1_Phonons_MACE.py` and `6.2_QuasiHarmonic_MACE.py`
Copy link
Collaborator

@janosh janosh left a comment

Choose a reason for hiding this comment

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

thanks @t-reents for catching and fixing! 👍

@janosh
Copy link
Collaborator

janosh commented Jul 4, 2025

CI failures due to plotly breaking change plotly/plotly.py#5253 (comment), workaround in c734c00

@janosh janosh merged commit 2bb3bd5 into TorchSim:main Jul 4, 2025
89 of 90 checks passed
@bmaranville
Copy link

Fixes for pymatviz compatibility with plotly>=6.2.0 are in janosh/pymatviz#310

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

Labels

cla-signed Contributor license agreement signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants