{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from power_cogs.callbacks.callback import *\n",
    "from power_cogs.callbacks.logger_callback import *\n",
    "from power_cogs.callbacks.class_method_callback import ClassMethodCallback"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:17: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class AdamConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:27: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class LambdaLRConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:35: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class MultiplicativeLRConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:43: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class StepLRConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:52: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class MultiStepLRConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:61: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class ExponentialLRConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:69: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class CosineAnnealingLRConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:78: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class ReduceLROnPlateauConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:93: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class CyclicLRConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:111: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class CosineAnnealingWarmRestartsConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:121: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class OneCycleLRConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:141: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class DataLoaderConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:158: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class DatasetConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:163: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class ChainDatasetConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:169: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class ConcatDatasetConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:175: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class IterableDatasetConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:180: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class TensorDatasetConf:\n",
      "/home/shyam/anaconda3/envs/py38/lib/python3.8/site-packages/power_cogs-0.1.1-py3.8.egg/power_cogs/config/torch/torch_config.py:186: RuntimeWarning: fields may not start with an underscore, ignoring \"_target_\"\n",
      "  class SubsetConf:\n"
     ]
    }
   ],
   "source": [
    "from power_cogs.config.config import load_config\n",
    "from power_cogs.examples.mnist.mnist_trainer import MNISTTrainer\n",
    "from typing import Dict, Any, Optional\n",
    "from omegaconf import OmegaConf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "mnist = MNISTTrainer.from_config_file(\"mnist.yaml\",\n",
    "                                      overrides={\"logging_config\":{\"checkpoint_interval\":5}})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'MNISTTrainer', 'visualize': False, 'batch_size': 32, 'epochs': 1000, 'early_stoppage': False, 'logging_config': {'mlflow': {'experiment_name': None, 'save_artifact': False}, 'wandb': {'project': None, 'api_key_file': None, 'log_config': False, 'reinit': False}, 'checkpoint_path': 'checkpoints', 'tensorboard_log_path': None, 'checkpoint_interval': 5}, 'stoppage_config': {'batch_size': 32, 'epochs': 1000, 'early_stoppage': False, 'loss_threshold': -inf, 'stop': None, 'callbacks': []}, 'tune_config': {'metric': 'loss', 'mode': 'min', 'num_samples': 1, 'name': '', 'checkpoint_freq': 5, 'checkpoint_at_end': True, 'callbacks': [], 'additional_config': {}}, 'optimizer_config': {'_target_': 'torch.optim.adam.Adam', 'params': '???', 'lr': 0.001, 'betas': [0.9, 0.999], 'eps': 1e-08, 'weight_decay': 0, 'amsgrad': False}, 'scheduler_config': {'_target_': 'torch.optim.lr_scheduler.ExponentialLR', 'optimizer': '???', 'gamma': 0.9999, 'last_epoch': -1}, 'dataloader_config': {'_target_': 'torch.utils.data.dataloader.DataLoader', 'dataset': '???', 'batch_size': 1, 'shuffle': False, 'sampler': None, 'batch_sampler': None, 'num_workers': 0, 'collate_fn': None, 'pin_memory': False, 'drop_last': False, 'timeout': 0, 'worker_init_fn': None, 'multiprocessing_context': None, 'generator': None}, 'cluster_config': {'name': '', 'cluster_config_path': None, 'join_cluster': False}, 'model_config': {'input_dims': 64, 'hidden_dims': [32], 'output_dims': 10, 'output_activation': None, 'use_normal_init': True, 'normal_std': 1.0, 'zero_bias': False}}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mnist.config"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-08-25 18:14:56.066 | INFO     | power_cogs.callbacks.tensorboard_callback:setup:40 - Follow tensorboard logs with: tensorboard --logdir checkpoints/2021-08-25-18:14:54_MNISTTrainer/tensorboard_logs\n",
      "accuracy:0.9488035614913745--loss:0.17829859492638664--min_loss:5.8412379075889476e-06--max_loss:8.888566970825195--mean_loss:0.17829859492638664--sum_loss:320.4025750827168--median_loss:0.017928097397089005--epoch:9: 100%|██████████| 10/10 [00:14<00:00,  1.47s/it]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'accuracy': 0.9488035614913745,\n",
       " 'loss': 0.17829859492638664,\n",
       " 'min_loss': 5.8412379075889476e-06,\n",
       " 'max_loss': 8.888566970825195,\n",
       " 'mean_loss': 0.17829859492638664,\n",
       " 'sum_loss': 320.4025750827168,\n",
       " 'median_loss': 0.017928097397089005,\n",
       " 'epoch': 9}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mnist.train(32, 10)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:py38] *",
   "language": "python",
   "name": "conda-env-py38-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
