Skip to content

Conversation

curtischong
Copy link
Collaborator

@curtischong curtischong commented Aug 3, 2025

Summary

I missed a few batch -> system renames when I did #217

Checklist

Before a pull request can be merged, the following items must be checked:

  • Doc strings have been added in the Google docstring format.
    Run ruff on your code.
  • Tests have been added for any new functionality or bug fixes.

We highly recommended installing the pre-commit hooks running in CI locally to speedup the development process. Simply run pip install pre-commit && pre-commit install to install the hooks which will check your code before each commit.

Summary by CodeRabbit

  • Documentation

    • Updated tutorials, comments, and print statements to replace "batchwise" terminology with "systemwise" for improved clarity and consistency.
  • Refactor

    • Renamed variables, function names, and method names from "batch" to "system" or "system_idx" throughout the codebase for clearer semantics.
    • Updated function and method signatures in neighbor list and related modules to reflect the new naming convention.
  • Bug Fixes

    • None.
  • New Features

    • None.

@cla-bot cla-bot bot added the cla-signed Contributor license agreement signed label Aug 3, 2025
Copy link

coderabbitai bot commented Aug 3, 2025

Walkthrough

This change performs a comprehensive renaming throughout the codebase, replacing "batch" terminology with "system" in variable names, function signatures, comments, and documentation. The update affects neighbor list computations, model implementations, tutorials, tests, and utility functions, ensuring consistent usage of "system" to refer to collections of atoms or molecules, rather than "batch." Several function and method names are updated to match the new terminology, with no changes to underlying logic or data flow.

Changes

Cohort / File(s) Change Summary
Examples: Variable and Doc Updates
examples/scripts/7_Others/7.3_Batched_neighbor_list.py, examples/tutorials/low_level_tutorial.py, examples/tutorials/state_tutorial.py
Renamed variables, print statements, and documentation from "batch" to "system" to clarify that data and attributes are systemwise, not batchwise. No logic changes.
Tests: Variable and Comment Updates
tests/test_autobatching.py, tests/test_integrators.py, tests/test_neighbors.py, tests/test_transforms.py
Updated variable names and comments from "batch" to "system" in test functions, maintaining logic but improving clarity and consistency.
Model Implementations: Internal Naming
torch_sim/models/graphpes.py, torch_sim/models/mace.py, torch_sim/models/orb.py, torch_sim/models/sevennet.py
Renamed variables, method names, and comments from "batch" to "system" (e.g., batch_masksystem_mask, setup_from_batchsetup_from_system_idx). One method in MaceModel and all references updated accordingly. No logic changes.
Neighbor List Functions: Signature and Doc Update
torch_sim/neighbors.py
Renamed function parameters, local variables, and docstrings from batch_mapping to system_mapping, and input arguments from batch to system_idx in neighbor list functions. Function signatures updated accordingly. No logic changes.
Quantities Utility: Function Rename
torch_sim/quantities.py
Renamed function batchwise_max_force to systemwise_max_force and updated docstring to match. No logic changes.
Runners and Integration: Systemwise Refactor
torch_sim/runners.py
Updated imports, variable names, comments, and docstrings from "batch" to "system," including convergence functions and reporting logic. Now consistently operates at the system level. Uses systemwise_max_force. No logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Runner
    participant Quantities
    participant NeighborList
    participant Model

    User->>Runner: Call integrate/optimize/static (systemwise)
    Runner->>NeighborList: Compute neighbor list (system_idx)
    Runner->>Model: Forward pass (system_idx, system_mask)
    Model->>NeighborList: Use system_mapping for edge construction
    Runner->>Quantities: Compute systemwise_max_force
    Note over Runner,Quantities: All operations now use "system" terminology
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Radical-AI/torch-sim#217: Also performs a comprehensive renaming from "batch" to "system" in neighbor list computations and related functions, closely matching the changes in this PR.

Poem

A rabbit hopped through code so vast,
Swapping "batch" for "system"—change at last!
Variables, docs, and tests align,
Each atom’s home now clearly defined.
With systemwise logic, the journey’s complete,
This tidy warren is now extra neat!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rename-more-batch-to-system

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 generate unit tests to generate unit tests for 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (7)
examples/scripts/7_Others/7.3_Batched_neighbor_list.py (1)

40-48: Second call mirrors first – same shape caveat

pbc_tensor is reused; ensuring the earlier fix propagates here will resolve any potential mismatch.

Consider factoring the neighbour-list call into a small helper to avoid duplication between linked-cell and (N^2) paths.

torch_sim/quantities.py (1)

153-159: Specify include_self=False to avoid a silent edge-case

Tensor.scatter_reduce includes the existing values of the destination tensor in the reduction unless include_self=False.
Right now the destination tensor is initialised with zeros, so the behaviour is correct, but:

  • the intent (“pure reduce over src”) is clearer with the flag set;
  • future refactors (e.g. different initial fill value) will not change semantics.
-    return system_wise_max_force.scatter_reduce(
-        dim=0, index=state.system_idx, src=max_forces, reduce="amax"
-    )
+    return system_wise_max_force.scatter_reduce(
+        dim=0,
+        index=state.system_idx,
+        src=max_forces,
+        reduce="amax",
+        include_self=False,
+    )
torch_sim/models/orb.py (1)

226-236: Minor type/device consistency caveat

system_num_edges is created on device which can legitimately be None (the default).
If the caller passes device=None while the rest of the tensors live on, say, CUDA, this tensor stays on CPU and triggers an implicit device copy inside AtomGraphs.__init__.
Consider defaulting to positions.device when device is None to avoid unnecessary transfers:

-device = device  # may be None
+device = device or positions.device
tests/test_integrators.py (1)

23-30: Out-of-date comment lists “3 systems” but four are generated

The updated system_idx creates four systems (indices 0-3).
Adjust the comment to prevent confusion during future maintenance.

torch_sim/neighbors.py (3)

704-706: Inconsistent naming between system_mapping and mapping_system.

Inside strict_nl the filtered tensor is stored in mapping_system, while the incoming argument is system_mapping.
Although not wrong, the flip in word order is easy to mis-read and requires mental context switching in the downstream functions.

-    mapping_system = system_mapping[mask]
-    ...
-    return mapping, mapping_system, shifts_idx
+    filtered_system_mapping = system_mapping[mask]
+    ...
+    return mapping, filtered_system_mapping, shifts_idx

753-759: Potential GPU → CPU device hop.

torch.bincount(system_idx) always returns a CPU tensor, regardless of the input device.
If positions (and therefore system_idx) lives on the GPU this introduces an unnecessary host–device sync every time torch_nl_n2 is called.

Consider keeping the tensor on the same device:

- n_atoms = torch.bincount(system_idx)
+ n_atoms = torch.bincount(system_idx.cpu()).to(system_idx.device)

810-817: Duplicate filter/rename logic – candidate for helper extraction.

torch_nl_n2 and torch_nl_linked_cell share the same two-step pattern:

  1. build_*_neighborhood → (mapping, system_mapping, shifts_idx)
  2. strict_nl → filtered result

Extracting this into a small private utility would remove duplication and lower the risk of future drift.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 16bf8f8 and 81ef554.

📒 Files selected for processing (14)
  • examples/scripts/7_Others/7.3_Batched_neighbor_list.py (1 hunks)
  • examples/tutorials/low_level_tutorial.py (2 hunks)
  • examples/tutorials/state_tutorial.py (5 hunks)
  • tests/test_autobatching.py (1 hunks)
  • tests/test_integrators.py (2 hunks)
  • tests/test_neighbors.py (3 hunks)
  • tests/test_transforms.py (2 hunks)
  • torch_sim/models/graphpes.py (1 hunks)
  • torch_sim/models/mace.py (4 hunks)
  • torch_sim/models/orb.py (3 hunks)
  • torch_sim/models/sevennet.py (1 hunks)
  • torch_sim/neighbors.py (11 hunks)
  • torch_sim/quantities.py (1 hunks)
  • torch_sim/runners.py (10 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (9)
torch_sim/models/graphpes.py (2)
tests/test_state.py (1)
  • test_deprecated_batch_properties_equal_to_new_system_properties (623-645)
torch_sim/state.py (2)
  • _filter_attrs_by_mask (613-666)
  • n_atoms_per_batch (166-177)
torch_sim/models/sevennet.py (1)
torch_sim/state.py (6)
  • row_vector_cell (246-248)
  • row_vector_cell (251-257)
  • batch (194-205)
  • n_atoms_per_batch (166-177)
  • SimState (26-373)
  • batch (180-191)
torch_sim/quantities.py (2)
torch_sim/state.py (3)
  • SimState (26-373)
  • batch (194-205)
  • n_atoms_per_batch (166-177)
tests/test_state.py (1)
  • test_deprecated_batch_properties_equal_to_new_system_properties (623-645)
tests/test_autobatching.py (1)
tests/test_runners.py (3)
  • test_integrate_with_autobatcher (182-212)
  • test_static_with_autobatcher (601-631)
  • test_static_with_autobatcher_and_reporting (634-739)
tests/test_transforms.py (1)
torch_sim/transforms.py (2)
  • compute_cell_shifts (537-563)
  • build_linked_cell_neighborhood (965-1039)
torch_sim/runners.py (3)
torch_sim/quantities.py (3)
  • calc_kinetic_energy (96-130)
  • calc_kT (23-69)
  • systemwise_max_force (144-159)
torch_sim/trajectory.py (1)
  • load_new_trajectories (145-174)
tests/test_state.py (1)
  • test_deprecated_batch_properties_equal_to_new_system_properties (623-645)
torch_sim/models/mace.py (1)
torch_sim/state.py (1)
  • batch (194-205)
tests/test_neighbors.py (4)
torch_sim/state.py (4)
  • batch (180-191)
  • batch (194-205)
  • device (142-144)
  • dtype (147-149)
torch_sim/transforms.py (1)
  • compute_cell_shifts (537-563)
torch_sim/neighbors.py (1)
  • strict_nl (640-706)
tests/test_state.py (1)
  • test_deprecated_batch_properties_equal_to_new_system_properties (623-645)
torch_sim/neighbors.py (1)
torch_sim/transforms.py (4)
  • compute_cell_shifts (537-563)
  • build_naive_neighborhood (614-685)
  • build_linked_cell_neighborhood (965-1039)
  • linked_cell (802-962)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (33)
  • GitHub Check: test-examples (examples/scripts/7_Others/7.6_Compare_ASE_to_VV_FIRE.py)
  • GitHub Check: test-examples (examples/scripts/7_Others/7.3_Batched_neighbor_list.py)
  • GitHub Check: test-examples (examples/scripts/7_Others/7.1_Soft_sphere_autograd.py)
  • GitHub Check: test-examples (examples/scripts/7_Others/7.4_Velocity_AutoCorrelation.py)
  • GitHub Check: test-examples (examples/scripts/2_Structural_optimization/2.5_MACE_UnitCellFilter_Gradient_Descen...
  • GitHub Check: test-examples (examples/scripts/2_Structural_optimization/2.6_MACE_UnitCellFilter_FIRE.py)
  • GitHub Check: test-examples (examples/scripts/5_Workflow/5.3_Elastic.py)
  • GitHub Check: test-examples (examples/scripts/5_Workflow/5.1_a2c_silicon_batched.py)
  • GitHub Check: test-examples (examples/scripts/4_High_level_api/4.1_high_level_api.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.5_MACE_NVT_Nose_Hoover.py)
  • GitHub Check: test-examples (examples/tutorials/low_level_tutorial.py)
  • GitHub Check: test-examples (examples/tutorials/metatomic_tutorial.py)
  • GitHub Check: test-examples (examples/tutorials/autobatching_tutorial.py)
  • GitHub Check: test-examples (examples/tutorials/high_level_tutorial.py)
  • GitHub Check: test-model (ubuntu-latest, 3.12, lowest-direct, fairchem, tests/models/test_fairchem.py)
  • GitHub Check: test-model (macos-14, 3.12, lowest-direct, graphpes, tests/models/test_graphpes.py)
  • GitHub Check: test-model (macos-14, 3.11, highest, sevenn, tests/models/test_sevennet.py)
  • GitHub Check: test-model (macos-14, 3.11, highest, orb, tests/models/test_orb.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, mattersim, tests/models/test_mattersim.py)
  • GitHub Check: test-model (ubuntu-latest, 3.12, lowest-direct, orb, tests/models/test_orb.py)
  • GitHub Check: test-model (ubuntu-latest, 3.11, highest, 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.12, lowest-direct, mace, tests/test_elastic.py)
  • GitHub Check: test-model (ubuntu-latest, 3.11, highest, mace, tests/test_optimizers_vs_ase.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, fairchem, tests/models/test_fairchem.py)
  • GitHub Check: test-model (ubuntu-latest, 3.11, highest, mace, tests/test_elastic.py)
  • GitHub Check: test-core (macos-14, 3.12, lowest-direct)
  • GitHub Check: test-core (ubuntu-latest, 3.12, lowest-direct)
  • GitHub Check: build-docs
🔇 Additional comments (22)
torch_sim/models/graphpes.py (1)

70-74: Consistent terminology change – looks good

batch_masksystem_mask aligns with the project-wide rename and keeps the masking logic intact. No functional impact observed.

torch_sim/models/sevennet.py (1)

185-192: Variable rename is correct and complete

The swap to system_mask on Lines 185-192 is internally consistent (positions, atomic numbers, and later usage). No additional updates required in this block.

tests/test_autobatching.py (1)

152-154: Comment wording updated – no code impact

Changing “batches” → “systems” keeps the assertion meaning clear and consistent with new terminology.

examples/tutorials/low_level_tutorial.py (1)

110-122: Docstring / print-statement rename confirmed

“batchwise” → “systemwise” wording only; runtime behaviour unchanged.

examples/scripts/7_Others/7.3_Batched_neighbor_list.py (1)

28-36: Down-stream uses depend on corrected pbc_tensor

Once the shape issue above is fixed, the renamed mapping_system variables here are correct. No further action required.

Please re-run the script locally after the shape fix to ensure torch_nl_linked_cell and torch_nl_n2 execute without RuntimeError on tensor shape mismatches.

tests/test_transforms.py (1)

1186-1189: LGTM – variable rename only

Renaming batch_mappingsystem_mapping keeps the test in sync with the API. No functional issues spotted.

examples/tutorials/state_tutorial.py (1)

74-80: Documentation update looks consistent

All occurrences of “batchwise” were correctly replaced with “systemwise”. No further action required.

Also applies to: 145-147, 185-198, 206-207

torch_sim/models/mace.py (4)

187-195: LGTM! Consistent terminology update.

The comment updates and method call rename from "batch" to "system_idx" are consistent with the PR objective and maintain the same functionality.


197-199: LGTM! Method renaming is consistent.

The method name change from setup_from_batch to setup_from_system_idx aligns with the new terminology and maintains the same functionality.


289-298: LGTM! Consistent update in forward method.

The comment and method call updates from "batch" to "system_idx" terminology are consistent with the renamed method and maintain the same logic flow.


308-325: LGTM! Consistent variable renaming improves semantic clarity.

The renaming from batch_mask to system_mask throughout the neighbor list processing loop is semantically more accurate and consistently applied across all variable usages.

torch_sim/runners.py (6)

25-25: LGTM! Import statement correctly updated.

The import change from batchwise_max_force to systemwise_max_force aligns with the function renaming in torch_sim.quantities and is necessary for the code to function correctly.


177-184: LGTM! Consistent variable renaming in integrate function.

The renaming from batch_indices to system_indices is semantically more accurate and consistently applied throughout the loop processing. The comment update also reflects the correct terminology.


300-313: LGTM! Convergence function updates are consistent.

The docstring updates correctly reflect that the function returns systemwise boolean results, and the function call change to systemwise_max_force aligns with the updated import and improved semantics.


440-446: LGTM! Consistent variable renaming in optimize function.

The variable renaming from batch_indices to system_indices maintains consistency with the integrate function and accurately represents the semantic meaning of the indices.


490-491: LGTM! Docstring updates improve clarity.

The docstring changes from "batch" to "system" accurately describe the function's behavior of returning results per system rather than per batch.


550-555: LGTM! Final variable renaming maintains consistency.

The variable renaming in the static function matches the pattern used in integrate and optimize functions, ensuring consistent terminology across all runner functions.

tests/test_neighbors.py (3)

345-351: LGTM! Test variable renaming aligns with implementation.

The variable renaming from mapping_batch to mapping_system correctly reflects the updated function signatures and improves semantic clarity in the test code.


499-522: LGTM! Consistent parameter renaming in strict_nl tests.

The variable and parameter renaming from batch_mapping to system_mapping correctly matches the updated strict_nl function signature and maintains consistency throughout the test cases.


562-562: LGTM! Performance test variable renaming is consistent.

The unpacking variable change from mapping_batch to mapping_system maintains consistency with the updated function signatures in the neighbor list implementations.

torch_sim/neighbors.py (2)

692-693: No-op when cell is None is still respected – LGTM.
compute_cell_shifts already handles the None-cell case, so the new variable name introduces no functional change.


645-647: Rename Confirmation: no downstream batch_mapping calls found

A repository-wide search for the old keyword argument (batch_mapping=) returned no matches in any .py files. There are no external call-sites using the removed name, so replacing batch_mapping with system_mapping is safe and won’t break downstream code.

Comment on lines 25 to 27
# Fix: Ensure pbc has the correct shape [n_systems, 3]
pbc_tensor = torch.tensor([[pbc] * 3] * len(atoms_list), dtype=torch.bool)

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Broadcast error: pbc_tensor gets wrong shape

[[pbc] * 3] * len(atoms_list) expands both the leading and 2nd dimensions, yielding shape (n_systems, 3, 3) instead of (n_systems, 3).
This will break downstream neighbour-list functions expecting (n_systems, 3) or (3,).

Suggested fix:

-# Fix: Ensure pbc has the correct shape [n_systems, 3]
-pbc_tensor = torch.tensor([[pbc] * 3] * len(atoms_list), dtype=torch.bool)
+# Ensure pbc has shape (n_systems, 3)
+if isinstance(pbc, torch.Tensor) and pbc.dim() == 1:
+    # pbc is a (3,) tensor – broadcast over systems
+    pbc_tensor = pbc.unsqueeze(0).repeat(len(atoms_list), 1)
+else:
+    # pbc is a python bool or already (3,) list
+    pbc_tensor = torch.tensor([pbc] * len(atoms_list), dtype=torch.bool)

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In examples/scripts/7_Others/7.3_Batched_neighbor_list.py around lines 25 to 27,
the construction of pbc_tensor incorrectly expands dimensions resulting in shape
(n_systems, 3, 3) instead of the required (n_systems, 3). To fix this, create a
list of pbc repeated n_systems times without duplicating the inner list three
times, then convert it to a tensor with dtype=torch.bool to ensure the shape is
(n_systems, 3).

Copy link
Collaborator

@CompRhys CompRhys left a comment

Choose a reason for hiding this comment

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

lgtm

@CompRhys CompRhys merged commit 926e043 into main Aug 6, 2025
92 of 93 checks passed
@CompRhys CompRhys deleted the rename-more-batch-to-system branch August 6, 2025 22:45
@coderabbitai coderabbitai bot mentioned this pull request Aug 14, 2025
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.

2 participants