Skip to content

Refactor/fmpy naming conventions#1871

Merged
sambles merged 6 commits intomainfrom
refactor/fmpy-naming-conventions
Feb 26, 2026
Merged

Refactor/fmpy naming conventions#1871
sambles merged 6 commits intomainfrom
refactor/fmpy-naming-conventions

Conversation

@sstruzik
Copy link
Copy Markdown
Contributor

Refactor fmpy naming conventions and add comprehensive documentation

Summary

This PR improves the readability, maintainability, and documentation of the Financial Module (fmpy) computation code through systematic variable naming refactoring and comprehensive documentation additions.

Changes

1. Variable Naming Convention Refactoring

Established and applied consistent naming patterns across the FM computation module:

  • Index/iterator variables: Use _i suffix (e.g., profile_i, layer_i, val_i)
  • Count/length variables: Use _count suffix (e.g., children_count, node_val_count)
  • Contextual prefixes: Add descriptive prefixes for clarity (e.g., profile_, layer_, node_)
  • Constant clarity: Renamed EXTRA_VALUES to EXTRA_SIDX_COUNT for better semantic meaning

Files modified:

  • common.py: Updated constant naming
  • compare.py: Updated import references
  • compute_sparse.py: Refactored loop variables and parameters
  • back_allocation.py: Refactored allocation variables
  • stream_sparse.py: Refactored stream handling variables
  • manager.py: Refactored event loop counter

2. Comprehensive Code Documentation

Added extensive inline documentation to improve code maintainability:

  • Module-level docstrings explaining the FM computation architecture
  • Detailed function comments documenting the algorithm flow
  • CSR-like sparse storage model explanation
  • Bottom-up level traversal with aggregation and back allocation logic
  • Profile application strategies (per-layer vs cross-layer)
  • Back allocation rules and extras handling
  • Stream I/O format and parsing state machine

3. Technical Documentation (TECHNICAL.md)

Created comprehensive technical documentation covering:

  • Detailed CSR-inspired sparse storage format
  • Data structure documentation (nodes, compute_idx, extras)
  • Complete computation flow with algorithms
  • Aggregation and back allocation explanations
  • Stream I/O format specification
  • Memory management and performance tips
  • Debugging guidance

4. User Guide (README.md)

Created user-friendly documentation including:

  • Quick start examples (Python API and CLI)
  • Configuration options (allocation rules, net loss, memory)
  • Input file requirements and output format explanation
  • Supported financial terms
  • Performance optimization tips
  • Troubleshooting guide
  • Architecture overview

5. Code Quality

  • Applied PEP8 formatting standards
  • Code cleanup and consistency fixes

Impact

These changes significantly improve the maintainability and accessibility of the FM computation module without altering its functionality. The consistent naming conventions make the code easier to understand, while the comprehensive documentation provides both technical details for developers and practical guidance for users.

Improve readability and consistency of variable names in the FM
loss computation module:

- Use _i suffix for indices/iterators (e.g., profile_i, layer_i, val_i)
- Use _count suffix for counts/lengths (e.g., children_count, node_val_count)
- Add descriptive prefixes for context (e.g., profile_, layer_, node_)
- Rename EXTRA_VALUES to EXTRA_SIDX_COUNT for clarity

Files modified:
- common.py: EXTRA_VALUES -> EXTRA_SIDX_COUNT
- compare.py: Updated import
- compute_sparse.py: Renamed loop variables and parameters
- back_allocation.py: Renamed allocation variables
- stream_sparse.py: Renamed stream handling variables
- manager.py: Renamed event loop counter
Add module-level docstrings and detailed function comments explaining:
- FM computation architecture and algorithm flow
- CSR-like sparse storage model for memory efficiency
- Bottom-up level traversal with aggregation and back allocation
- Profile application (per-layer vs cross-layer)
- Back allocation rules and extras handling
- Stream I/O format and parsing state machine

This improves code maintainability by documenting the complex
financial module computation logic.
TECHNICAL.md:
- Detailed CSR-inspired sparse storage format
- Data structure documentation (nodes, compute_idx, extras)
- Complete computation flow with algorithms
- Aggregation and back allocation explanations
- Stream I/O format specification
- Memory management and performance tips
- Debugging guidance

README.md:
- Quick start examples (Python API and CLI)
- Configuration options (allocation rules, net loss, memory)
- Input file requirements
- Output format explanation
- Supported financial terms
- Performance optimization tips
- Troubleshooting guide
- Architecture overview
@sstruzik sstruzik self-assigned this Feb 10, 2026
@sstruzik sstruzik linked an issue Feb 10, 2026 that may be closed by this pull request
5 tasks
@sstruzik sstruzik requested review from Ha-Ree and vinulw February 10, 2026 17:06
@sstruzik sstruzik moved this to Waiting for Review in Oasis Dev Team Tasks Feb 10, 2026
@sambles sambles merged commit 220f087 into main Feb 26, 2026
26 checks passed
@sambles sambles deleted the refactor/fmpy-naming-conventions branch February 26, 2026 09:59
@github-project-automation github-project-automation bot moved this from Waiting for Review to Done in Oasis Dev Team Tasks Feb 26, 2026
@sambles sambles mentioned this pull request Feb 26, 2026
@awsbuild awsbuild added this to the 2.5.1 milestone Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Improve time and memory performance for big Portfolio

5 participants