Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-12 08:24:57

0001 """Helpers for invoking objective scripts in workflows.
0002 
0003 These utilities build language-agnostic command-line arguments and environment
0004 variables for passing design parameters and collecting objective outputs.
0005 
0006 Contract:
0007 - Flags: --design_params_file, --output_file
0008 - Env:   AID2E_PARAMS_FILE, AID2E_OUTPUT_FILE
0009 
0010 Use both for maximum compatibility with Python, bash/csh, or other executables.
0011 """
0012 
0013 from __future__ import annotations
0014 
0015 from pathlib import Path
0016 from typing import Dict, List, Tuple
0017 
0018 
0019 def build_objective_call(
0020     command: List[str],
0021     params_file: Path,
0022     output_file: Path,
0023 ) -> Tuple[List[str], Dict[str, str]]:
0024     """Build command args and environment for objective execution.
0025 
0026     Args:
0027       command: Base command argv (e.g., ["python", "scripts/dtlz2_problem.py"]).
0028       params_file: Path to JSON design parameters file.
0029       output_file: Path to JSON output file.
0030 
0031     Returns:
0032       A tuple (argv, env) where:
0033         - argv: command with flags appended
0034         - env: environment variables to set
0035 
0036     Notes:
0037       - The flags are appended unconditionally; objective scripts may ignore
0038         them if they prefer env vars.
0039       - Caller is responsible for creating parent directories for output_file.
0040     """
0041     argv = list(command) + [
0042         "--design_params_file",
0043         str(params_file),
0044         "--output_file",
0045         str(output_file),
0046     ]
0047     env = {
0048         "AID2E_PARAMS_FILE": str(params_file),
0049         "AID2E_OUTPUT_FILE": str(output_file),
0050     }
0051     return argv, env