forked from tinkoff-ai/etna
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Чиков Александр Павлович
committed
Dec 26, 2024
1 parent
48921d4
commit aea8e6c
Showing
8 changed files
with
689 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import random | ||
from typing import Optional | ||
|
||
import hydra | ||
import hydra_slayer | ||
import numpy as np | ||
import pandas as pd | ||
from omegaconf import DictConfig | ||
from omegaconf import OmegaConf | ||
|
||
from pathlib import Path | ||
|
||
from etna.datasets import TSDataset | ||
from etna.loggers import ClearMLLogger | ||
from etna.loggers import tslogger | ||
from etna.pipeline import Pipeline | ||
|
||
OmegaConf.register_new_resolver("range", lambda x, y: list(range(x, y))) | ||
OmegaConf.register_new_resolver("sum", lambda x, y: x + y) | ||
|
||
|
||
FILE_PATH = Path(__file__) | ||
|
||
def set_seed(seed: int = 42): | ||
random.seed(seed) | ||
np.random.seed(seed) | ||
|
||
|
||
def init_logger(config: dict, project: str = "a.p.chikov/test/clearml_basic", tags: Optional[list] = ["test", "clearml", "concurrency"]): | ||
tslogger.loggers = [] | ||
cml_logger = ClearMLLogger(project_name=project, tags=tags, config=config) | ||
tslogger.add(cml_logger) | ||
|
||
|
||
def dataloader(file_path: Path, freq: str) -> TSDataset: | ||
df = pd.read_csv(file_path) | ||
df = TSDataset.to_dataset(df) | ||
ts = TSDataset(df=df, freq=freq) | ||
return ts | ||
|
||
|
||
@hydra.main(config_name="config.yaml") | ||
def backtest(cfg: DictConfig): | ||
config = OmegaConf.to_container(cfg, resolve=True) | ||
|
||
# Set seed for reproducibility | ||
set_seed(cfg.seed) | ||
|
||
# Load data | ||
ts = dataloader(file_path=cfg.dataset.file_path, freq=cfg.dataset.freq) | ||
|
||
# Init pipeline | ||
pipeline: Pipeline = hydra_slayer.get_from_params(**config["pipeline"]) | ||
|
||
# Init backtest parameters like metrics and e.t.c. | ||
backtest_params = hydra_slayer.get_from_params(**config["backtest"]) | ||
|
||
# Init WandB logger | ||
init_logger(pipeline.to_dict()) | ||
|
||
# Run backtest | ||
_, _, _ = pipeline.backtest(ts, n_jobs=3, joblib_params=dict(backend="loky"), **backtest_params) | ||
|
||
|
||
if __name__ == "__main__": | ||
backtest() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import random | ||
from typing import Optional | ||
|
||
import hydra | ||
import hydra_slayer | ||
import numpy as np | ||
import pandas as pd | ||
from omegaconf import DictConfig | ||
from omegaconf import OmegaConf | ||
|
||
from pathlib import Path | ||
|
||
from etna.datasets import TSDataset | ||
from etna.loggers import ClearMLLogger | ||
from etna.loggers import tslogger | ||
from etna.pipeline import Pipeline | ||
from etna.models.nn import MLPModel | ||
from etna.transforms import LagTransform, StandardScalerTransform | ||
from joblib import Parallel,delayed | ||
|
||
FILE_PATH = Path(__file__) | ||
|
||
OmegaConf.register_new_resolver("range", lambda x, y: list(range(x, y))) | ||
OmegaConf.register_new_resolver("sum", lambda x, y: x + y) | ||
|
||
def set_seed(seed: int = 42): | ||
random.seed(seed) | ||
np.random.seed(seed) | ||
|
||
|
||
def init_logger(config: dict, project: str = "a.p.chikov/test/clearml_basic", tags: Optional[list] = ["test", "clearml", "nn"]): | ||
tslogger.loggers = [] | ||
cml_logger = ClearMLLogger(project_name=project, tags=tags, config=config, auto_connect_frameworks=True) | ||
tslogger.add(cml_logger) | ||
|
||
|
||
|
||
|
||
@hydra.main(config_name="config.yaml") | ||
def backtest(cfg: DictConfig): | ||
config = OmegaConf.to_container(cfg, resolve=True) | ||
|
||
# Set seed for reproducibility | ||
set_seed(cfg.seed) | ||
|
||
logger = ClearMLLogger(project_name="a.p.chikov/test/clearml_basic", task_name="conc_example", | ||
tags=["test", "clearml", "nn"], auto_connect_frameworks=True) | ||
def log(i, ob): | ||
logger.task.logger.report_scalar(title="lol", series=f"lol_{ob}", iteration=i, value=i) | ||
|
||
obj = np.random.randint(0, 3, size=1000) | ||
|
||
Parallel(n_jobs=3)( | ||
delayed(log)(i, ob) for i,ob in enumerate(obj) | ||
) | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
backtest() |
Oops, something went wrong.