Files
Atomizer/archive/deprecated/result_extractors/generated/extract_expression.py
Anto01 eabcc4c3ca 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

56 lines
1.8 KiB
Python

"""
Extract expression value from NX .prt file
Used for extracting computed values like mass, volume, etc.
This extractor reads expressions using the .exp export method for accuracy.
"""
from pathlib import Path
from typing import Dict, Any
from optimization_engine.nx.updater import NXParameterUpdater
def extract_expression(prt_file: Path, expression_name: str):
"""
Extract an expression value from NX .prt file.
Args:
prt_file: Path to .prt file
expression_name: Name of expression to extract (e.g., 'p173' for mass)
Returns:
Dict with expression value and units
"""
updater = NXParameterUpdater(prt_file, backup=False)
expressions = updater.get_all_expressions(use_exp_export=True)
if expression_name not in expressions:
raise ValueError(f"Expression '{expression_name}' not found in {prt_file}")
expr_info = expressions[expression_name]
# If expression is a formula (value is None), we need to evaluate it
# For now, we'll raise an error if it's a formula - user should use the computed value
if expr_info['value'] is None and expr_info['formula'] is not None:
raise ValueError(
f"Expression '{expression_name}' is a formula: {expr_info['formula']}. "
f"This extractor requires a computed value, not a formula reference."
)
return {
expression_name: expr_info['value'],
f'{expression_name}_units': expr_info['units']
}
if __name__ == '__main__':
# Example usage
import sys
if len(sys.argv) > 2:
prt_file = Path(sys.argv[1])
expression_name = sys.argv[2]
result = extract_expression(prt_file, expression_name)
print(f"Extraction result: {result}")
else:
print(f"Usage: python {sys.argv[0]} <prt_file> <expression_name>")