|
1 | 1 | """Unified input configuration module for DeePKS.""" |
2 | 2 |
|
| 3 | +from .config import ( |
| 4 | + VALID_TASK_TYPES, |
| 5 | + apply_backend_compatibility, |
| 6 | + get_default_config, |
| 7 | + infer_scf_backend, |
| 8 | + normalize_config, |
| 9 | + render_input_parameter_doc, |
| 10 | +) |
3 | 11 | from .loader import load_config |
4 | | -from .merger import merge_configs |
| 12 | +from .merger import merge_configs, apply_parameter_inheritance, package_config |
5 | 13 | from .validator import validate_config |
6 | | -from .defaults import get_default_config |
7 | 14 | from .dispatcher import dispatch_command |
8 | 15 |
|
| 16 | + |
| 17 | +def build_runtime_config_from_raw(raw_config): |
| 18 | + """Build packaged runtime config from an in-memory raw config dictionary.""" |
| 19 | + task_type = raw_config.get('type') |
| 20 | + if task_type is None: |
| 21 | + raise ValueError("'type' field is required in configuration file") |
| 22 | + if task_type not in VALID_TASK_TYPES: |
| 23 | + raise ValueError( |
| 24 | + f"Unknown type: {task_type}. Valid types: {', '.join(sorted(VALID_TASK_TYPES))}" |
| 25 | + ) |
| 26 | + |
| 27 | + normalized = normalize_config(raw_config, task_type) |
| 28 | + scf_soft = infer_scf_backend(normalized) |
| 29 | + defaults = get_default_config(task_type, scf_soft) |
| 30 | + config = merge_configs(defaults, normalized) |
| 31 | + |
| 32 | + if task_type == 'iterate': |
| 33 | + config = apply_parameter_inheritance(config) |
| 34 | + |
| 35 | + config = apply_backend_compatibility(config, task_type) |
| 36 | + validate_config(config, task_type) |
| 37 | + return package_config(config) |
| 38 | + |
| 39 | + |
| 40 | +def build_runtime_config(config_path): |
| 41 | + """Build packaged runtime config from a user config path.""" |
| 42 | + raw_config = load_config(config_path) |
| 43 | + return build_runtime_config_from_raw(raw_config) |
| 44 | + |
| 45 | + |
9 | 46 | __all__ = [ |
| 47 | + 'VALID_TASK_TYPES', |
10 | 48 | 'load_config', |
11 | 49 | 'merge_configs', |
| 50 | + 'apply_parameter_inheritance', |
| 51 | + 'package_config', |
12 | 52 | 'validate_config', |
13 | 53 | 'get_default_config', |
14 | 54 | 'dispatch_command', |
| 55 | + 'build_runtime_config', |
| 56 | + 'build_runtime_config_from_raw', |
| 57 | + 'normalize_config', |
| 58 | + 'apply_backend_compatibility', |
| 59 | + 'infer_scf_backend', |
| 60 | + 'render_input_parameter_doc', |
15 | 61 | ] |
0 commit comments