Skip to content

Commit

Permalink
look into value filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
rfbgo committed Jan 21, 2025
1 parent 8cf155b commit 1febdc0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
7 changes: 3 additions & 4 deletions lib/ramble/ramble/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def __init__(
filter_query=None,
summary_only=False
):
if filter_query:
#self.filter_query = list(itertools.chain.from_iterable(filter_query))
self.filter_query = filter_query

# TODO: can I use this method?
#self.filter_query = list(itertools.chain.from_iterable(filter_query))
self.filter_query = filter_query
self.summary_only = summary_only
42 changes: 36 additions & 6 deletions lib/ramble/ramble/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2129,15 +2129,45 @@ def no_active_workspace():

def _filter_results(results, output_filter):
# TODO: Fitler more

Check warning on line 2131 in lib/ramble/ramble/workspace/workspace.py

View workflow job for this annotation

GitHub Actions / formatting

"Fitler" should be "Filter".
expression = output_filter.filter_query
for result in results:
if inst.expander.evaluate_predicate(expression):
print(result)
yield result
expression = None
if output_filter:
expression = output_filter.filter_query

if expression and "experiments" in results:
filtered_exps = []
added = 0
total = 0
for exp in results["experiments"]:
exp_copy = copy.deepcopy(exp)
filtered_contexts = []
for context in exp["CONTEXTS"]:
context_copy = copy.deepcopy(context)
filtered_foms = []
for fom in context["foms"]:
fom['fom_name'] = fom['name']

expander = ramble.expander.Expander(fom, None)
# TODO: numeric filters will not work well here for a workspace that has mixed types, since `evaluate_predicate` hard dies instead of throws on type error
if expander.evaluate_predicate(expression):
filtered_foms.append(fom)
added += 1

total += 1

context_copy["foms"] = filtered_foms
filtered_contexts.append(context_copy)
exp_copy['CONTEXTS'] = filtered_contexts
filtered_exps.append(exp_copy)
tty.debug(f"Filtered results showing {added} foms out of {total}")
results["experiments"] = filtered_exps

if added == 0:
logger.die('No results selected during filter')

if not output_filter.summary_only or "experiments" not in results:
print('early return')
return results
results = copy.deepcopy(results)
#results = copy.deepcopy(results) # TODO: is this needed?
results["experiments"] = [r for r in results["experiments"] if r["N_REPEATS"] > 0]
return results

Expand Down

0 comments on commit 1febdc0

Please sign in to comment.