- Restructure docs/ folder (remove numeric prefixes): - 04_USER_GUIDES -> guides/ - 05_API_REFERENCE -> api/ - 06_PHYSICS -> physics/ - 07_DEVELOPMENT -> development/ - 08_ARCHIVE -> archive/ - 09_DIAGRAMS -> diagrams/ - Replace tagline 'Talk, don't click' with 'LLM-driven optimization framework' in 9 files - Create comprehensive docs/GETTING_STARTED.md: - Prerequisites and quick setup - Project structure overview - First study tutorial (Claude or manual) - Dashboard usage guide - Neural acceleration introduction - Rewrite docs/00_INDEX.md with correct paths and modern structure - Archive obsolete files: - 01_PROTOCOLS.md -> archive/historical/01_PROTOCOLS_legacy.md - 03_GETTING_STARTED.md -> archive/historical/ - ATOMIZER_PODCAST_BRIEFING.md -> archive/marketing/ - Update timestamps to 2026-01-20 across all key files - Update .gitignore to exclude docs/generated/ - Version bump: ATOMIZER_CONTEXT v1.8 -> v2.0
10 KiB
Phase 3.2 Integration Status
Date: 2025-11-17 Status: Partially Complete - Framework Ready, API Integration Pending
Overview
Phase 3.2 aims to integrate the LLM components (Phases 2.5-3.1) into the production optimization workflow, enabling users to run optimizations using natural language requests.
Goal: Enable users to run:
python run_optimization.py --llm "maximize displacement, ensure safety factor > 4"
What's Been Completed ✅
1. Generic Optimization Runner (optimization_engine/run_optimization.py)
Created: 2025-11-17
A flexible, command-line driven optimization runner supporting both LLM and manual modes:
# LLM Mode (Natural Language)
python optimization_engine/run_optimization.py \
--llm "maximize displacement, ensure safety factor > 4" \
--prt model/Bracket.prt \
--sim model/Bracket_sim1.sim \
--trials 20
# Manual Mode (JSON Config)
python optimization_engine/run_optimization.py \
--config config.json \
--prt model/Bracket.prt \
--sim model/Bracket_sim1.sim \
--trials 50
Features:
- ✅ Command-line argument parsing (
--llm,--config,--prt,--sim, etc.) - ✅ Integration with
LLMWorkflowAnalyzerfor natural language parsing - ✅ Integration with
LLMOptimizationRunnerfor automated extractor/hook generation - ✅ Proper error handling and user feedback
- ✅ Comprehensive help message with examples
- ✅ Flexible output directory and study naming
Files:
- optimization_engine/run_optimization.py - Generic runner
- tests/test_phase_3_2_llm_mode.py - Integration tests
2. Test Suite
Test Results: ✅ All tests passing
Tests verify:
- Argument parsing works correctly
- Help message displays
--llmflag - Framework is ready for LLM integration
Current Limitation ⚠️
LLM Workflow Analysis Requires API Key
The LLMWorkflowAnalyzer currently requires an Anthropic API key to actually parse natural language requests. The use_claude_code flag exists but doesn't implement actual integration with Claude Code's AI capabilities.
Current Behavior:
--llmmode is implemented in the CLI- But
LLMWorkflowAnalyzer.analyze_request()returns empty workflow whenuse_claude_code=Trueand no API key provided - Actual LLM analysis requires
--api-keyargument
Workaround Options:
Option 1: Use Anthropic API Key
python run_optimization.py \
--llm "maximize displacement" \
--prt model/part.prt \
--sim model/sim.sim \
--api-key "sk-ant-..."
Option 2: Pre-Generate Workflow JSON (Hybrid Approach)
- Use Claude Code to help create workflow JSON manually
- Save as
llm_workflow.json - Load and use with
LLMOptimizationRunner
Example:
# In your study's run_optimization.py
from optimization_engine.llm_optimization_runner import LLMOptimizationRunner
import json
# Load pre-generated workflow (created with Claude Code assistance)
with open('llm_workflow.json', 'r') as f:
llm_workflow = json.load(f)
# Run optimization with LLM runner
runner = LLMOptimizationRunner(
llm_workflow=llm_workflow,
model_updater=model_updater,
simulation_runner=simulation_runner,
study_name='my_study'
)
results = runner.run_optimization(n_trials=20)
Option 3: Use Existing Study Scripts
The bracket study's run_optimization.py already demonstrates the complete workflow with hardcoded configuration - this works perfectly!
Architecture
LLM Mode Flow (When API Key Provided)
User Natural Language Request
↓
LLMWorkflowAnalyzer (Phase 2.7)
├─> Claude API call
└─> Parse to structured workflow JSON
↓
LLMOptimizationRunner (Phase 3.2)
├─> ExtractorOrchestrator (Phase 3.1) → Auto-generate extractors
├─> InlineCodeGenerator (Phase 2.8) → Auto-generate calculations
├─> HookGenerator (Phase 2.9) → Auto-generate hooks
└─> Run Optuna optimization with generated code
↓
Results
Manual Mode Flow (Current Working Approach)
Hardcoded Workflow JSON (or manually created)
↓
LLMOptimizationRunner (Phase 3.2)
├─> ExtractorOrchestrator → Auto-generate extractors
├─> InlineCodeGenerator → Auto-generate calculations
├─> HookGenerator → Auto-generate hooks
└─> Run Optuna optimization
↓
Results
What Works Right Now
✅ LLM Components are Functional
All individual components work and are tested:
- Phase 2.5: Intelligent Gap Detection ✅
- Phase 2.7: LLM Workflow Analysis (requires API key) ✅
- Phase 2.8: Inline Code Generator ✅
- Phase 2.9: Hook Generator ✅
- Phase 3.0: pyNastran Research Agent ✅
- Phase 3.1: Extractor Orchestrator ✅
- Phase 3.2: LLM Optimization Runner ✅
✅ Generic CLI Runner
The new run_optimization.py provides:
- Clean command-line interface
- Argument validation
- Error handling
- Comprehensive help
✅ Bracket Study Demonstrates End-to-End Workflow
studies/bracket_displacement_maximizing/run_optimization.py shows the complete integration:
- Wizard-based setup (Phase 3.3)
- LLMOptimizationRunner with hardcoded workflow
- Auto-generated extractors and hooks
- Real NX simulations
- Complete results with reports
Next Steps to Complete Phase 3.2
Short Term (Can Do Now)
-
Document Hybrid Approach ✅ (This document!)
- Show how to use Claude Code to create workflow JSON
- Example workflow JSON templates for common use cases
-
Create Example Workflow JSONs
examples/llm_workflows/maximize_displacement.jsonexamples/llm_workflows/minimize_stress.jsonexamples/llm_workflows/multi_objective.json
-
Update DEVELOPMENT_GUIDANCE.md
- Mark Phase 3.2 as "Partially Complete"
- Document the API key requirement
- Provide hybrid approach guidance
Medium Term (Requires Decision)
Option A: Implement True Claude Code Integration
- Modify
LLMWorkflowAnalyzerto actually interface with Claude Code - Would require understanding Claude Code's internal API/skill system
- Most aligned with "Development Strategy" (use Claude Code, defer API integration)
Option B: Defer Until API Integration is Priority
- Document current state as "Framework Ready"
- Focus on other high-priority items (NXOpen docs, Engineering pipeline)
- Return to full LLM integration when ready to integrate Anthropic API
Option C: Hybrid Approach (Recommended for Now)
- Keep generic CLI runner as-is
- Document how to use Claude Code to manually create workflow JSONs
- Use
LLMOptimizationRunnerwith pre-generated workflows - Provides 90% of the value with 10% of the complexity
Recommendation
For now, adopt Option C (Hybrid Approach):
Why:
- Development Strategy Alignment: We're using Claude Code for development, not integrating API yet
- Provides Value: All automation components (extractors, hooks, calculations) work perfectly
- No Blocker: Users can still leverage LLM components via pre-generated workflows
- Flexible: Can add full API integration later without changing architecture
- Focus: Allows us to prioritize Phase 3.3+ items (NXOpen docs, Engineering pipeline)
What This Means:
- ✅ Phase 3.2 is "Framework Complete"
- ⚠️ Full natural language CLI requires API key (documented limitation)
- ✅ Hybrid approach (Claude Code → JSON → LLMOptimizationRunner) works today
- 🎯 Can return to full integration when API integration becomes priority
Example: Using Hybrid Approach
Step 1: Create Workflow JSON (with Claude Code assistance)
{
"engineering_features": [
{
"action": "extract_displacement",
"domain": "result_extraction",
"description": "Extract displacement results from OP2 file",
"params": {"result_type": "displacement"}
},
{
"action": "extract_solid_stress",
"domain": "result_extraction",
"description": "Extract von Mises stress from CTETRA elements",
"params": {
"result_type": "stress",
"element_type": "ctetra"
}
}
],
"inline_calculations": [
{
"action": "calculate_safety_factor",
"params": {
"input": "max_von_mises",
"yield_strength": 276.0,
"operation": "divide"
},
"code_hint": "safety_factor = 276.0 / max_von_mises"
}
],
"post_processing_hooks": [],
"optimization": {
"algorithm": "TPE",
"direction": "minimize",
"design_variables": [
{
"parameter": "thickness",
"min": 3.0,
"max": 10.0,
"units": "mm"
}
]
}
}
Step 2: Use in Python Script
import json
from pathlib import Path
from optimization_engine.llm_optimization_runner import LLMOptimizationRunner
from optimization_engine.nx_updater import NXParameterUpdater
from optimization_engine.nx_solver import NXSolver
# Load pre-generated workflow
with open('llm_workflow.json', 'r') as f:
workflow = json.load(f)
# Setup model updater
updater = NXParameterUpdater(prt_file_path=Path("model/part.prt"))
def model_updater(design_vars):
updater.update_expressions(design_vars)
updater.save()
# Setup simulation runner
solver = NXSolver(nastran_version='2412', use_journal=True)
def simulation_runner(design_vars) -> Path:
result = solver.run_simulation(Path("model/sim.sim"), expression_updates=design_vars)
return result['op2_file']
# Run optimization
runner = LLMOptimizationRunner(
llm_workflow=workflow,
model_updater=model_updater,
simulation_runner=simulation_runner,
study_name='my_optimization'
)
results = runner.run_optimization(n_trials=20)
print(f"Best design: {results['best_params']}")
References
- DEVELOPMENT_GUIDANCE.md - Strategic direction
- optimization_engine/run_optimization.py - Generic CLI runner
- optimization_engine/llm_optimization_runner.py - LLM runner
- optimization_engine/llm_workflow_analyzer.py - Workflow analyzer
- studies/bracket_displacement_maximizing/run_optimization.py - Complete example
Document Maintained By: Antoine Letarte Last Updated: 2025-11-17 Status: Framework Complete, API Integration Pending