def _update_monitor_stats(sample_index, chain_stats, monitor_stats,
    monitor_dict):
    """Update dictionary of per-iteration monitored statistics."""
    for trans_key, stats_key in monitor_stats:
        if sample_index == 0 and not (trans_key in chain_stats and 
            stats_key in chain_stats[trans_key]):
            raise KeyError(
                f'Statistics key pair {trans_key, stats_key} to be monitoredis not present in chain statistics returned by transitions.'
                )
        val = chain_stats[trans_key][stats_key][sample_index]
        if stats_key not in monitor_dict:
            monitor_dict[stats_key] = val
        else:
            monitor_dict[f'{trans_key}.{stats_key}'] = val
