polyaxon / polyaxon

MLOps Tools For Managing & Orchestrating The Machine Learning LifeCycle
https://polyaxon.com
Apache License 2.0
3.56k stars 313 forks source link

Add DateTimeRange to matrix generators #763

Closed mmourafiq closed 2 years ago

mmourafiq commented 4 years ago

Feature motivation

Is it possible to generate dates as hyper-params?

Add possibility to generate datetime ranges.

Feature description

DateTimeRange should allow users to generate list of datetimes based on start/end and a step, to be passed as hyper-parameters for parallel operations.

Feature implementation

mmourafiq commented 2 years ago

Adds also support of a backfill strategy when used with grid search:

from polyaxon.polytune.search_managers.grid_search.manager import GridSearchManager
from polyaxon.polyflow import V1Matrix, V1GridSearch

config_dict = {
    "kind": "grid",
    "concurrency": 1,
    "numRuns": 10,
    "params": {"dates": {"kind": "dtrange", "value": ["2019-06-22 00:00", "2019-07-25 00:00", 3600 * 24]}},
}
config = V1GridSearch.from_dict(config_dict)
GridSearchManager(config).get_suggestions()

Out[3]: 
[{'dates': datetime.datetime(2019, 6, 22, 0, 0)},
 {'dates': datetime.datetime(2019, 6, 23, 0, 0)},
 {'dates': datetime.datetime(2019, 6, 24, 0, 0)},
 {'dates': datetime.datetime(2019, 6, 25, 0, 0)},
 {'dates': datetime.datetime(2019, 6, 26, 0, 0)},
 {'dates': datetime.datetime(2019, 6, 27, 0, 0)},
 {'dates': datetime.datetime(2019, 6, 28, 0, 0)},
 {'dates': datetime.datetime(2019, 6, 29, 0, 0)},
 {'dates': datetime.datetime(2019, 6, 30, 0, 0)},
 {'dates': datetime.datetime(2019, 7, 1, 0, 0)}]
from polyaxon.polytune.search_managers.grid_search.manager import GridSearchManager
from polyaxon.polyflow import V1Matrix, V1GridSearch

config_dict = {
    "kind": "grid",
    "params": {"dts": {"kind": "dtrange", "value": {"start": "2019-06-22 21:00", "stop": "2019-06-25 21:00", step: "3600"]}},
}
config = V1GridSearch.from_dict(config_dict)
GridSearchManager(config).get_suggestions()

Out[5]: 
[{'dts': datetime.datetime(2019, 6, 22, 21, 0)},
 {'dts': datetime.datetime(2019, 6, 22, 22, 0)},
 {'dts': datetime.datetime(2019, 6, 22, 23, 0)},
 {'dts': datetime.datetime(2019, 6, 23, 0, 0)},
 {'dts': datetime.datetime(2019, 6, 23, 1, 0)},
 {'dts': datetime.datetime(2019, 6, 23, 2, 0)},
 {'dts': datetime.datetime(2019, 6, 23, 3, 0)},
 {'dts': datetime.datetime(2019, 6, 23, 4, 0)},
 {'dts': datetime.datetime(2019, 6, 23, 5, 0)},
 {'dts': datetime.datetime(2019, 6, 23, 6, 0)},
 {'dts': datetime.datetime(2019, 6, 23, 7, 0)},
 {'dts': datetime.datetime(2019, 6, 23, 8, 0)},
 ...]