Initial commit: NX OptiMaster project structure
- Set up Python package structure with pyproject.toml - Created MCP server, optimization engine, and NX journals modules - Added configuration templates - Implemented pluggable result extractor architecture - Comprehensive README with architecture overview - Project ready for GitHub push 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
66
optimization_engine/result_extractors/__init__.py
Normal file
66
optimization_engine/result_extractors/__init__.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""
|
||||
Pluggable Result Extractor System
|
||||
|
||||
Base classes and implementations for extracting metrics from FEA results.
|
||||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Dict, Any, Optional
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class ResultExtractor(ABC):
|
||||
"""Base class for all result extractors."""
|
||||
|
||||
@abstractmethod
|
||||
def extract(self, result_files: Dict[str, Path], config: Dict[str, Any]) -> Dict[str, float]:
|
||||
"""
|
||||
Extract metrics from FEA results.
|
||||
|
||||
Args:
|
||||
result_files: Dictionary mapping file types to paths (e.g., {'op2': Path(...), 'f06': Path(...)})
|
||||
config: Extractor-specific configuration parameters
|
||||
|
||||
Returns:
|
||||
Dictionary mapping metric names to values
|
||||
"""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def required_files(self) -> list[str]:
|
||||
"""List of required file types (e.g., ['op2'], ['f06'], etc.)."""
|
||||
pass
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Extractor name for registration."""
|
||||
return self.__class__.__name__.replace("Extractor", "").lower()
|
||||
|
||||
|
||||
# Registry of available extractors
|
||||
_EXTRACTOR_REGISTRY: Dict[str, type[ResultExtractor]] = {}
|
||||
|
||||
|
||||
def register_extractor(extractor_class: type[ResultExtractor]) -> type[ResultExtractor]:
|
||||
"""Decorator to register an extractor."""
|
||||
_EXTRACTOR_REGISTRY[extractor_class().name] = extractor_class
|
||||
return extractor_class
|
||||
|
||||
|
||||
def get_extractor(name: str) -> Optional[type[ResultExtractor]]:
|
||||
"""Get extractor class by name."""
|
||||
return _EXTRACTOR_REGISTRY.get(name)
|
||||
|
||||
|
||||
def list_extractors() -> list[str]:
|
||||
"""List all registered extractor names."""
|
||||
return list(_EXTRACTOR_REGISTRY.keys())
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ResultExtractor",
|
||||
"register_extractor",
|
||||
"get_extractor",
|
||||
"list_extractors",
|
||||
]
|
||||
Reference in New Issue
Block a user