Skip to content

Refactor/scaffold#106

Merged
ryanmccann1024 merged 82 commits intorelease/6.0.0from
refactor/scaffold
Aug 13, 2025
Merged

Refactor/scaffold#106
ryanmccann1024 merged 82 commits intorelease/6.0.0from
refactor/scaffold

Conversation

@ryanmccann1024
Copy link
Copy Markdown
Collaborator

@ryanmccann1024 ryanmccann1024 commented Jul 23, 2025

📝 Description

This pull request completes a comprehensive refactor of the FUSION project, addressing code quality, architectural improvements, and bug fixes. The changes build upon the previous CLI architectural refactor and focus on stabilizing the codebase while removing deprecated functionality.

Key Changes:

🔧 Code Quality & Bug Fixes

  • Fixed critical metrics processing issues: Resolved duplicate link processing, division by zero errors, and normalization problems in the metrics module
  • Resolved RL workflow issues: Fixed environment reset logic that was causing unnecessary resets after trial completion
  • Fixed all pylint violations: Cleaned up import organization, removed unused parameters, and improved code structure in test files

🧹 Code Cleanup & Maintenance

  • Removed deprecated run scripts: Eliminated run_gui.py, run_ml_sim.py, run_rl_sim.py, and run_sim.py as these have been fully replaced by the new CLI structure
  • Improved test structure: Refactored test comparison script to follow better patterns with extracted helper functions
  • Enhanced code organization: Moved imports to proper locations and eliminated code duplication

🏗️ Architectural Improvements

  • Consolidated CLI functionality: All application entry points now use the unified fusion CLI structure
  • Improved modularity: Enhanced separation of concerns in metrics processing and RL workflows
  • Better error handling: Added safeguards for edge cases in statistical calculations

Fixes: Issues with code quality violations and deprecated script usage


🧐 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 💅 UI/UX change (improves the user interface or experience)
  • 📚 Documentation update
  • ⚙️ Chore (refactoring, dependency updates, etc.)

💥 Impact of Breaking Change

This PR contains moderate breaking changes related to the removal of deprecated scripts.

What will stop working?

  • Direct execution of the removed run scripts (run_gui.py, run_ml_sim.py, run_rl_sim.py, run_sim.py) will no longer work
  • Any external automation or scripts that directly invoke these files will fail

Migration Path for Users:

  • For simulation runs: Use python -m fusion.cli run_sim instead of python run_sim.py
  • For RL training: Use python -m fusion.cli train instead of python run_rl_sim.py
  • For GUI: Use python -m fusion.cli gui instead of python run_gui.py
  • For ML workflows: Use the appropriate fusion CLI commands for ML functionality

All core functionality remains available through the unified CLI interface.

🧪 How Has This Been Tested?

Code Quality Validation

  • Pylint compliance: All pylint errors in tests/run_comparison.py have been resolved
  • Import organization: Verified all imports are properly organized at module top-level
  • Function structure: Extracted helper functions to improve readability and maintainability

Functional Testing

  • Metrics processing: Validated that duplicate processing fixes don't break existing functionality
  • RL workflows: Confirmed environment reset logic works correctly for multi-trial scenarios
  • Test suite: All existing tests continue to pass with the refactored code structure

Integration Testing

  • CLI functionality: Verified that all removed script functionality is accessible through CLI
  • Configuration loading: Confirmed config loading works correctly with the new structure
  • Module imports: Validated that all internal imports use correct new paths

Test Configuration:

  • Operating System: MacOS
  • Python version: 3.11+
  • Dependencies: All existing project dependencies maintained

📈 Performance Impact

  • Improved efficiency: Fixed duplicate processing in metrics reduces computational overhead
  • Memory optimization: Eliminated redundant data processing and normalization
  • Code maintenance: Cleaner code structure improves development velocity

🔍 Code Review Focus Areas

  • Verify metrics calculations produce expected results
  • Confirm RL environment reset logic works for various trial configurations
  • Check that CLI provides equivalent functionality to removed scripts
  • Validate import organization follows project standards
  • Review extracted helper functions for clarity and reusability

✅ Final Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (removed deprecated scripts)
  • My changes generate no new warnings (pylint violations resolved)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked that my commit message follows the project's formatting guidelines
  • Breaking changes are documented and migration path is provided
  • Deprecated functionality has been properly removed

📋 Additional Notes

This PR represents the completion of the architectural refactor phase, focusing on code quality and stability. The removal of deprecated scripts finalizes the transition to the unified CLI architecture, providing a cleaner and more maintainable codebase for future development.

The metrics fixes address several edge cases that could cause runtime errors in production scenarios, particularly around division by zero and duplicate data processing. The RL workflow improvements ensure more robust training procedures.

- Moved all argument registration scripts from arg_scripts/ to fusion/cli/args/
  - config_args.py → run_sim_args.py
  - parse_args.py → main_parser.py
  - setup_config.py → config_setup.py
- Added __init__.py to cli/ and cli/args/ with docstrings and import structure
- Deleted legacy arg_scripts/ directory
- Established CLI entrypoint structure for run_sim.py, run_train.py, run_gui.py (empty or stubbed for now)
- Ready for Phase 1 test coverage: CLI parsing, config resolution
- Replaced legacy flat argument parsing with subcommand-based parser
- Implemented register_run_sim_args to handle all COMMAND_LINE_PARAMS under 'run_sim'
- Stubbed setup_config_from_cli to return vars(args) for now
- Verified that parsed CLI args pass through to config successfully
- Commented out unimplemented CLI modules in cli/args/__init__.py
- Validated CLI end-to-end via: python -m fusion.cli.run_sim run_sim --erlang_start 100 --run_id test123
- Moved NetworkSimulator into fusion/sim/network_simulator.py
- Updated imports (e.g., src.engine → fusion.core.engine)
- Updated CLI run_sim.py to use new run_simulation entrypoint
- Connected build_parser → setup_config → run_simulation
- Added print to confirm parsed config
- Early test run parsing support
- Integrated argparse-based command parsing into fusion.cli.run_sim
- Fixed config loading for INI files using setup_config_from_cli()
- Added support for relative and user-specified config paths
- Ensured proper simulation launch via fusion.sim.run_simulation()
- Verified successful end-to-end execution with parsed config
- Integrated multiprocessing.Event() to support graceful shutdowns
- Updated fusion/cli/run_sim.py to create and pass stop_flag to simulation runner
- Ensures clean process termination and future compatibility with GUI/interactive use
- Updated `create_input()` and `save_input()` in setup_helpers.py to resolve all paths via PROJECT_ROOT
- Prevented accidental writes to cli/data by enforcing top-level FUSION/data/
- Ensured proper file flushing and syncing for input JSON reliability
- Added fallback logic to find project root via .git or run_sim.py
- Consolidated training CLI through run_train.py to support both RL and ML pipelines.
- Introduced ConfigManager in fusion/cli/config_setup.py for centralized configuration loading and parsing.
- Added modular argument parsing functions (e.g., add_run_sim_args, add_routing_args, etc.) in the CLI args modules.
- Stubbed train_pipeline.py (RL) and ml_pipeline.py (ML) to verify proper dispatch based on agent type.
- Ensured multi-threaded config support (e.g., s1, s2 sections) is maintained across pipelines.
- Replaced legacy CLI logic in run_gui.py with standardized main_parser and ConfigManager usage.
- Added gui_args.py with support for --config_path and --run_id flags.
- Stubbed launch_gui() in fusion/gui/runner.py for future GUI logic integration.
- Verified end-to-end CLI parsing, config validation, and stub dispatch.
@ryanmccann1024 ryanmccann1024 requested a review from bozo-bud July 23, 2025 19:01
@ryanmccann1024
Copy link
Copy Markdown
Collaborator Author

ryanmccann1024 commented Aug 7, 2025

This Unit Test passes locally, interesting. Any ideas @bozo-bud ?

@bozo-bud
Copy link
Copy Markdown
Contributor

bozo-bud commented Aug 7, 2025

I think test get start time has an issue where the times will sometimes not match. I haven't been able to replicate it or get it to happen consistently though.

@ryanmccann1024
Copy link
Copy Markdown
Collaborator Author

This could either be a fluke or the error that happens on Unity at times. If a user submits hundreds of jobs sometimes they write over each other...

Maybe there is a start time consistency issue

ryanmccann1024 and others added 5 commits August 7, 2025 11:46
The RL pipeline is not working properly with the new refactor including:

- Input/Output results
- Config files
…/scaffold

# Conflicts:
#	fusion/helper_scripts/sim_helpers.py
Moved files to more scalable directories. Changed naming conventions to be more consistent and readable.
Broke up multi-class files into multiple single class files. Added skeleton files for future refactor.
@ryanmccann1024
Copy link
Copy Markdown
Collaborator Author

The failure is on the pull request target and passes on this PR.

Will ignore for now.

ryanmccann1024 and others added 4 commits August 13, 2025 10:34
- Prevent duplicate link processing in _get_link_usage_summary
- Fix division by zero in bit_rate_blocking_prob calculation
- Prevent duplicate modulation statistics processing
- Add safeguards for block_reasons_dict normalization
- Improve debug logging and code formatting

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Only reset environment if trials are not yet completed
- Prevents unnecessary resets after all trials are finished

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Move all imports to top level to resolve import-outside-toplevel warnings
- Remove unused 'is_testing' parameter from run_rl_simulation function
- Extract helper functions to reduce statement count in _run_single_case
- Resolve all reimport and unused-import warnings

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove run_gui.py, run_ml_sim.py, run_rl_sim.py, and run_sim.py
- These scripts have been replaced by the new CLI structure
- Functionality has been migrated to fusion module

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ryanmccann1024 ryanmccann1024 merged commit c450fbb into release/6.0.0 Aug 13, 2025
12 checks passed
ryanmccann1024 added a commit that referenced this pull request Aug 14, 2025
@ryanmccann1024 ryanmccann1024 deleted the refactor/scaffold branch January 19, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants