2025-11-16 13:35:41 -05:00
"""
Test Phase 2.5 with CBUSH Element Stiffness Optimization Request
Tests the intelligent gap detection with a 1 D element force optimization request .
"""
import sys
from pathlib import Path
project_root = Path ( __file__ ) . parent . parent
sys . path . insert ( 0 , str ( project_root ) )
refactor: Major reorganization of optimization_engine module structure
BREAKING CHANGE: Module paths have been reorganized for better maintainability.
Backwards compatibility aliases with deprecation warnings are provided.
New Structure:
- core/ - Optimization runners (runner, intelligent_optimizer, etc.)
- processors/ - Data processing
- surrogates/ - Neural network surrogates
- nx/ - NX/Nastran integration (solver, updater, session_manager)
- study/ - Study management (creator, wizard, state, reset)
- reporting/ - Reports and analysis (visualizer, report_generator)
- config/ - Configuration management (manager, builder)
- utils/ - Utilities (logger, auto_doc, etc.)
- future/ - Research/experimental code
Migration:
- ~200 import changes across 125 files
- All __init__.py files use lazy loading to avoid circular imports
- Backwards compatibility layer supports old import paths with warnings
- All existing functionality preserved
To migrate existing code:
OLD: from optimization_engine.nx_solver import NXSolver
NEW: from optimization_engine.nx.solver import NXSolver
OLD: from optimization_engine.runner import OptimizationRunner
NEW: from optimization_engine.core.runner import OptimizationRunner
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 12:30:59 -05:00
from optimization_engine . utils . codebase_analyzer import CodebaseCapabilityAnalyzer
from optimization_engine . future . workflow_decomposer import WorkflowDecomposer
from optimization_engine . config . capability_matcher import CapabilityMatcher
from optimization_engine . future . targeted_research_planner import TargetedResearchPlanner
2025-11-16 13:35:41 -05:00
def main ( ) :
user_request = """ I want to extract forces in direction Z of all the 1D elements and find the average of it, then find the maximum value and compere it to the average, then assign it to a objective metric that needs to be minimized.
I want to iterate on the FEA properties of the Cbush element stiffness in Z to make the objective function minimized .
I want to use uptuna with TPE to iterate and optimize this """
print ( ' = ' * 80 )
print ( ' PHASE 2.5 TEST: 1D Element Forces Optimization with CBUSH Stiffness ' )
print ( ' = ' * 80 )
print ( )
print ( ' User Request: ' )
print ( user_request )
print ( )
print ( ' = ' * 80 )
print ( )
# Initialize
analyzer = CodebaseCapabilityAnalyzer ( )
decomposer = WorkflowDecomposer ( )
matcher = CapabilityMatcher ( analyzer )
planner = TargetedResearchPlanner ( )
# Step 1: Decompose
print ( ' [1] Decomposing Workflow ' )
print ( ' - ' * 80 )
steps = decomposer . decompose ( user_request )
print ( f ' Identified { len ( steps ) } workflow steps: ' )
print ( )
for i , step in enumerate ( steps , 1 ) :
print ( f ' { i } . { step . action . replace ( " _ " , " " ) . title ( ) } ' )
print ( f ' Domain: { step . domain } ' )
if step . params :
print ( f ' Params: { step . params } ' )
print ( )
# Step 2: Match to capabilities
print ( )
print ( ' [2] Matching to Existing Capabilities ' )
print ( ' - ' * 80 )
match = matcher . match ( steps )
print ( f ' Coverage: { match . coverage : .0% } ( { len ( match . known_steps ) } / { len ( steps ) } steps) ' )
print ( f ' Confidence: { match . overall_confidence : .0% } ' )
print ( )
print ( ' KNOWN Steps (Already Implemented): ' )
for i , known in enumerate ( match . known_steps , 1 ) :
print ( f ' { i } . { known . step . action . replace ( " _ " , " " ) . title ( ) } ( { known . step . domain } ) ' )
if known . implementation != ' unknown ' :
impl_name = Path ( known . implementation ) . name if ( ' \\ ' in known . implementation or ' / ' in known . implementation ) else known . implementation
print ( f ' File: { impl_name } ' )
print ( )
print ( ' MISSING Steps (Need Research): ' )
if match . unknown_steps :
for i , unknown in enumerate ( match . unknown_steps , 1 ) :
print ( f ' { i } . { unknown . step . action . replace ( " _ " , " " ) . title ( ) } ( { unknown . step . domain } ) ' )
print ( f ' Required: { unknown . step . params } ' )
if unknown . similar_capabilities :
similar_str = ' , ' . join ( unknown . similar_capabilities )
print ( f ' Similar to: { similar_str } ' )
print ( f ' Confidence: { unknown . confidence : .0% } (can adapt) ' )
else :
print ( f ' Confidence: { unknown . confidence : .0% } (needs research) ' )
print ( )
else :
print ( ' None - all capabilities are known! ' )
print ( )
# Step 3: Create research plan
print ( )
print ( ' [3] Creating Targeted Research Plan ' )
print ( ' - ' * 80 )
plan = planner . plan ( match )
print ( f ' Research steps needed: { len ( plan ) } ' )
print ( )
if plan :
for i , step in enumerate ( plan , 1 ) :
print ( f ' Step { i } : { step [ " description " ] } ' )
print ( f ' Action: { step [ " action " ] } ' )
details = step . get ( ' details ' , { } )
if ' capability ' in details :
print ( f ' Study: { details [ " capability " ] } ' )
if ' query ' in details :
print ( f ' Query: " { details [ " query " ] } " ' )
print ( f ' Expected confidence: { step [ " expected_confidence " ] : .0% } ' )
print ( )
else :
print ( ' No research needed - all capabilities exist! ' )
print ( )
print ( )
print ( ' = ' * 80 )
print ( ' ANALYSIS SUMMARY ' )
print ( ' = ' * 80 )
print ( )
print ( ' Request Complexity: ' )
print ( ' - Extract forces from 1D elements (Z direction) ' )
print ( ' - Calculate average and maximum forces ' )
print ( ' - Define custom objective metric (max vs avg comparison) ' )
print ( ' - Modify CBUSH element stiffness properties ' )
print ( ' - Optuna TPE optimization ' )
print ( )
print ( f ' System Analysis: ' )
print ( f ' Known capabilities: { len ( match . known_steps ) } / { len ( steps ) } ( { match . coverage : .0% } ) ' )
print ( f ' Missing capabilities: { len ( match . unknown_steps ) } / { len ( steps ) } ' )
print ( f ' Overall confidence: { match . overall_confidence : .0% } ' )
print ( )
if match . unknown_steps :
print ( ' What needs research: ' )
for unknown in match . unknown_steps :
print ( f ' - { unknown . step . action } ( { unknown . step . domain } ) ' )
else :
print ( ' All capabilities already exist in Atomizer! ' )
print ( )
if __name__ == ' __main__ ' :
main ( )