Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Extended name filtering capabilities for the name_filter method. #700

Open
hongyi-zhao opened this issue Nov 2, 2024 · 2 comments

Comments

@hongyi-zhao
Copy link

hongyi-zhao commented Nov 2, 2024

Current Behavior

The name_filter parameter currently only supports simple string matching:

# Current functionality - simple string containment matching
flow.update_maker_kwargs(settings, name_filter="relax")

This basic matching is implemented using string containment (name_filter in job.name), which limits filtering capabilities to substring matching only.

Proposed Enhancement

Extend the name_filter functionality to support:

  1. List-based filtering for multiple patterns:
# Match jobs containing either "relax" or "static"
flow.update_maker_kwargs(settings, name_filter=["relax", "static"])
  1. Negative filtering (exclusion):
# Match jobs that don't contain "relax"
flow.update_maker_kwargs(settings, name_filter="!relax")
# Or alternatively with explicit parameter
flow.update_maker_kwargs(settings, name_filter="relax", exclude=True)

Implementation Suggestion

def update_maker_kwargs(
    self,
    settings: dict,
    name_filter: Union[str, List[str], None] = None,
    exclude: bool = False,
    ...
) -> Flow:
    def matches_filter(job_name: str) -> bool:
        if name_filter is None:
            return True
            
        if isinstance(name_filter, list):
            # For list filters, any match satisfies (OR logic)
            matches = any(nf in job_name for nf in name_filter)
        else:
            # For string filters, simple containment
            matches = name_filter in job_name
            
        # Handle exclusion
        return not matches if exclude else matches

Benefits

  • More flexible job filtering patterns
  • Ability to update multiple job types in one operation
  • Support for exclusion patterns
  • Maintains backward compatibility with existing code

Questions for Discussion

  1. Should we support AND logic for list filters (matching all patterns) in addition to OR logic?
  2. Should we consider supporting regex patterns for more advanced matching?
  3. For negative filtering, which approach is preferred:
    • Prefix notation (!pattern)
    • Explicit parameter (exclude=True)

Related Work

  • Current implementation in jobflow/core/job.py
  • Similar filtering patterns in other workflow management systems

Let me know your thoughts on the proposed enhancements and implementation approach.

@hongyi-zhao hongyi-zhao changed the title Enhancement: Extended name filtering capabilities for update_maker_kwargs and related methods. Enhancement: Extended name filtering capabilities for the name_filter method. Nov 2, 2024
@utf
Copy link
Member

utf commented Nov 12, 2024

Thanks very much for the suggestion. I wonder whether an alternative option is to allow a filter function. This could the be extremely flexible about how the filtering is performed.

For example:

  • List-based filtering for multiple patterns:
# Match jobs containing either "relax" or "static"
flow.update_maker_kwargs(settings, filter_func=lambda job: job.name in ["relax", "static"])
  • Negative filtering (exclusion):
# Match jobs that don't contain "relax"
flow.update_maker_kwargs(settings, filter_func=lambda job: "relax" not in job.name)

What do you think?

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Nov 13, 2024

@utf Your idea is much better than mine, it is extremely flexible and powerful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants