"""Versioned round6 adapter of the frozen, matched dynamic40 training engine."""
import types

from .cluster_targets import digest
from .mask_model_training_data import PROJECT,write,require

path=PROJECT/'pallet/pallet_description_round5_mask.py'
SOURCE=path.read_text().replace('round5','round6')
old='round4_independent_branch_same_round6_latest_holdout_labels'
require(SOURCE.count(old)==1,'Unexpected comparison scope anchor')
SOURCE=SOURCE.replace(old,'round5_independent_branch_same_round6_latest_holdout_labels')
implementation=types.ModuleType('pallet._round6_mask_training');implementation.__file__=__file__
exec(compile(SOURCE,str(path),'exec'),implementation.__dict__)
ROOT=implementation.ROOT;RUN=implementation.RUN;CONFIG=implementation.CONFIG;learning=implementation.learning;class_tables=implementation.class_tables


def train():
    require(not RUN.exists(),'Preserve previous round6 mask attempt')
    try:implementation.train()
    finally:
        if RUN.exists():
            (RUN/'adapted_round6_mask.py').write_text(SOURCE)
            write(RUN/'adapter_provenance.json',dict(adapter_sha256=digest(__file__),frozen_source_sha256=digest(path),adapted_sha256=digest(RUN/'adapted_round6_mask.py'),
                changes='round5_to_round6_roots_data_snapshot_titles_and_previous_comparison_scope_only',hyperparameters_unchanged=True))


if __name__=='__main__':train()
