Skip to content

Conversation

dmarek-flex
Copy link
Contributor

@dmarek-flex dmarek-flex commented Oct 15, 2025

Greptile Overview

Updated On: 2025-10-15 18:28:06 UTC

Greptile Summary

This PR fixes the DirectivityMonitor class to enforce that the far_field_approx parameter must always be True. The change modifies the monitor class to use Literal[True] type constraint, preventing users from setting far_field_approx=False which would be physically incorrect for directivity calculations. Directivity measurements inherently require far-field approximations since they measure radiation patterns at distances much larger than the antenna/device size.

The implementation adds a field override in DirectivityMonitor that constrains far_field_approx to only accept True values, includes proper documentation noting this is for internal use, and maintains backward compatibility since the default was already True. The change integrates well with the existing monitor inheritance hierarchy and follows Tidy3D's pattern of using Pydantic field validation for enforcing physical constraints.

Important Files Changed

Changed Files
Filename Score Overview
tidy3d/components/monitor.py 5/5 Adds field enforcement to make far_field_approx always True in DirectivityMonitor using Literal[True] constraint
tests/test_components/test_monitor.py 5/5 Adds validation test ensuring DirectivityMonitor raises error when far_field_approx=False is attempted
CHANGELOG.md 5/5 Documents the breaking change that DirectivityMonitor now forces far_field_approx to True

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it enforces a physically correct constraint and includes proper testing
  • Score reflects simple, well-tested changes that prevent incorrect usage while maintaining backward compatibility
  • No files require special attention as all changes are straightforward and properly validated

Sequence Diagram

sequenceDiagram
    participant User
    participant DirectivityMonitor
    participant PydanticValidator
    participant ValidationError

    User->>DirectivityMonitor: "Create DirectivityMonitor(far_field_approx=False)"
    DirectivityMonitor->>PydanticValidator: "Validate far_field_approx field"
    PydanticValidator->>PydanticValidator: "Check Literal[True] constraint"
    PydanticValidator->>ValidationError: "far_field_approx must be True"
    ValidationError->>User: "Raise ValidationError"
    
    Note over User,ValidationError: Invalid case: far_field_approx=False
    
    User->>DirectivityMonitor: "Create DirectivityMonitor() or DirectivityMonitor(far_field_approx=True)"
    DirectivityMonitor->>PydanticValidator: "Validate far_field_approx field"
    PydanticValidator->>PydanticValidator: "Check Literal[True] constraint - PASS"
    PydanticValidator->>DirectivityMonitor: "Validation successful"
    DirectivityMonitor->>User: "Return DirectivityMonitor instance"
    
    Note over User,DirectivityMonitor: Valid case: far_field_approx=True (default or explicit)
Loading

@dmarek-flex dmarek-flex self-assigned this Oct 15, 2025
@dmarek-flex dmarek-flex added the RF label Oct 15, 2025
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@dmarek-flex dmarek-flex changed the title fix(rf): enforce far_field_approx=True for DirectivityMonitor fix(rf): SCRF-714 enforce far_field_approx=True for DirectivityMonitor Oct 15, 2025
@dmarek-flex dmarek-flex force-pushed the SCRF-714-enforce-far-field-approx branch 3 times, most recently from ce45d30 to 0f293dc Compare October 15, 2025 20:00
Copy link
Contributor

Diff Coverage

Diff: origin/develop...HEAD, staged and unstaged changes

  • tidy3d/components/monitor.py (100%)

Summary

  • Total: 1 line
  • Missing: 0 lines
  • Coverage: 100%

@dmarek-flex dmarek-flex force-pushed the SCRF-714-enforce-far-field-approx branch from 0f293dc to e537119 Compare October 16, 2025 01:07
@dmarek-flex dmarek-flex enabled auto-merge October 16, 2025 01:08
@dmarek-flex dmarek-flex added this pull request to the merge queue Oct 16, 2025
Merged via the queue into develop with commit a27afd2 Oct 16, 2025
25 checks passed
@dmarek-flex dmarek-flex deleted the SCRF-714-enforce-far-field-approx branch October 16, 2025 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants