"""Unchanged dynamic40 learner; fresh generic start, exact-label round7 baseline."""
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','round8')
old='round4_independent_branch_same_round8_latest_holdout_labels'
require(SOURCE.count(old)==1,'Previous mask comparison anchor changed')
SOURCE=SOURCE.replace(old,'round7_independent_branch_same_round8_latest_holdout_labels')
implementation=types.ModuleType('pallet._round8_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 round8 mask attempt')
    try:implementation.train()
    finally:
        if RUN.exists():
            (RUN/'adapted_round8_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_round8_mask.py'),hyperparameters_unchanged=True))


if __name__=='__main__':train()
