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

[Feat] Support conditionals in Pipeline definition #120

Open
eddiebergman opened this issue Jul 3, 2023 · 1 comment
Open

[Feat] Support conditionals in Pipeline definition #120

eddiebergman opened this issue Jul 3, 2023 · 1 comment
Labels
feature A new feature

Comments

@eddiebergman
Copy link
Contributor

Just a suggestion, it's a bit redundant but hopefully clear in terms of how it would work

space = {
    "a": HP(
        values=[1, 2, 3, 4]
        conditions=[
            Restrict(
                to=[2, 3],
                when=(
                    HP.Ref("b", values=["red"])
                    | Hp.Ref("b", values=["blue"])
                    & Hp.Ref("b", values=["red"])
                 )
             ),
            Active(when=HP.Ref("b", values=["red", "blue"])
        ]
     ),
    "b": ["red", "green", "blue"]
}
# 'a' is inactive when 'b' is "green" but can be in [2,3] when 'b' in ["red", "blue"]
@LennartPurucker
Copy link
Collaborator

A workaround for activating HPs could be the following:

space = {
    "a": [1, 2, 3, 4],
    "b": ["red", "green", "blue"],
    "c": [True, False],
    "d": (0, 1)
}
config = {
    "conditional_meta_info": {
        # Only activate a when b is red or blue
        "a": ("b", ["red", "blue"]),
        # only activate b when c is true (hence, also only activate a when c is True)
        "b": ("c", True),
        # only activate d when b is blue and c is True
        "d": [("b", "blue"), ("c", True)]
    }
}

# ...build space, sample from space...

input_pipeline = pipeline.configure(trial.config)

for config_key, conditions in input_pipeline.tail.config.pop("conditional_meta_info").items():
    list_check = lambda c_v: (c_v if isinstance(c_v, list) else [c_v])
    conditions = list_check(conditions)

    if any(
            # 1. Check if relevant key already deleted or not part of the config, if so we
            #   assume the condition is not met.
            (condition_key not in input_pipeline.tail.config) or
            # 2. Check if condition is not met directly.
            (input_pipeline.tail.config[condition_key] not in list_check(condition_values))
            # - check this for all possible conditions
            for condition_key, condition_values in conditions
    ):
        #  If any of the above for any condition, delete the config key;
        #   removing it from the pipeline.
        del input_pipeline.tail.config[config_key]

We build a space with all HPs and remove deactivated HPs post hoc.

@eddiebergman eddiebergman added the feature A new feature label Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature
Projects
None yet
Development

No branches or pull requests

2 participants