NEDAS.core.context module
- class NEDAS.core.context.Context(config: Config | None = None, config_file: str | None = None, parse_args: bool = False, **kwargs)[source]
Bases:
objectRuntime context manages the generation and interaction of dynamic objects in runtime
- comm: parallel.Comm
- comm_rec: parallel.Comm
- comm_mem: parallel.Comm
- progress: progress.Progress
- grid: grid.GridType
- grid_orig: grid.GridType
- assimilator: Assimilator
- localization_funcs: dict[str, Callable]
- debug: bool
- interactive: bool
- is_notebook: bool
- time: datetime
- iter: int
- pid_show: int
- nens: int
- mem_list: dict[ProcIDMem, list[MemID]]
- fs: FileSystem
- jsub: JobSubmitter
- check_interactive() bool[source]
If the runtime environment supports interactive output (with ANSI escape code).
- update_assim_tools()[source]
Update the assimilation tool components based on runtime configuration
- property prev_time: datetime
Previous analysis time. Automatically updated when self.time changes.
- Returns:
Previous analysis time.
- Return type:
datetime
- property next_time: datetime
Next analysis time. Automatically updated when self.time changes.
- Returns:
Next analysis time.
- Return type:
datetime
- set_comm() None[source]
Initialize the MPI communicator, split the communicator if necessary.
For serial program, use a dummy communicator, set
nprocto the number of available processors on the machine; for MPI program, useMPI.COMM_WORLDand check if size matchs withnproc.Split the communicator into member and record groups, according to
nprocandnproc_mem. SeeNEDAS.utils.parallelmodule for more details.
- set_grid() None[source]
Initialize the analysis grid based on the configuration.
If
grid_def['type']is ‘custom’, will create a analysis grid based on provided parameters. Ifgrid_def['type']is a model name, will load the grid from the specified model class.
- set_models() None[source]
Initialize model instances based on
model_def[model_name]settings. Store the model instances inmodels[model_name].
- set_datasets() None[source]
Initialize dataset instances based on
dataset_def[dataset_name]settings. Store the dataset instances indatasets[dataset_name].
- property total_tasks
- property current_task
- property message
- property debug_message
- logger(func_name: str)[source]
Decorator to register the func in call stack and show runtime messages.
- print_1p(msg: str)[source]
Customized print function for showing runtime message.
Only the processor with PID = self.pid_show will show the message, this avoids the redundancy if all processors are showing the same message.
- dump_config(config_file: str) None[source]
Dumps a snapshot of the current state to a yaml config file. The original config object remains unchanged in memory.
- run_job(commands: str, parallel_mode: Literal['serial', 'mpi', 'openmp'] = 'serial', nproc: int = 1, offset: int = 0, **kwargs) None[source]
The user-facing method for running command on a computer. It re-configures the existing job submitter with runtime arguments and execute the command.
- Parameters:
commands (str) – Shell commands to be dispatched by job submitter
parallel_mode (ParallelMode, optional) – parallel mode (‘serial’, ‘mpi’, ‘openmp’), default is ‘serial’
nproc (int, optional) – number of processors (default is 1)
offset (int, optional) – offset in full list of processors (default is 0)
**kwargs – other keyword arguments to update the job submitter configuration