Configuration
Config Parsing
Default configuration templates and YAML merge loader for HamGNN.
Defines config_default and nested section dicts, and provides load_config()
to merge user YAML with defaults into easydict.EasyDict, including parsing
of loss/metric function specs.
- hamgnn.config.config_parsing.config_default = {'dataset_params': {'batch_size': 1, 'graph_data_path': './', 'split_file': None, 'test_ratio': 0.2, 'train_ratio': 0.6, 'val_ratio': 0.2}, 'losses_metrics': {'losses': [{'loss_weight': 27.211, 'metric': 'mae', 'prediction': 'hamiltonian', 'target': 'hamiltonian'}], 'metrics': [{'metric': 'mae', 'prediction': 'hamiltonian', 'target': 'hamiltonian'}]}, 'optim_params': {'gradient_clip_val': 0.0, 'lr': 0.01, 'lr_decay': 0.5, 'lr_patience': 5, 'max_epochs': 3000, 'min_epochs': 100, 'stop_patience': 30}, 'output_nets': {'HamGNN_out': {'add_H0': True, 'add_H_nonsoc': False, 'band_num_control': 8, 'calculate_band_energy': False, 'collinear_spin': False, 'get_nonzero_mask_tensor': False, 'ham_only': True, 'ham_type': 'openmx', 'k_path': None, 'minMagneticMoment': 0.5, 'nao_max': 26, 'nonlinearity_type': 'gate', 'num_k': 5, 'soc_switch': False, 'spin_constrained': False, 'symmetrize': True, 'zero_point_shift': True}, 'output_module': 'HamGNN_out'}, 'profiler_params': {'progress_bar_refresh_rat': 1, 'train_dir': './'}, 'representation_nets': {'HamGNN_pre': {'build_internal_graph': False, 'correlation': 2, 'cutoff': 26.0, 'cutoff_func': 'cos', 'edge_sh_normalization': 'component', 'edge_sh_normalize': True, 'irreps_edge_sh': '0e + 1o + 2e + 3o + 4e + 5o', 'irreps_node_features': '64x0e+64x0o+32x1o+16x1e+12x2o+25x2e+18x3o+9x3e+4x4o+9x4e+4x5o+4x5e+2x6e', 'num_hidden_features': 16, 'num_layers': 3, 'num_radial': 64, 'num_types': 96, 'radial_MLP': [64, 64], 'radius_scale': 1.01, 'radius_type': 'openmx', 'rbf_func': 'bessel', 'set_features': True, 'use_corr_prod': False, 'use_gradient_checkpointing': False, 'use_kan': False}}, 'setup': {'GNN_Net': 'HamGNNpre', 'checkpoint_path': './', 'hostname': 'host', 'ignore_warnings': True, 'job_id': 'time_2025', 'load_from_checkpoint': False, 'num_gpus': 1, 'precision': 32, 'property': 'hamiltonian', 'resume': False, 'stage': 'fit', 'use_gradient_checkpointing': False}}
The parameters for setup
- hamgnn.config.config_parsing.recursive_update(base_dict, update_dict)[source]
Recursively update a dictionary with values from another dictionary.
- Parameters:
- Returns:
The updated dictionary
- Return type:
Dict[str, Any]
Notes
If a key exists in both dictionaries and both values are dictionaries, recursively merge these nested dictionaries
If a key exists in both dictionaries but values aren’t both dictionaries, the value from update_dict overrides the value in base_dict
If a key exists only in update_dict, it’s added to base_dict
- hamgnn.config.config_parsing.load_config(config_file_path=None)[source]
Load configuration from a YAML file and merge it with default configuration.
This function reads a YAML configuration file and recursively merges its contents with the default configuration. The config file path can be provided either as a function parameter or as a command-line argument.
- Parameters:
config_file_path (
Optional[str]) – Path to the YAML configuration file. If None, attempts to get the path from command-line arguments. If not provided via command line either, uses ‘config_default.yaml’.- Returns:
An EasyDict object containing the merged configuration.
- Return type:
EasyDict
- Raises:
FileNotFoundError – If the configuration file doesn’t exist.
yaml.YAMLError – If the YAML file has parsing errors.
UnicodeDecodeError – If there are encoding issues when reading the file.
Exception – For any other unexpected errors.