""" Example Plugin: Log Trial Start Simple pre-solve hook that logs trial information. This demonstrates the plugin API and serves as a template for custom hooks. """ from typing import Dict, Any, Optional import logging logger = logging.getLogger(__name__) def trial_start_logger(context: Dict[str, Any]) -> Optional[Dict[str, Any]]: """ Log trial information before solver execution. Args: context: Hook context containing: - trial_number: Current trial number - design_variables: Dict of variable values - sim_file: Path to simulation file Returns: Dict with logging status """ trial_num = context.get('trial_number', '?') design_vars = context.get('design_variables', {}) logger.info("=" * 60) logger.info(f"TRIAL {trial_num} STARTING") logger.info("=" * 60) for var_name, var_value in design_vars.items(): logger.info(f" {var_name}: {var_value:.4f}") return {'logged': True, 'trial': trial_num} def register_hooks(hook_manager): """ Register this plugin's hooks with the manager. This function is called automatically when the plugin is loaded. Args: hook_manager: The HookManager instance """ hook_manager.register_hook( hook_point='pre_solve', function=trial_start_logger, description='Log trial number and design variables before solve', name='log_trial_start', priority=10 # Run early )