This document outlines the plan to refactor the src/structure_net/evolution/ directory into a modular, component-based architecture as described in docs/New Componentwise refactoring.md.
The first and most critical step is to break apart the large, monolithic files into smaller, more focused components that align with the new architecture.
-
Create
componentsDirectory: Create the new target directory:src/structure_net/components/. Inside, create subdirectories for each component type:metrics,analyzers,strategies,evolvers,schedulers, andorchestrators. -
De-Monolith
adaptive_learning_rates: This is the most urgent task. Theadaptive_learning_rates.pyfile is a massive, deprecated monolith.- Create new files inside
src/structure_net/components/schedulers/for each distinct scheduler type (e.g.,phase_schedulers.py,layer_schedulers.py). - Move the corresponding classes (
ExtremaPhaseScheduler,LayerAgeAwareLR, etc.) from the old files into these new, focused files. - Refactor each moved class to inherit from
BaseScheduler(or a more specific base likeBasePhaseScheduler) and implement theIComponentcontract.
- Create new files inside
-
De-Monolith
metrics: The various metric analysis files (mutual_information.py,activity_analysis.py, etc.) will be split according to the guide.- Low-level measurements will become individual
IMetriccomponents insrc/structure_net/components/metrics/. For example,mutual_information.pywill be split intoLayerMIMetric,EntropyMetric, etc. - High-level analysis logic will be moved into
IAnalyzercomponents insrc/structure_net/components/analyzers/. For example, the logic for combining MI and entropy to find bottlenecks will go into anInformationFlowAnalyzer.
- Low-level measurements will become individual
-
De-Monolith
evolutionComponents:- The
ExtremaGrowthStrategyand other strategies fromcomponents/strategies.pywill be moved tosrc/structure_net/components/strategies/. - The
OptimalGrowthEvolverfromnetwork_evolver.pywill be refactored into one or moreIEvolvercomponents insrc/structure_net/components/evolvers/.
- The
For each newly created component file from Phase 1, perform the following "contract implementation" steps:
- Inherit from Base: Ensure each class inherits from the correct base component (e.g.,
BaseMetric,BaseAnalyzer,BaseStrategy). - Implement
contractProperty: Add the@property def contract(self) -> ComponentContract:method to each class. - Define the Contract: Inside the
contractproperty, meticulously define:component_name,version, andmaturity.required_inputs: What data does this component need from theEvolutionContextorAnalysisReport? (e.g.,{"metrics.activity", "model"}).provided_outputs: What data does this component produce? (e.g.,{"analyzers.extrema_report"}).resources: Estimate theResourceRequirements.
- Refactor
apply/analyzeMethods: Refactor the core logic of each component to work with the newEvolutionContextandAnalysisReportdata structures, ensuring they consume theirrequired_inputsand produce theirprovided_outputs.
Once the individual components are created and conform to their contracts, build the systems that use them.
- Create
MetricsOrchestrator: Create a newMetricsOrchestratorinsrc/structure_net/components/orchestrators/. This class will replace the oldCompleteMetricsSystem. Its job will be to run a list ofIMetriccomponents and assemble the results into a comprehensiveAnalysisReport. - Create
EvolutionOrchestrator: This will be the main engine. It will take a list ofIAnalyzer,IStrategy, andIEvolvercomponents. Itsrun_cyclemethod will execute the full evolution loop as described in the guide. - Update
adaptive_learning_ratesManager: TheAdaptiveLearningRateManagerwill be refactored into anIOrchestratorthat specifically manages a collection ofISchedulercomponents.
- Add Deprecation Warnings: Go through all the old, now-monolithic files in
src/structure_net/evolution/and add clearDeprecationWarnings at the top, pointing to the new component locations. - Update
__init__.pyFiles: Update the__init__.pyfiles to ensure they still provide the old classes for backward compatibility, but also issue warnings. - Final Review: Do a final pass to ensure all old files are properly marked and the new component system is the clearly recommended path forward.