Step-by-Step Refactoring Plan for NTSim
Phase 1: Preparation and Git Organization
-
Set Up Git Branching and Initial State
-
Create Release Tag: Tag the current stable version of
ntsim_2.py(e.g.,v0.0.9) so we can always reference or revert to it if needed. -
Create Feature Branches:
- For each feature, create a new branch. The naming convention could be:
dvn/feature/<feature-name>for userdvnand updated appropriately for other users. - Example branches:
dvn/feature/config-refactordvn/feature/argument-parser-modularizationdvn/feature/simulation-split
- For each feature, create a new branch. The naming convention could be:
-
Create Release Tag: Tag the current stable version of
-
Set Up Continuous Integration (CI)
- Use GitHub Actions (or another CI platform) to run unit tests and style checks (
flake8,black, anything else?). - Create a simple workflow to run tests on push or pull requests to any feature branch.
- Use GitHub Actions (or another CI platform) to run unit tests and style checks (
Phase 2: Refactor Argument Handling and Configuration
-
Refactor Argument Parsing (Feature Branch:
dvn/feature/argument-parser-modularization)-
Create a New Script: Create
ntsim.pyas a fresh starting point. -
Move Argument Parsing to
ntsim_arguments.py:- Split argument parsing into a standalone module.
- Use
configargparsebut enhance it with config file support. Allow users to provide a YAML/JSON configuration.
-
Introduce a Configuration File:
- Provide a default configuration file (
ntsim.yaml) that can be customized. - Modify
ntsim.pyto load settings from the configuration file first, then override with command-line arguments if provided.
- Provide a default configuration file (
-
Create a New Script: Create
-
Refactor Initialization Logic (Feature Branch:
dvn/feature/config-refactor)- Create a configuration management class (
NTSimConfig) to handle all the configurations. -
Goals:
- Centralize all configuration in one place.
- Reduce the use of direct references to
optsacross the script. - Ensure the command-line interface can override configuration settings.
- Create a configuration management class (
Phase 3: Refactor NTSim Class and Split Responsibilities
-
Split
NTSimResponsibilities (Feature Branch:dvn/feature/simulation-split)- Break down the large responsibilities of the
NTSimclass into multiple methods and smaller classes:- NTSimArgumentParser: Handle all argument parsing.
- NTSimConfigurator: Responsible for reading the configuration, setting up dependencies, and initializing objects.
- NTSimSimulator: Focus purely on the simulation logic.
- NTSimWriter: Handle all file writing and logging.
-
Action Steps:
- Extract methods from
process(). - Move
configure()logic toNTSimConfigurator. - Create clean, readable methods for event initialization, particle simulation, photon propagation, etc.
- Extract methods from
-
Deliverables:
- Each class or function has a single responsibility.
- Each method is easily testable in isolation.
- Break down the large responsibilities of the
-
Introduce Modular Factories (Feature Branch:
dvn/feature/factory-improvements)- Refactor Factories: Update the current Factory classes so that dependencies are instantiated dynamically.
-
Blueprint Handling: Avoid the dual usage of terms like "Blueprint." Consider using clearer terms like
ConfigTemplatevs.Instance.
Phase 4: Simplify Package Management & Installation
-
Package and Module Management (Feature Branch:
dvn/feature/package-management)-
Optional Installation:
- Update
pyproject.tomlto include optional installations:Users should be able to run[project.optional_dependencies] generator-neutrino-ava = "nupropagator>=0.0.2" # or generator-neutrino-ava = ["nupropagator @ git@git.jinr.ru:ava/nupropogator.git"] telescope-baikal = ["baikal-model @ git@git.jinr.ru:Baikal/bgvd-model.git"]pip install ntsim[telescope-baikal]or topip install ntsim[generator-neutrino-ava]install optional dependencies.
- Update
-
Interactive Welcome Mode:
- Implement a welcome feature in
ntsim.pyto display available configurations based on installed packages. -
Optional Dependency Installer: Add a utility that informs the user which optional dependencies are missing and offers the necessary
pip installcommand.
- Implement a welcome feature in
-
Optional Installation:
-
Installation Verification (Feature Branch:
dvn/feature/installation-check)-
Add Diagnostic Script (
ntsim_check.py):- This script checks the current environment for missing dependencies.
- Print a summary with steps to install any missing components.
-
Post-Installation Report:
- Add a post-installation success message summarizing the status of optional components.
-
Add Diagnostic Script (
Phase 5: Testing & Verification
-
Implement Unit Tests for Core Components (Feature Branch:
dvn/feature/unit-testing)- Create tests for individual classes:
-
Configuration Parsing: Verify
NTSimConfigcorrectly reads and overrides settings. -
Factory Modules: Test each Factory’s
get_blueprint()andconfigure()methods. -
Simulation Methods: Test components of
process(), especially the refactored methods likesimulate_particles(),simulate_photons().
-
Configuration Parsing: Verify
- Add test cases for:
- Edge Scenarios: Such as missing dependencies or misconfigured inputs.
- Optional Dependencies: Test welcome mode behavior based on installed components.
- Create tests for individual classes:
-
End-to-End Testing (Feature Branch:
dvn/feature/e2e-testing)- Set up tests to run complete simulations, validate the output, and check for correctness and consistency.
- Use the
tqdmsimulation loops and validate progress and logging consistency.
Phase 6: Documentation & User Interface
-
Update Documentation (Feature Branch:
dvn/feature/documentation)- Update the README.md to reflect new setup methods and modular installations.
- Write user guides for:
-
Installing Different Modes
-
welcome(minimal possible informing the user what is available and what could be installed) -
baikal-gvd(install all data and models for GVD), -
generator-neutrino(ava,nugen,proposal,all), -
generator-muon(Corsika, ...) - ...
-
- Using the New Configuration System: Include examples of YAML/JSON config.
-
Installing Different Modes
- Write a Developer Guide on contributing to
ntsim, focusing on how to use feature branches and how to run tests.
-
User-Friendly Logging & CLI Improvements (Feature Branch:
dvn/feature/logging-improvements)- Improve logging:
- Refactor logging configurations to be more modular (
ntsim_logging.py). - Add detailed log levels to track progress in different parts of the simulation (
INFO,DEBUG,WARNING).
- Refactor logging configurations to be more modular (
-
Command-Line Interface:
- Shorten the command-line usage by leveraging the configuration file.
- Provide meaningful error messages if required arguments are missing or incorrectly formatted.
- Improve logging:
Phase 7: Final Release & Feedback Collection
-
Prepare for Release (Feature Branch:
dvn/feature/release-preparation)- Ensure all feature branches are merged into
main. - Tag a new release version (
v0.1-beta). - Include release notes summarizing major refactoring steps, new features, and breaking changes.
- Ensure all feature branches are merged into
-
User Feedback & Iteration
- Release to a subset of users for beta testing.
- Gather feedback on:
- Ease of Use: Are the new configurations and installations user-friendly?
- Performance: Does the refactored code maintain or improve simulation times?
- Prioritize bug fixes and minor enhancements based on feedback.