credit.postblock#
Submodules#
- credit.postblock.advect
- credit.postblock.base
- credit.postblock.conservation
- credit.postblock.exp
- credit.postblock.gen1
- credit.postblock.geopotential
- credit.postblock.hybrid_interp
- credit.postblock.mslp
- credit.postblock.pressure_interp
- credit.postblock.reconstruct
- credit.postblock.scaler
- credit.postblock.square
- credit.postblock.wet_mask_samudra
- credit.postblock.wind_filter
Attributes#
Functions#
|
|
|
Decorator that adds an external postblock class to the postblock registry. |
|
Instantiate postblocks for a single phase from the full CREDIT config. |
|
Apply a postblock group built by |
Package Contents#
- credit.postblock.logger#
- credit.postblock.__getattr__(name)#
- credit.postblock.register_postblock(block_type)#
Decorator that adds an external postblock class to the postblock registry.
The class must inherit from
credit.postblock.base.BasePostblockso that the correctforward(batch: dict) -> dictsignature is enforced.- Parameters:
block_type – Key used in the config
postblocks.<phase>.<block>.typefield.
Example:
from credit.postblock import register_postblock from credit.postblock.base import BasePostblock @register_postblock("my_postblock") class MyPostBlock(BasePostblock): def forward(self, batch: dict) -> dict: ...
- credit.postblock.build_postblocks(conf: dict, phase: str = 'per_step') torch.nn.ModuleDict#
Instantiate postblocks for a single phase from the full CREDIT config.
Config format:
postblocks: per_step: # run after every forward pass in the rollout loop reconstruct: type: reconstruct inverse_scale: type: bridgescaler_transform args: method: inverse_transform scaler_path: /path/to/scaler.json post_rollout: # run once after all rollout steps complete mass_fixer: type: global_mass_fixer args: ...
Typical usage — build once per phase, store separately:
step_postblocks = build_postblocks(conf, phase="per_step") rollout_postblocks = build_postblocks(conf, phase="post_rollout") # inside rollout loop, after each forward pass: full_data_dict = apply_postblocks(step_postblocks, full_data_dict) # once after rollout loop completes: apply_postblocks(rollout_postblocks, full_data_dict)
- Parameters:
conf – the full CREDIT config dict.
phase – which section to build —
"per_step"or"post_rollout".
- Returns:
nn.ModuleDictof instantiated blocks for the requested phase.- Raises:
ValueError – if the config contains keys other than
"per_step"/"post_rollout", ifphaseis not one of those values, or if a block’stypevalue is not in_POSTBLOCK_REGISTRY.
- credit.postblock.apply_postblocks(postblocks: torch.nn.ModuleDict, batch_dict: dict) dict#
Apply a postblock group built by
build_postblocks.- Parameters:
postblocks –
nn.ModuleDictbuilt bybuild_postblocksfor a single phase.batch_dict – dict containing at minimum
"y_pred"and"metadata".
- Returns:
The same
batch_dictafter all blocks in the group have run.