PhysicsNeMo is an open-source PyTorch framework for creating, training, and fine-tuning machine-learning models for physics, scientific computing, and engineering. Researchers and engineers use its reusable components and training recipes for applications such as aerodynamics, weather forecasting, structural mechanics, geophysics, and thermal design. The catalogue entries provide rules and skills for working with PhysicsNeMo projects.
Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/nvidia/physicsnemo/mod-011-use-proper-optional-dependency-handlinggit clone --depth 1 https://github.com/NVIDIA/physicsnemoWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/rules/nvidia/physicsnemo/mod-011-use-proper-optional-dependency-handling)<a href="https://agentmods.dev/rules/nvidia/physicsnemo/mod-011-use-proper-optional-dependency-handling"><img src="https://agentmods.dev/badge/rules/nvidia/physicsnemo/mod-011-use-proper-optional-dependency-handling.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00036 | $0.00787 |
| Opus 5 | $0.00018 | $0.00394 |
| Sonnet 5 | $0.00007 | $0.00157 |
| Haiku 4.5 | $0.00004 | $0.00079 |
Grade A, and why
mod-011-use-proper-optional-dependency-handling scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
What it actually says
When handling optional dependencies in model code, rule MOD-011 must be followed. Explicitly reference "Following rule MOD-011, which requires using check_min_version() for optional dependencies..." when implementing dependency checks.
MOD-011: Use proper optional dependency handling
Description:
When a model requires optional dependencies (packages not installed by default), use the PhysicsNeMo APIs for dependency handling:
-
check_min_version(package, version, hard_fail=False): Use this function to check if a package is installed and available without actually importing it. Sethard_fail=Truefor hard requirements,hard_fail=Falsefor soft requirements. This is the primary method for handling optional dependencies. -
@require_version(package, version): Use this decorator when core code must always be available but certain features need to be protected against older versions. This is rare and should only be used when you need to protect specific methods or classes. -
pyproject.toml: This file is the one, only, and universal source of truth for all dependencies in PhysicsNeMo. All optional dependencies must be declared there.
Rationale:
Centralized dependency handling ensures consistent error messages and version
checking across the codebase. Checking availability without importing prevents
import errors and allows graceful degradation. Using pyproject.toml as the
single source of truth prevents dependency specification from becoming scattered
and inconsistent.
Example:
import torch
from physicsnemo.core import Module
from physicsnemo.core.version_check import check_min_version, require_version
# Check optional dependency availability without importing
APEX_AVAILABLE = check_min_version("apex", "0.1.0", hard_fail=False)
class MyModel(Module):
def __init__(
self,
input_dim: int,
use_apex: bool = False
):
super().__init__()
self.use_apex = use_apex
if use_apex and not APEX_AVAILABLE:
raise RuntimeError(
"apex is required for use_apex=True but is not installed. "
"Install with: pip install apex>=0.1.0"
)
if use_apex:
import apex # Only import when actually needed
self.fused_layer = apex.FusedLayer()
else:
self.fused_layer = None
# Using @require_version for protecting version-specific features
class AdvancedModel(Module):
@require_version("torch", "2.4.0")
def use_device_mesh(self):
"""This feature requires torch>=2.4.0."""
from torch.distributed.device_mesh import DeviceMesh
# Protected code
Anti-pattern:
# WRONG: Direct import without checking availability
import apex # Will fail if apex not installed!
class MyModel(Module):
def __init__(self, use_apex: bool = False):
if use_apex:
self.layer = apex.FusedLayer() # Already failed at import!
# WRONG: Try/except for dependency checking
try:
import apex
APEX_AVAILABLE = True
except ImportError:
APEX_AVAILABLE = False
# Use check_min_version instead!
# WRONG: Hardcoded version strings in multiple places
if version.parse(apex.__version__) < version.parse("0.1.0"):
raise ImportError("apex>=0.1.0 required")
# Should use check_min_version or require_version!
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 5d ago First seen · 101 lines · 36 tokens per session scan A abc7ff27d7cc
mod-011-use-proper-optional-dependency-handling is a cursor rule published in the GitHub repository NVIDIA/physicsnemo (3,222 stars, last pushed today), licensed Apache-2.0. It adds 36 tokens to every session and 787 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other cursor rules, from other repositories
typescript
Changes to these high-fan-out internals can affect every message, delta, element, or rerun. Keep work in them minimal, and benchmark changes with representative stress-test apps.
python_lib
Tips and guidelines specific to the development of the Streamlit Python library, not applicable to scripts and e2e tests.
python_tests
We use the unit tests to cover internal behavior that can work without the web / backend counterpart. We aim for 95%+ unit test coverage of our Python code in lib/streamlit.
overview
Streamlit is an open-source (Apache 2.0) Python library for creating interactive web applications and dashboards with focus on data apps and internal tools.
python
Cursor rule "python" from streamlit/streamlit, covering python development guide, key principles, docstrings, package structure and dependencies.
python-style
Python code style — imports, third-party submodules, and docstrings.