diff --git a/cfr/reconjob.py b/cfr/reconjob.py index 0ae3e829..3c73dc5f 100644 --- a/cfr/reconjob.py +++ b/cfr/reconjob.py @@ -289,7 +289,7 @@ def clear_proxydb_tags(self, verbose=False): verbose (bool, optional): print verbose information. Defaults to False. ''' for pid, pobj in self.proxydb.records.items(): - pobj.tags = [] + pobj.tags = set() if verbose: p_success(f'>>> job.proxydb updated with tags cleared') @@ -304,6 +304,12 @@ def split_proxydb(self, tag='calibrated', assim_frac=None, seed=0, verbose=False verbose (bool, optional): print verbose information. Defaults to False. ''' assim_frac = self.io_cfg('proxy_assim_frac', assim_frac, default=0.75, verbose=verbose) + + # remove the tags of any previous split, so that repeated calls (e.g., one per seed + # in run_da_mc) give independent splits instead of accumulating 'assim' records + for pid, pobj in self.proxydb.records.items(): + pobj.tags = set(pobj.tags) - {'assim', 'eval'} + target_pdb = self.proxydb.filter(by='tag', keys=[tag]) nrec_assim = int(target_pdb.nrec * assim_frac) diff --git a/tests/test_reconjob.py b/tests/test_reconjob.py index e32862c9..8fcad6c5 100644 --- a/tests/test_reconjob.py +++ b/tests/test_reconjob.py @@ -252,6 +252,18 @@ def test_same_seed_gives_same_split(self): tags2 = {pid: frozenset(r.tags) for pid, r in job.proxydb.records.items()} assert tags1 == tags2 + def test_resplit_replaces_previous_split(self): + # A second split (e.g., the next seed in run_da_mc) must not keep the + # 'assim'/'eval' tags of the first one + job = self._make_calibrated_job(n=4) + for seed in range(10): + job.split_proxydb(seed=seed, assim_frac=0.5) + assim = {pid for pid, r in job.proxydb.records.items() if 'assim' in r.tags} + evals = {pid for pid, r in job.proxydb.records.items() if 'eval' in r.tags} + assert len(assim) == 2 + assert len(evals) == 2 + assert assim.isdisjoint(evals) + def test_all_tagged_records_assigned(self): # Every calibrated record gets either assim or eval — none left unassigned job = self._make_calibrated_job(n=4)