Skip to content

Conversation

@Aaryan-549
Copy link

Improve geometry file loading error handling

Addresses: #1662

Summary

Adds comprehensive error handling for geometry file loading (CHEASE, FBT, EQDSK) with helpful error messages, file suggestions, and pre-parsing validation.

Problem

Geometry file loading errors were unhelpful:

  • Generic FileNotFoundError without context
  • Deep library stack traces obscuring the real issue
  • No suggestions when files weren't found
  • No validation before parsing

Solution

1. Custom Exception Hierarchy

GeometryFileError (base) ├── GeometryFileNotFoundError # with similar file suggestions ├── GeometryFileFormatError # with specific format details ├── GeometryFilePermissionError ├── GeometryFileEmptyError └── GeometryDataValidationError # for future use

2. Modular Error Handling

Created geometry_error_handling.py module with:

  • find_similar_files() - Uses difflib for filename suggestions
  • validate_file_access() - Pre-parsing validation

Keeps geometry_loader.py focused on core loading logic.

3. Better Error Messages

Before:

FileNotFoundError: [Errno 2] No such file or directory: 'geometry.txt' 

After:

GeometryFileNotFoundError: Geometry file not found: 'geometry.txt' Searched in directory: /path/to/geo Did you mean one of these? - geometry_file.txt - geometry_data.txt Action: Check the file path and ensure the file exists. 

4. Format-Specific Validation

  • CHEASE: Header, column count, data type validation
  • FBT: MATLAB structure validation
  • EQDSK: COCOS parameter validation, required fields

5. Logging Integration

  • INFO logs for success
  • ERROR logs for failures
  • EXCEPTION logs with tracebacks

Changes

New Files:

  • geometry_errors.py - Exception classes
  • geometry_error_handling.py - Helper functions
  • tests/geometry_loader_test.py - Comprehensive tests (15+ cases)

Modified Files:

  • geometry_loader.py - Enhanced with error handling

Stats: 3 files changed, 600+ insertions, 50+ deletions

Testing

  • File not found with suggestions
  • Permission errors
  • Empty file detection
  • Format errors (CHEASE, FBT, EQDSK)
  • Valid file loading (regression)

Backward Compatibility

  • Fully backward compatible**
  • No API changes
  • Only improves error messages on failures
  • No performance impact on success path
Aaryan-549 and others added 6 commits November 6, 2025 03:28
This commit implements a Custom Pedestal Model API that allows users to define custom pedestal scaling laws without modifying TORAX source code. Fixes google-deepmind#1711 ## Changes - Add CustomPedestalModel class supporting user-defined callable functions - Add CustomPedestal Pydantic configuration - Update PedestalConfig union to include CustomPedestal - Add comprehensive unit tests (7 test cases) - Add example configuration with EPED-like scaling - Add complete API documentation ## Features Users can now provide Python functions to compute: - Ion temperature at pedestal (T_i_ped) - Electron temperature at pedestal (T_e_ped) - Electron density at pedestal (n_e_ped) - Optional dynamic pedestal location (rho_norm_ped_top) Functions receive full access to runtime parameters, geometry, and core profiles, enabling machine-specific scaling laws (e.g., STEP pedestal models with Europed data fits). ## API Design Follows the transport model pattern with: - JAX Model Layer: CustomPedestalModel (frozen dataclass) - Pydantic Config Layer: CustomPedestal (validation) - Runtime Parameters: time-varying support Fully backwards compatible - no changes to existing models.
Addresses google-deepmind#1662 This PR implements comprehensive error handling for geometry file loading (CHEASE, FBT, EQDSK formats) to provide more helpful error messages and better user experience. Changes: - Add custom exception hierarchy (GeometryFileError and subclasses) - Implement pre-parsing validation (file existence, permissions, empty files) - Add intelligent file similarity suggestions using difflib - Provide descriptive error messages with actionable steps - Integrate logging throughout the loading process - Add comprehensive test coverage for error conditions The new error handling includes: - GeometryFileNotFoundError: Suggests similar filenames when files aren't found - GeometryFilePermissionError: Clear message about permission issues - GeometryFileEmptyError: Detects and reports empty files - GeometryFileFormatError: Detailed format validation for each file type - GeometryDataValidationError: For future data constraint validation All changes are backward compatible and only affect error reporting, not the successful loading path.
Following maintainer feedback for simplicity and modularity: - Extract error handling logic into separate module - Create geometry_error_handling.py with helper functions - Move find_similar_files() and validate_file_access() to new module - Keep geometry_loader.py focused on core loading logic - Simplify PR description to be more concise - Update tests to use new module structure This separation makes the code more maintainable and follows the single responsibility principle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant