agentleFS
NVIDIAKnown publisherNVIDIA/physicsnemo/.cursor/rules/mod-004-model-code-is-not-self-contained.mdc

physicsnemo / rules

Cursor rule3.3k starsChanged 12 months agoApache-2.0View on GitHub

All utility functions specific to a model must be in the same module file as the model itself, not in separate utility files, to maintain self-contained modules.

Trending

Quiet since September.about the whole repository

Dec 2025: 0 mentionsJan 2026: 3 mentionsFeb 2026: 1 mentionMar 2026: 1 mentionApr 2026: 0 mentionsMay 2026: 1 mentionJun 2026: 3 mentionsJul 2026: 3 mentionsAug 2026: 0 mentionsSep 2026: 2 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the NVIDIA/physicsnemo repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about NVIDIA/physicsnemo

The biggest 5 of 15 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 15

Talked about on GitHub (15 times).

On GitHub · 15

10 more on GitHub

The file

We split this mod-004-model-code-is-not-self-contained.mdc into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When organizing model code, rule MOD-004 must be followed.

    line 6
  2. Distinctive:

    All utility functions for a model class should be organized together with the model class in a clear and logical structure.

    line 12

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
mod-004-model-code-is-not-self-contained.mdc
---
description: All utility functions specific to a model must be in the same module file as the model itself, not in separate utility files, to maintain self-contained modules.
alwaysApply: false
---

When organizing model code, rule MOD-004 must be followed. Explicitly reference "Following rule MOD-004, which states that all utility functions for a model class should be contained in the same module file as the model class itself..." when deciding where to place utility functions.

## MOD-004: Model code is not self-contained

**Description:**

All utility functions for a model class should be organized together with the
model class in a clear and logical structure. Acceptable patterns include:

1. A single self-contained file: `physicsnemo/<models or nn>/model_name.py`
2. A subdirectory: `physicsnemo/<models or nn>/model_name/` containing:
   - `model_name.py` with the main model class
   - Additional modules for utility functions specific to this model

What should be avoided is a flat organization where model files and their
utility files are all mixed together in `physicsnemo/<models or nn>/`, making it
unclear which utilities belong to which models.

The only exception is when a utility function is used across multiple models. In
that case, the shared utility should be placed in an appropriate shared module.

**Rationale:**

Self-contained modules are easier to understand, maintain, and navigate. Having
all model-specific code in one place reduces cognitive load and makes it clear
which utilities are model-specific versus shared. This also simplifies code
reviews and reduces the likelihood of orphaned utility files when models are
refactored or removed.

**Example:**

```python
# Good Pattern 1: Single self-contained file
# File: physicsnemo/models/my_simple_model.py

def _compute_attention_mask(seq_length: int) -> torch.Tensor:
    """Helper function specific to MySimpleModel."""
    mask = torch.triu(torch.ones(seq_length, seq_length), diagonal=1)
    return mask.masked_fill(mask == 1, float('-inf'))

class MySimpleModel(Module):
    """A simple model with utilities in same file."""
    def forward(self, x: torch.Tensor) -> torch.Tensor:
        mask = _compute_attention_mask(x.shape[1])
        return self._apply_attention(x, mask)

# Good Pattern 2: Subdirectory organization
# File: physicsnemo/models/my_complex_model/my_complex_model.py
from physicsnemo.models.my_complex_model.utils import helper_function

class MyComplexModel(Module):
    """A complex model with utilities in subdirectory."""
    pass

# File: physicsnemo/models/my_complex_model/utils.py
def helper_function(x):
    """Utility specific to MyComplexModel."""
    pass
```

**Anti-pattern:**

```python
# WRONG: Flat organization with utilities mixed in main directory
# File: physicsnemo/models/my_transformer.py
from physicsnemo.models.my_transformer_utils import _compute_mask  # WRONG

class MyTransformer(Module):
    pass

# File: physicsnemo/models/my_transformer_utils.py (WRONG: mixed with other models)
# File: physicsnemo/models/other_model.py
# File: physicsnemo/models/other_model_utils.py (WRONG: utilities scattered)
# All mixed together in flat structure - unclear organization!
```

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.