feat: Add MCP build_optimization_config tool
Integrate OP2 data extraction with optimization config builder: - Add build_optimization_config() MCP tool - Add list_optimization_options() helper - Add format_optimization_options_for_llm() formatter - Update MCP tools documentation with full API details - Test with bracket example, generates valid config Features: - Discovers design variables from FEA model - Lists 4 available objectives (mass, stress, displacement, volume) - Lists 4 available constraints (stress/displacement/mass limits) - Validates user selections against model - Generates complete optimization_config.json Tested with examples/bracket/Bracket_sim1.sim: - Found 4 design variables (support_angle, tip_thickness, p3, support_blend_radius) - Created config with 2 objectives, 2 constraints, 150 trials 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -53,17 +53,77 @@ python mcp_server/tools/model_discovery.py examples/test_bracket.sim
|
||||
|
||||
---
|
||||
|
||||
### 2. Build Optimization Config (PLANNED)
|
||||
### 2. Build Optimization Config (`optimization_config.py`) ✅ IMPLEMENTED
|
||||
|
||||
**Purpose**: Generate `optimization_config.json` from natural language requirements.
|
||||
**Purpose**: Generate `optimization_config.json` from user selections of objectives, constraints, and design variables.
|
||||
|
||||
**Function**: `build_optimization_config(requirements: str, model_info: Dict) -> Dict[str, Any]`
|
||||
**Functions**:
|
||||
- `build_optimization_config(...)` - Create complete optimization configuration
|
||||
- `list_optimization_options(sim_file_path)` - List all available options for a model
|
||||
- `format_optimization_options_for_llm(options)` - Format options as Markdown
|
||||
|
||||
**Planned Features**:
|
||||
- Parse LLM instructions ("minimize stress while reducing mass")
|
||||
- Select appropriate result extractors
|
||||
- Suggest reasonable parameter bounds
|
||||
- Generate complete config for optimization engine
|
||||
**What it does**:
|
||||
- Discovers available design variables from the FEA model
|
||||
- Lists available objectives (minimize mass, stress, displacement, volume)
|
||||
- Lists available constraints (max stress, max displacement, mass limits)
|
||||
- Builds a complete `optimization_config.json` based on user selections
|
||||
- Validates that all selections are valid for the model
|
||||
|
||||
**Usage Example**:
|
||||
```python
|
||||
from mcp_server.tools import build_optimization_config, list_optimization_options
|
||||
|
||||
# Step 1: List available options
|
||||
options = list_optimization_options("examples/bracket/Bracket_sim1.sim")
|
||||
print(f"Available design variables: {len(options['available_design_variables'])}")
|
||||
|
||||
# Step 2: Build configuration
|
||||
result = build_optimization_config(
|
||||
sim_file_path="examples/bracket/Bracket_sim1.sim",
|
||||
design_variables=[
|
||||
{'name': 'tip_thickness', 'lower_bound': 15.0, 'upper_bound': 25.0},
|
||||
{'name': 'support_angle', 'lower_bound': 20.0, 'upper_bound': 40.0}
|
||||
],
|
||||
objectives=[
|
||||
{'objective_key': 'minimize_mass', 'weight': 5.0},
|
||||
{'objective_key': 'minimize_max_stress', 'weight': 10.0}
|
||||
],
|
||||
constraints=[
|
||||
{'constraint_key': 'max_displacement_limit', 'limit_value': 1.0},
|
||||
{'constraint_key': 'max_stress_limit', 'limit_value': 200.0}
|
||||
],
|
||||
optimization_settings={
|
||||
'n_trials': 150,
|
||||
'sampler': 'TPE'
|
||||
}
|
||||
)
|
||||
|
||||
if result['status'] == 'success':
|
||||
print(f"Config saved to: {result['config_file']}")
|
||||
```
|
||||
|
||||
**Command Line Usage**:
|
||||
```bash
|
||||
python mcp_server/tools/optimization_config.py examples/bracket/Bracket_sim1.sim
|
||||
```
|
||||
|
||||
**Available Objectives**:
|
||||
- `minimize_mass`: Minimize total mass (weight reduction)
|
||||
- `minimize_max_stress`: Minimize maximum von Mises stress
|
||||
- `minimize_max_displacement`: Minimize maximum displacement (increase stiffness)
|
||||
- `minimize_volume`: Minimize total volume (material usage)
|
||||
|
||||
**Available Constraints**:
|
||||
- `max_stress_limit`: Maximum allowable von Mises stress
|
||||
- `max_displacement_limit`: Maximum allowable displacement
|
||||
- `min_mass_limit`: Minimum required mass (structural integrity)
|
||||
- `max_mass_limit`: Maximum allowable mass (weight budget)
|
||||
|
||||
**Output**: Creates `optimization_config.json` with:
|
||||
- Design variable definitions with bounds
|
||||
- Multi-objective configuration with weights
|
||||
- Constraint definitions with limits
|
||||
- Optimization algorithm settings (trials, sampler)
|
||||
|
||||
---
|
||||
|
||||
@@ -218,4 +278,4 @@ These tools are designed to be called by the MCP server and consumed by LLMs. Th
|
||||
---
|
||||
|
||||
**Last Updated**: 2025-11-15
|
||||
**Status**: Phase 1 (Model Discovery) ✅ COMPLETE
|
||||
**Status**: Phase 1 (Model Discovery) ✅ COMPLETE | Phase 2 (Optimization Config Builder) ✅ COMPLETE
|
||||
|
||||
Reference in New Issue
Block a user