Warning, /AID2E-framework/docs/CLI_DESIGN.md is written in an unsupported language. File is not indexed.
0001 # AID2E CLI Design and Implementation Plan
0002
0003 ## Overview
0004
0005 The AID2E CLI provides a comprehensive command-line interface for managing optimization workflows, from configuration validation to execution. The CLI is designed around three configuration types that work together:
0006
0007 1. **DesignConfig** - Defines the parameter search space and constraints
0008 2. **ProblemConfiguration** - Embeds design config + objectives + paths
0009 3. **OptimizationConfiguration** - Defines optimizer selection and settings
0010
0011 ## Modular Code Structure
0012
0013 The CLI is organized into focused modules for maintainability and extensibility:
0014
0015 ```
0016 src/aid2e/cli/
0017 ├── __init__.py # Exports main cli group
0018 ├── aid2e_cli.py # Main CLI group + plugin loader + command registration
0019 ├── _helpers.py # Shared utilities (config detection, formatters)
0020 ├── config_commands.py # Config inspection: describe, inspect, validate
0021 ├── workflow_commands.py # Execution: optimize, run (future)
0022 ├── utility_commands.py # Utilities: list, version
0023 └── legacy_commands.py # Deprecated: load, info
0024 ```
0025
0026 ### Module Responsibilities
0027
0028 | Module | Purpose | Lines | Commands |
0029 |--------|---------|-------|----------|
0030 | `aid2e_cli.py` | Main entry point, command registration, plugin discovery | ~100 | N/A (coordinator) |
0031 | `_helpers.py` | Shared utilities for config detection and formatting | ~400 | N/A (library) |
0032 | `config_commands.py` | Configuration inspection and validation | ~170 | describe, inspect, validate |
0033 | `workflow_commands.py` | Workflow execution and lifecycle management | ~150 | optimize, run*, resume*, stop*, status*, clean* |
0034 | `utility_commands.py` | Information and resource listing | ~90 | list, version, init*, graph* |
0035 | `legacy_commands.py` | Backward compatibility (with deprecation warnings) | ~210 | load, info |
0036
0037 *Planned commands not yet implemented
0038
0039 ### Import Patterns
0040
0041 The CLI supports both legacy and new import patterns for backward compatibility:
0042
0043 ```python
0044 # Legacy pattern (still works)
0045 from aid2e.cli.aid2e_cli import cli
0046
0047 # New preferred pattern
0048 from aid2e.cli import cli
0049 ```
0050
0051 Both patterns work identically due to the export in `__init__.py`.
0052
0053 ## CLI Command Structure
0054
0055 ```
0056 aid2e
0057 ├── [Config Inspection]
0058 │ ├── describe # Quick summary of any config file (auto-detects type)
0059 │ ├── inspect # Detailed inspection with section filtering
0060 │ └── validate # Syntax and structure validation
0061 ├── [Workflow Execution]
0062 │ ├── optimize # Run optimization (current implementation)
0063 │ ├── run # Execute full workflow (planned)
0064 │ ├── resume # Restart from checkpoint (planned)
0065 │ ├── stop # Halt running optimization (planned)
0066 │ ├── status # Check progress (planned)
0067 │ └── clean # Remove temporary files (planned)
0068 ├── [Utilities]
0069 │ ├── list # Available optimizers/templates/problems
0070 │ ├── version # Display version
0071 │ ├── init # Create configs from templates (planned)
0072 │ └── graph # Visualize workflow (planned)
0073 ```
0074
0075 ## Implemented Commands
0076
0077 ### 1. `aid2e describe <config_file>`
0078
0079 **Purpose:** Quick, human-readable summary with automatic config type detection.
0080
0081 **Features:**
0082 - Auto-detects: `full`, `problem`, `optimization`, or `design` config
0083 - Compact or detailed output modes
0084 - Multiple output formats: text, JSON, YAML
0085
0086 **Usage:**
0087 ```bash
0088 # Quick text summary
0089 aid2e describe config.yml
0090
0091 # Compact output
0092 aid2e describe design.params --compact
0093
0094 # JSON output for scripting
0095 aid2e describe config.yml --format json
0096
0097 # YAML output
0098 aid2e describe config.yml --format yaml
0099 ```
0100
0101 **Output example:**
0102 ```
0103 ======================================================================
0104 Configuration: dtlz2_optimization.yml
0105 Type: FULL
0106 ======================================================================
0107
0108 PROBLEM
0109 Name: DTLZ2 Multi-Objective Optimization
0110 Type: toy
0111 Output: ./output/dtlz2
0112 Work Dir: ./work/dtlz2
0113 Design: design.params (file)
0114 Objectives: 2
0115 - f1: minimize
0116 - f2: minimize
0117
0118 OPTIMIZATION
0119 Algorithm: ax (Bayesian)
0120 Iterations: 50
0121 Initial Samples: 10
0122 Parallel: 1
0123 Parameters:
0124 initialization_strategy: sobol
0125 surrogate_model: saasbo
0126 acquisition_function: qnehvi
0127 ```
0128
0129 ### 2. `aid2e inspect <config_file>`
0130
0131 **Purpose:** Detailed inspection with optional section filtering.
0132
0133 **Features:**
0134 - Section filtering: `--section [problem|optimization|design|all]`
0135 - Full parameter listings with bounds/choices
0136 - Constraint details
0137 - Replaces/enhances the old `info` command
0138
0139 **Usage:**
0140 ```bash
0141 # Inspect entire configuration
0142 aid2e inspect config.yml
0143
0144 # Inspect only optimization section
0145 aid2e inspect config.yml --section optimization
0146
0147 # Inspect only design parameters
0148 aid2e inspect config.yml --section design
0149
0150 # Inspect only problem definition
0151 aid2e inspect config.yml --section problem
0152 ```
0153
0154 **Output example:**
0155 ```
0156 ======================================================================
0157 Configuration: DTLZ2 Multi-Objective Optimization
0158 ======================================================================
0159
0160 PROBLEM CONFIGURATION
0161 Name: DTLZ2 Multi-Objective Optimization
0162 Type: toy
0163 Output Location: ./output/dtlz2
0164 Work Location: ./work/dtlz2
0165
0166 DESIGN PARAMETERS
0167
0168 DTLZ2_variables (10 parameters):
0169 - x1: 0.5 (0.0, 1.0)
0170 - x2: 0.0 (0.0, 1.0)
0171 ...
0172
0173 PARAMETER CONSTRAINTS
0174 - simple_constraint
0175 Rule: DTLZ2_variables.x1 < 1.0
0176 Description: x1 must be less than 1.0
0177
0178 OPTIMIZATION CONFIGURATION
0179 Name: dtlz2-optimization
0180 Optimizer: ax (Bayesian)
0181 Iterations: 50
0182 Initial Samples: 10
0183 Parallel Evaluations: 1
0184
0185 Objectives (2):
0186 - minimize:f1
0187 - minimize:f2
0188
0189 Optimizer Parameters:
0190 - initialization_strategy: sobol
0191 - surrogate_model: saasbo
0192 - acquisition_function: qnehvi
0193 - batch_size: 3
0194 - seed: 42
0195
0196 ======================================================================
0197 ```
0198
0199 ### 3. `aid2e validate <config_file>`
0200
0201 **Purpose:** Validate configuration syntax and structure without full execution.
0202
0203 **Features:**
0204 - Auto-detects config type
0205 - Validates using appropriate loader/model
0206 - Reports specific validation errors
0207 - Exit code 0 on success, 1 on failure
0208
0209 **Usage:**
0210 ```bash
0211 # Validate any config type
0212 aid2e validate config.yml
0213
0214 # Validate design parameters
0215 aid2e validate design.params
0216
0217 # Validate problem config
0218 aid2e validate problem.yml
0219 ```
0220
0221 **Output examples:**
0222 ```
0223 # Success
0224 Validating full configuration...
0225 ✓ Configuration is valid!
0226 Type: full
0227 Parameters: 10
0228
0229 # Failure
0230 Validating design configuration...
0231 ✗ Validation failed: Invalid constraint 'bad_constraint': Unknown parameters in constraint: DTLZ2.unknown
0232 ```
0233
0234 ### 4. `aid2e list [optimizers|templates|problems]`
0235
0236 **Purpose:** Display available optimizers, templates, and problem types.
0237
0238 **Features:**
0239 - Lists all categories when no argument provided
0240 - Shows optimizer capabilities and use cases
0241 - Lists available templates
0242 - Documents supported problem types
0243
0244 **Usage:**
0245 ```bash
0246 # List everything
0247 aid2e list
0248
0249 # List only optimizers
0250 aid2e list optimizers
0251
0252 # List only templates
0253 aid2e list templates
0254
0255 # List only problem types
0256 aid2e list problems
0257 ```
0258
0259 **Output example:**
0260 ```
0261 Available Optimizers:
0262 • ax (Bayesian Optimization)
0263 - Initialization: Sobol quasi-random
0264 - Surrogate: SAASBO (Sparse Axis-Aligned Subspace BO)
0265 - Acquisition: qNEHVI (Noisy Expected Hypervolume Improvement)
0266 - Use case: Multi-objective optimization, continuous parameters
0267
0268 Available Templates:
0269 • dtlz2 - Multi-objective test problem (2 objectives, 10 variables)
0270 • basic - Minimal configuration template
0271 • epic_tracking - EPIC detector tracking optimization
0272
0273 Supported Problem Types:
0274 • toy - Benchmark test problems (DTLZ2, ZDT, etc.)
0275 • epic_tracking - EPIC detector tracking system
0276 • custom - User-defined evaluation functions
0277 ```
0278
0279 ## Planned Commands (Not Yet Implemented)
0280
0281 ### 5. `aid2e run <config_file>` (HIGH PRIORITY)
0282
0283 **Purpose:** Execute complete optimization workflow.
0284
0285 **Planned features:**
0286 - Full orchestration: config → problem → optimizer → execution → results
0287 - Checkpoint/resume support
0288 - Output directory override
0289 - Dry-run mode
0290
0291 **Planned usage:**
0292 ```bash
0293 # Run full workflow
0294 aid2e run config.yml
0295
0296 # Dry run (validate and show plan)
0297 aid2e run config.yml --dry-run
0298
0299 # Override output location
0300 aid2e run config.yml --output results/experiment_1/
0301
0302 # Resume from checkpoint
0303 aid2e run config.yml --resume checkpoint.json
0304
0305 # Verbose logging
0306 aid2e run config.yml -vv --log output.log
0307 ```
0308
0309 ### 6. `aid2e init` (MEDIUM PRIORITY)
0310
0311 **Purpose:** Create new configuration files from templates.
0312
0313 **Planned features:**
0314 - Template-based generation
0315 - Interactive wizard mode
0316 - Type-specific templates (design/problem/optimization)
0317
0318 **Planned usage:**
0319 ```bash
0320 # Initialize from template
0321 aid2e init --template dtlz2
0322
0323 # Create specific config type
0324 aid2e init --type design > design.yml
0325 aid2e init --type problem > problem.yml
0326 aid2e init --type optimization --optimizer ax > optimization.yml
0327
0328 # Interactive mode
0329 aid2e init --interactive
0330 ```
0331
0332 ### 7. `aid2e graph <config_file>` (LOW PRIORITY)
0333
0334 **Purpose:** Visualize workflow structure and dependencies.
0335
0336 **Planned features:**
0337 - Dependency graph generation
0338 - Export to PNG/SVG/DOT
0339 - Show parameter flow
0340
0341 **Planned usage:**
0342 ```bash
0343 # Display workflow graph
0344 aid2e graph config.yml
0345
0346 # Export to file
0347 aid2e graph config.yml --output workflow.png
0348 aid2e graph config.yml --format svg
0349 ```
0350
0351 ## Configuration Type Detection
0352
0353 The CLI automatically detects configuration type based on structure:
0354
0355 ```python
0356 def _detect_config_type(data: dict) -> str:
0357 """Auto-detect configuration type."""
0358 if "problem" in data and "optimization" in data:
0359 return "full" # Full workflow config
0360 elif "problem" in data:
0361 return "problem" # Problem-only config
0362 elif "optimization" in data:
0363 return "optimization" # Optimizer-only config
0364 elif "design_space" in data or "design_parameters" in data:
0365 return "design" # Design space only
0366 else:
0367 return "unknown"
0368 ```
0369
0370 ## Configuration Hierarchy
0371
0372 ```
0373 FullConfiguration (loaded via load_config())
0374 ├── ProblemConfiguration
0375 │ ├── DesignConfig (embedded)
0376 │ │ ├── DesignParameters (parameter groups)
0377 │ │ └── ParameterConstraints (optional)
0378 │ ├── objectives
0379 │ └── output/work paths
0380 └── OptimizationConfiguration
0381 ├── OptimizerConfig
0382 │ ├── name (e.g., "ax")
0383 │ ├── type (e.g., "Bayesian")
0384 │ └── parameters (algorithm-specific)
0385 ├── objectives
0386 ├── n_iterations
0387 └── parallel_evaluations
0388 ```
0389
0390 ## YAML Structure Examples
0391
0392 ### Full Configuration
0393 ```yaml
0394 problem:
0395 name: DTLZ2 Optimization
0396 type: toy
0397 output_location: ./output/dtlz2
0398 work_location: ./work/dtlz2
0399 design_parameters_file: ./design.params
0400 objectives:
0401 - name: f1
0402 minimize: true
0403 - name: f2
0404 minimize: true
0405
0406 optimization:
0407 name: dtlz2-optimization
0408 optimizer:
0409 name: ax
0410 type: Bayesian
0411 parameters:
0412 initialization_strategy: sobol
0413 surrogate_model: saasbo
0414 acquisition_function: qnehvi
0415 n_initial_samples: 10
0416 batch_size: 3
0417 seed: 42
0418 objectives: ["minimize:f1", "minimize:f2"]
0419 n_iterations: 50
0420 n_initial_samples: 10
0421 parallel_evaluations: 1
0422 ```
0423
0424 ### Design Configuration (design.params)
0425 ```yaml
0426 design_space:
0427 design_parameters:
0428 DTLZ2_variables:
0429 parameters:
0430 x1: {value: 0.5, bounds: [0.0, 1.0]}
0431 x2: {value: 0.0, bounds: [0.0, 1.0]}
0432 # ... x3-x10
0433
0434 design_constraints:
0435 - name: simple_constraint
0436 description: x1 must be less than 1.0
0437 rule: DTLZ2_variables.x1 < 1.0
0438 ```
0439
0440 ### Problem Configuration Only
0441 ```yaml
0442 problem:
0443 name: My Problem
0444 type: toy
0445 output_location: ./output
0446 work_location: ./work
0447 design_parameters_file: ./design.params
0448 objectives:
0449 - name: f1
0450 minimize: true
0451 ```
0452
0453 ### Optimization Configuration Only
0454 ```yaml
0455 optimization:
0456 name: my-optimization
0457 optimizer:
0458 name: ax
0459 type: Bayesian
0460 parameters:
0461 n_initial_samples: 10
0462 batch_size: 4
0463 objectives: ["minimize:f1"]
0464 n_iterations: 20
0465 ```
0466
0467 ## Implementation Status
0468
0469 ### Modular Reorganization (v0.3.0)
0470
0471 **✅ COMPLETED** - CLI has been reorganized into modular structure:
0472
0473 | Module | Status | Lines | Purpose |
0474 |--------|--------|-------|---------|
0475 | `_helpers.py` | ✅ Complete | ~400 | Shared utilities and formatters |
0476 | `config_commands.py` | ✅ Complete | ~170 | Config inspection commands |
0477 | `workflow_commands.py` | ✅ Complete | ~150 | Workflow execution (optimize placeholder) |
0478 | `utility_commands.py` | ✅ Complete | ~90 | Resource listing and version |
0479 | `aid2e_cli.py` | ✅ Complete | ~100 | Main group and command registration |
0480 | `__init__.py` | ✅ Complete | ~20 | Package exports |
0481
0482 ### Command Implementation Status
0483
0484 | Command | Module | Status | Priority | Notes |
0485 |---------|--------|--------|----------|-------|
0486 | `describe` | config_commands | ✅ Complete | High | Auto-detects type, multiple formats |
0487 | `inspect` | config_commands | ✅ Complete | High | Section filtering, detailed output |
0488 | `validate` | config_commands | ✅ Complete | High | Type-aware validation |
0489 | `list` | utility_commands | ✅ Complete | Medium | Optimizers/templates/problems |
0490 | `version` | utility_commands | ✅ Complete | Low | Version display |
0491 | `optimize` | workflow_commands | ⚠️ Placeholder | High | Config loading works, execution pending |
0492 | `run` | workflow_commands | ⏳ Planned | High | Full workflow orchestration |
0493 | `resume` | workflow_commands | ⏳ Planned | High | Checkpoint restart |
0494 | `stop` | workflow_commands | ⏳ Planned | Medium | Graceful halt |
0495 | `status` | workflow_commands | ⏳ Planned | Medium | Progress monitoring |
0496 | `clean` | workflow_commands | ⏳ Planned | Low | Cleanup temporary files |
0497 | `init` | utility_commands | ⏳ Planned | Medium | Template generation |
0498 | `graph` | utility_commands | ⏳ Planned | Low | Workflow visualization |
0499
0500 ### Benefits of Modular Structure
0501
0502 1. **Maintainability**: Each module ~100-400 lines vs 740-line monolith
0503 2. **Testability**: Commands can be unit tested independently
0504 3. **Extensibility**: New commands added to appropriate module
0505 4. **Clarity**: Functional grouping matches user mental model
0506 5. **Simplicity**: No legacy command surface to maintain
0507
0508 ## Design Principles
0509
0510 1. **Auto-detection**: Commands should detect config type automatically
0511 2. **Consistency**: Similar output formats across commands
0512 3. **Composability**: Output formats (JSON/YAML) for scripting
0513 4. **Clear errors**: Specific, actionable error messages
0514 5. **Progressive disclosure**: Compact by default, detailed on demand
0515 6. **Exit codes**: 0 for success, 1 for failure (script-friendly)
0516
0517 ## Next Steps
0518
0519 ### Completed (v0.3.0)
0520 - [x] Reorganize CLI into modular structure
0521 - [x] Create `_helpers.py` for shared utilities
0522 - [x] Create `config_commands.py` (describe/inspect/validate)
0523 - [x] Create `workflow_commands.py` (optimize placeholder)
0524 - [x] Create `utility_commands.py` (list/version)
0525 - [x] Refactor `aid2e_cli.py` to main group coordinator
0526 - [x] Update `__init__.py` for backward compatibility
0527 - [x] Update CLI_DESIGN.md documentation
0528
0529 ### Immediate (Next PR)
0530 - [ ] Write unit tests for each command module
0531 - [ ] Test `config_commands` (describe/inspect/validate)
0532 - [ ] Test `workflow_commands` (optimize)
0533 - [ ] Test `utility_commands` (list/version)
0534 - [ ] Test plugin discovery in `aid2e_cli`
0535 - [ ] Test all commands with example configs
0536 - [ ] Test with `examples/basic/full_example.yml`
0537 - [ ] Test with `examples/configurations/dtlz2_optimization.yml`
0538 - [ ] Test with `tests/test_utilities/fixtures/dtlz2/design.params`
0539 - [ ] Verify CLI entry point
0540 - [ ] Ensure existing tests still pass
0541 - [ ] Confirm entry point works: `aid2e --help`
0542 - [ ] Test both import patterns work
0543
0544 ### Near Term
0545 - [ ] Implement `run` command with WorkflowOrchestrator
0546 - [ ] Add `resume` command for checkpoint restart
0547 - [ ] Add `status` command for progress monitoring
0548 - [ ] Auto-register AxOptimizerConfig in registry
0549 - [ ] Create template system for `init` command
0550
0551 ### Future
0552 - [ ] Add `graph` command for visualization
0553 - [ ] Add `clean` command for file cleanup
0554 - [ ] Support for config composition/inheritance
0555 - [ ] Interactive config builder
0556 - [ ] Shell completion (bash/zsh/fish)
0557 - [ ] Extended plugin system for custom optimizers
0558
0559 ## Testing Strategy
0560
0561 ```bash
0562 # Test describe command
0563 aid2e describe examples/basic/full_example.yml
0564 aid2e describe examples/basic/design.params --compact
0565 aid2e describe examples/basic/optimizer.config --format json
0566
0567 # Test inspect command
0568 aid2e inspect examples/basic/full_example.yml
0569 aid2e inspect examples/basic/full_example.yml --section optimization
0570
0571 # Test validate command
0572 aid2e validate examples/basic/full_example.yml
0573 aid2e validate examples/basic/design.params
0574
0575 # Test list command
0576 aid2e list
0577 aid2e list optimizers
0578 aid2e list templates
0579 ```
0580
0581 ## Related Files
0582
0583 - **CLI Implementation**: `src/aid2e/cli/aid2e_cli.py`
0584 - **Config Loaders**:
0585 - `src/aid2e/utilities/configurations/design_config.py`
0586 - `src/aid2e/utilities/configurations/problem_config.py`
0587 - `src/aid2e/utilities/configurations/optimization_config.py`
0588 - `src/aid2e/utilities/configurations/full_config.py`
0589 - **Example Configs**: `examples/basic/`, `tests/test_utilities/fixtures/dtlz2/`
0590 - **Documentation**: `docs/CONSTRAINT_HANDLING.md`, `README.md`
0591
0592 ## Support
0593
0594 For issues or questions about the CLI:
0595 - Repository: https://github.com/aid2e/AID2E-framework
0596 - Documentation: https://aid2e.github.io/AID2E-framework
0597 - Issues: https://github.com/aid2e/AID2E-framework/issues