# Path: snntoolbox/bin/run.py
# def main(filepath=None):
#     """Entry point for running the toolbox.
# 
#     Note
#     ----
# 
#     There is no need to call this function directly, because python sets up an
#     executable during :ref:`installation` that can be called from terminal.
# 
#     """
#     from snntoolbox.bin.utils import update_setup, run_pipeline
# 
#     if filepath is not None:
#         config = update_setup(filepath)
#         run_pipeline(config)
#         return
# 
#     parser = argparse.ArgumentParser(
#         description='Run SNN toolbox to convert an analog neural network into '
#                     'a spiking neural network, and optionally simulate it.')
#     parser.add_argument('config_filepath', nargs='?',
#                         help='Path to configuration file.')
#     parser.add_argument('-t', '--terminal', action='store_true',
#                         help='Set this flag to run the toolbox from terminal. '
#                              'Omit this flag to open GUI.')
#     args = parser.parse_args()
# 
#     _filepath = os.path.abspath(args.config_filepath)
#     if _filepath is not None:
#         config = update_setup(_filepath)
# 
#         if args.terminal:
#             run_pipeline(config)
#         else:
#             from snntoolbox.bin.gui import gui
#             gui.main()
#     else:
#         if args.terminal:
#             parser.error("When using the SNN toolbox from terminal, a "
#                          "config_filepath argument must be provided.")
#             return
#         else:
#             from snntoolbox.bin.gui import gui
#             gui.main()
# 
# Path: snntoolbox/utils/utils.py
# def import_configparser():
#     try:
#         import configparser
#     except ImportError:
#         # noinspection PyPep8Naming
#         import ConfigParser as configparser
# 
#     return configparser


import os
import time
import numpy as np
from tensorflow import keras
from tensorflow.keras import Input, Model
from tensorflow.keras.layers import Conv2D, AveragePooling2D, Flatten, Dense, \
    Dropout, Concatenate, BatchNormalization, Activation
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
from snntoolbox.bin.run import main
from snntoolbox.utils.utils import import_configparser
    'evaluate_ann': True,           # Test ANN on dataset before conversion.
    'normalize': True               # Normalize weights for full dynamic range.
}

config['simulation'] = {
    'simulator': 'INI',             # Chooses execution backend of SNN toolbox.
    'duration': 50,                 # Number of time steps to run each sample.
    'num_to_test': 100,             # How many test samples to run.
    'batch_size': 50,               # Batch size for simulation.
    'keras_backend': 'tensorflow'   # Which keras backend to use.
}

config['output'] = {
    'plot_vars': {                  # Various plots (slows down simulation).
        'spiketrains',              # Leave section empty to turn off plots.
        'spikerates',
        'activations',
        'correlation',
        'v_mem',
        'error_t'}
}

# Store config file.
config_filepath = os.path.join(path_wd, 'config')
with open(config_filepath, 'w') as configfile:
    config.write(configfile)

# RUN SNN TOOLBOX #
###################


# Path: snntoolbox/bin/run.py
# def main(filepath=None):
#     """Entry point for running the toolbox.
# 
#     Note
#     ----
# 
#     There is no need to call this function directly, because python sets up an
#     executable during :ref:`installation` that can be called from terminal.
# 
#     """
#     from snntoolbox.bin.utils import update_setup, run_pipeline
# 
#     if filepath is not None:
#         config = update_setup(filepath)
#         run_pipeline(config)
#         return
# 
#     parser = argparse.ArgumentParser(
#         description='Run SNN toolbox to convert an analog neural network into '
#                     'a spiking neural network, and optionally simulate it.')
#     parser.add_argument('config_filepath', nargs='?',
#                         help='Path to configuration file.')
#     parser.add_argument('-t', '--terminal', action='store_true',
#                         help='Set this flag to run the toolbox from terminal. '
#                              'Omit this flag to open GUI.')
#     args = parser.parse_args()
# 
#     _filepath = os.path.abspath(args.config_filepath)
#     if _filepath is not None:
#         config = update_setup(_filepath)
# 
#         if args.terminal:
#             run_pipeline(config)
#         else:
#             from snntoolbox.bin.gui import gui
#             gui.main()
#     else:
#         if args.terminal:
#             parser.error("When using the SNN toolbox from terminal, a "
#                          "config_filepath argument must be provided.")
#             return
#         else:
#             from snntoolbox.bin.gui import gui
#             gui.main()
# 
# Path: snntoolbox/utils/utils.py
# def import_configparser():
#     try:
#         import configparser
#     except ImportError:
#         # noinspection PyPep8Naming
#         import ConfigParser as configparser
# 
#     return configparser


# Path: examples/mnist_keras_INI.py
import os
import time
import numpy as np
from tensorflow import keras
from tensorflow.keras import Input, Model
from tensorflow.keras.layers import Conv2D, AveragePooling2D, Flatten, Dense, \
    Dropout, Concatenate, BatchNormalization, Activation
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
from snntoolbox.bin.run import main
from snntoolbox.utils.utils import import_configparser

    'evaluate_ann': True,           # Test ANN on dataset before conversion.
    'normalize': True               # Normalize weights for full dynamic range.
}

config['simulation'] = {
    'simulator': 'INI',             # Chooses execution backend of SNN toolbox.
    'duration': 50,                 # Number of time steps to run each sample.
    'num_to_test': 100,             # How many test samples to run.
    'batch_size': 50,               # Batch size for simulation.
    'keras_backend': 'tensorflow'   # Which keras backend to use.
}

config['output'] = {
    'plot_vars': {                  # Various plots (slows down simulation).
        'spiketrains',              # Leave section empty to turn off plots.
        'spikerates',
        'activations',
        'correlation',
        'v_mem',
        'error_t'}
}

# Store config file.
config_filepath = os.path.join(path_wd, 'config')
with open(config_filepath, 'w') as configfile:
    config.write(configfile)

# RUN SNN TOOLBOX #
###################


main(config_filepath)