Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cfr/reconjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_reconjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading