feat: Implement Phase 1 - Plugin & Hook System
Core plugin architecture for LLM-driven optimization: New Features: - Hook system with 6 lifecycle points (pre_mesh, post_mesh, pre_solve, post_solve, post_extraction, custom_objectives) - HookManager for centralized registration and execution - Code validation with AST-based safety checks - Feature registry (JSON) for LLM capability discovery - Example plugin: log_trial_start - 23 comprehensive tests (all passing) Integration: - OptimizationRunner now loads plugins automatically - Hooks execute at 5 points in optimization loop - Custom objectives can override total_objective via hooks Safety: - Module whitelist (numpy, scipy, pandas, optuna, pyNastran) - Dangerous operation blocking (eval, exec, os.system, subprocess) - Optional file operation permission flag Files Added: - optimization_engine/plugins/__init__.py - optimization_engine/plugins/hooks.py - optimization_engine/plugins/hook_manager.py - optimization_engine/plugins/validators.py - optimization_engine/feature_registry.json - optimization_engine/plugins/pre_solve/log_trial_start.py - tests/test_plugin_system.py (23 tests) Files Modified: - optimization_engine/runner.py (added hook integration) Ready for Phase 2: LLM interface layer 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
32
optimization_engine/plugins/__init__.py
Normal file
32
optimization_engine/plugins/__init__.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
Atomizer Plugin System
|
||||
|
||||
Enables extensibility through hooks at various stages of the optimization lifecycle.
|
||||
|
||||
Hook Points:
|
||||
- pre_mesh: Before meshing operations
|
||||
- post_mesh: After meshing, before solve
|
||||
- pre_solve: Before solver execution
|
||||
- post_solve: After solve, before result extraction
|
||||
- post_extraction: After result extraction, before objective calculation
|
||||
- custom_objectives: Custom objective/constraint functions
|
||||
|
||||
Usage:
|
||||
from optimization_engine.plugins import HookManager
|
||||
|
||||
hook_manager = HookManager()
|
||||
hook_manager.register_hook('pre_solve', my_custom_function)
|
||||
hook_manager.execute_hooks('pre_solve', context={'trial_number': 5})
|
||||
"""
|
||||
|
||||
from .hooks import Hook, HookPoint
|
||||
from .hook_manager import HookManager
|
||||
from .validators import validate_plugin_code, PluginValidationError
|
||||
|
||||
__all__ = [
|
||||
'Hook',
|
||||
'HookPoint',
|
||||
'HookManager',
|
||||
'validate_plugin_code',
|
||||
'PluginValidationError'
|
||||
]
|
||||
Reference in New Issue
Block a user