config

class neuralhydrology.utils.config.Config(yml_path_or_dict: Path | dict, dev_mode: bool = False)

Bases: object

Read run configuration from the specified path or dictionary and parse it into a configuration object.

During parsing, config keys that contain ‘dir’, ‘file’, or ‘path’ will be converted to pathlib.Path instances. Configuration keys ending with ‘_date’ will be parsed to pd.Timestamps. The expected format is DD/MM/YYYY.

Parameters:
  • yml_path_or_dict (Union[Path, dict]) – Either a path to the config file or a dictionary of configuration values.

  • dev_mode (bool, optional) – If dev_mode is off, the config creation will fail if there are unrecognized keys in the passed config specification. dev_mode can be activated either through this parameter or by setting dev_mode: True in yml_path_or_dict.

Raises:

ValueError – If the passed configuration specification is neither a Path nor a dict or if dev_mode is off (default) and the config file or dict contain unrecognized keys.

property additional_feature_files: List[Path]
property allow_subsequent_nan_losses: int
as_dict() dict

Return run configuration as dictionary.

Returns:

The run configuration, as defined in the .yml file.

Return type:

dict

property autoregressive_inputs: List[str] | Dict[str, List[str]]
property base_run_dir: Path
property batch_size: int
property bidirectional_stacked_forecast_lstm: bool
property cache_validation_data: bool
property checkpoint_path: Path
property clip_gradient_norm: float
property clip_targets_to_zero: List[str]
property conceptual_model: str
property continue_from_epoch: int
property custom_normalization: dict
property data_dir: Path
property dataset: str
property device: str
dump_config(folder: Path, filename: str = 'config.yml')

Save the run configuration as a .yml file to disk.

Parameters:
  • folder (Path) – Folder in which the configuration will be stored.

  • filename (str, optional) – Name of the file that will be stored. Default: ‘config.yml’.

Raises:

FileExistsError – If the specified folder already contains a file named filename.

property duplicate_features: dict
property dynamic_conceptual_inputs: List[str]
property dynamic_inputs: List[str] | Dict[str, List[str]]
property dynamics_embedding: dict
property epochs: int
property evolving_attributes: List[str]
property experiment_name: str
property finetune_modules: List[str] | Dict[str, str]
property forcings: List[str]
property forecast_hidden_size: int
property forecast_inputs: List[str]
property forecast_network: dict
property forecast_overlap: int
property forecast_seq_length: int
property head: str
property hidden_size: int | Dict[str, int]
property hindcast_hidden_size: int | Dict[str, int]
property hindcast_inputs: List[str]
property hydroatlas_attributes: List[str]
property img_log_dir: Path
property initial_forget_bias: float
property is_continue_training: bool
property is_finetuning: bool
property lagged_features: dict
property learning_rate: Dict[int, float]
property log_interval: int
property log_n_figures: int
property log_tensorboard: bool
property loss: str
property mamba_d_conv: int
property mamba_d_state: int
property mamba_expand: int
property mass_inputs: List[str]
property max_updates_per_epoch: int | None
property mc_dropout: bool
property metrics: List[str] | Dict[str, List[str]]
property model: str
property n_distributions: int
property n_samples: int
property n_taus: int
property negative_sample_handling: str
property negative_sample_max_retries: int
property no_loss_frequencies: list
property num_workers: int
property number_of_basins: int
property ode_method: str
property ode_num_unfolds: int
property ode_random_freq_lower_bound: str
property optimizer: str
property output_activation: str
property output_dropout: float
property per_basin_test_periods_file: Path
property per_basin_train_periods_file: Path
property per_basin_validation_periods_file: Path
property predict_last_n: int | Dict[str, int]
property random_holdout_from_dynamic_features: Dict[str, float]
property rating_curve_file: Path
property regularization: List[str | Tuple[str, float]]
property run_dir: Path
property save_all_output: bool
property save_git_diff: bool
property save_train_data: bool
property save_validation_results: bool
property save_weights_every: int
property seed: int
property seq_length: int | Dict[str, int]
property shared_mtslstm: bool
property state_handoff_network: dict
property static_attributes: List[str]
property statics_embedding: dict
property target_loss_weights: List[float]
property target_noise_std: float
property target_variables: List[str]
property tau_down: float
property tau_up: float
property test_basin_file: Path
property test_end_date: pandas.Timestamp
property test_start_date: pandas.Timestamp
property timestep_counter: bool
property train_basin_file: Path
property train_data_file: Path
property train_dir: Path
property train_end_date: pandas.Timestamp
property train_start_date: pandas.Timestamp
property transfer_mtslstm_states: Dict[str, str]
property transformer_dim_feedforward: int
property transformer_dropout: float
property transformer_nheads: int
property transformer_nlayers: int
property transformer_positional_dropout: float
property transformer_positional_encoding_type: str
property umal_extend_batch: bool
update_config(yml_path_or_dict: Path | dict, dev_mode: bool = False)

Update config arguments.

Useful e.g. in the context of fine-tuning or when continuing to train from a checkpoint to adapt for example the learning rate, train basin files or anything else.

Parameters:
  • yml_path_or_dict (Union[Path, dict]) – Either a path to the new config file or a dictionary of configuration values. Each argument specified in this file will overwrite the existing config argument.

  • dev_mode (bool, optional) – If dev_mode is off, the config creation will fail if there are unrecognized keys in the passed config specification. dev_mode can be activated either through this parameter or by setting dev_mode: True in yml_path_or_dict.

Raises:

ValueError – If the passed configuration specification is neither a Path nor a dict, or if dev_mode is off (default) and the config file or dict contain unrecognized keys.

property use_basin_id_encoding: bool
property use_frequencies: List[str]
property validate_every: int
property validate_n_random_basins: int
property validation_basin_file: Path
property validation_end_date: pandas.Timestamp
property validation_start_date: pandas.Timestamp
property verbose: int

Defines level of verbosity.

0: Only log info messages, don’t show progress bars 1: Log info messages and show progress bars

Returns:

Level of verbosity.

Return type:

int

property warmup_period: int
neuralhydrology.utils.config.create_random_name()