# Path: treecat/config.py
# def make_config(**options):
#     """Create a new global config dict with default values."""
#     config = DEFAULT_CONFIG.copy()
#     for key, value in options.items():
#         if key not in config:
#             raise ValueError('Unknown option: {}. Try one of:\n  {}'.format(
#                 key, '\n  '.join(sorted(config.keys()))))
#         config[key] = int(value)
#     return config
# 
# Path: treecat/format.py
# def pickle_dump(data, filename):
#     """Serialize data to file using gzip compression."""
#     if filename.endswith('.pkz'):
#         with gzip.open(filename, 'wb') as f:
#             pickle.dump(data, f, protocol=2)  # Try to support python 2.
#     elif filename.endswith('.jz'):
#         with gzip.open(filename, 'wt') as f:
#             f.write(json_dumps(data))
#     else:
#         raise ValueError(
#             'Cannot determine format: {}'.format(os.path.basename(filename)))
# 
# Path: treecat/format.py
# def pickle_load(filename):
#     """Deserialize data from file using gzip compression."""
#     if filename.endswith('.pkz'):
#         with gzip.open(filename, 'rb') as f:
#             return pickle.load(f)
#     elif filename.endswith('.jz'):
#         with gzip.open(filename, 'rt') as f:
#             return json_loads(f.read())
#     else:
#         raise ValueError(
#             'Cannot determine format: {}'.format(os.path.basename(filename)))
# 
# Path: treecat/testutil.py
# @contextlib.contextmanager
# def tempdir():
#     dirname = tempfile.mkdtemp()
#     try:
#         yield dirname
#     finally:
#         shutil.rmtree(dirname)


import os
import platform
import sys
import numpy as np
    import numpy as np
from subprocess import CalledProcessError
from subprocess import Popen
from subprocess import check_call
from parsable import parsable
from treecat.config import make_config
from treecat.format import pickle_dump
from treecat.format import pickle_load
from treecat.testutil import tempdir
    from treecat.training import train_ensemble
    from treecat.serving import TreeCatServer
    from treecat.generate import generate_dataset_file
    from treecat.generate import generate_model_file
    from treecat.generate import generate_dataset_file
    from treecat.validate import train
        learning_parallel=parallel)
    dataset_path = generate_dataset_file(rows, cols)
    with tempdir() as dirname:
        config_path = os.path.join(dirname, 'config.pkz')
        pickle_dump(config, config_path)
        cmd = [FILE, 'train_files', dataset_path, config_path]
        run_with_tool(cmd, tool, dirname)


@parsable
def serve(rows=100, cols=10, cats=4, tool='timers'):
    """Profile TreeCatServer on a random dataset.
    Available tools: timers, time, snakeviz, line_profiler, pdb
    """
    config = make_config()
    model_path = generate_model_file(rows, cols, cats)
    with tempdir() as dirname:
        config_path = os.path.join(dirname, 'config.pkz')
        pickle_dump(config, config_path)
        cmd = [FILE, 'serve_files', model_path, config_path, str(rows)]
        run_with_tool(cmd, tool, dirname)


@parsable
def eval(rows=100, cols=10, cats=4, tool='timers'):
    """Profile treecat.validate.eval on a random dataset.
    Available tools: timers, time, snakeviz, line_profiler, pdb
    """
    dataset_path = generate_dataset_file(rows, cols)
    validate_py = os.path.join(os.path.dirname(FILE), 'validate.py')

# Path: treecat/config.py
# def make_config(**options):
#     """Create a new global config dict with default values."""
#     config = DEFAULT_CONFIG.copy()
#     for key, value in options.items():
#         if key not in config:
#             raise ValueError('Unknown option: {}. Try one of:\n  {}'.format(
#                 key, '\n  '.join(sorted(config.keys()))))
#         config[key] = int(value)
#     return config
# 
# Path: treecat/format.py
# def pickle_dump(data, filename):
#     """Serialize data to file using gzip compression."""
#     if filename.endswith('.pkz'):
#         with gzip.open(filename, 'wb') as f:
#             pickle.dump(data, f, protocol=2)  # Try to support python 2.
#     elif filename.endswith('.jz'):
#         with gzip.open(filename, 'wt') as f:
#             f.write(json_dumps(data))
#     else:
#         raise ValueError(
#             'Cannot determine format: {}'.format(os.path.basename(filename)))
# 
# Path: treecat/format.py
# def pickle_load(filename):
#     """Deserialize data from file using gzip compression."""
#     if filename.endswith('.pkz'):
#         with gzip.open(filename, 'rb') as f:
#             return pickle.load(f)
#     elif filename.endswith('.jz'):
#         with gzip.open(filename, 'rt') as f:
#             return json_loads(f.read())
#     else:
#         raise ValueError(
#             'Cannot determine format: {}'.format(os.path.basename(filename)))
# 
# Path: treecat/testutil.py
# @contextlib.contextmanager
# def tempdir():
#     dirname = tempfile.mkdtemp()
#     try:
#         yield dirname
#     finally:
#         shutil.rmtree(dirname)


# Path: treecat/profile.py
import os
import platform
import sys
import numpy as np
    import numpy as np
from subprocess import CalledProcessError
from subprocess import Popen
from subprocess import check_call
from parsable import parsable
from treecat.config import make_config
from treecat.format import pickle_dump
from treecat.format import pickle_load
from treecat.testutil import tempdir
    from treecat.training import train_ensemble
    from treecat.serving import TreeCatServer
    from treecat.generate import generate_dataset_file
    from treecat.generate import generate_model_file
    from treecat.generate import generate_dataset_file
    from treecat.validate import train

        learning_parallel=parallel)
    dataset_path = generate_dataset_file(rows, cols)
    with tempdir() as dirname:
        config_path = os.path.join(dirname, 'config.pkz')
        pickle_dump(config, config_path)
        cmd = [FILE, 'train_files', dataset_path, config_path]
        run_with_tool(cmd, tool, dirname)


@parsable
def serve(rows=100, cols=10, cats=4, tool='timers'):
    """Profile TreeCatServer on a random dataset.
    Available tools: timers, time, snakeviz, line_profiler, pdb
    """
    config = make_config()
    model_path = generate_model_file(rows, cols, cats)
    with tempdir() as dirname:
        config_path = os.path.join(dirname, 'config.pkz')
        pickle_dump(config, config_path)
        cmd = [FILE, 'serve_files', model_path, config_path, str(rows)]
        run_with_tool(cmd, tool, dirname)


@parsable
def eval(rows=100, cols=10, cats=4, tool='timers'):
    """Profile treecat.validate.eval on a random dataset.
    Available tools: timers, time, snakeviz, line_profiler, pdb
    """
    dataset_path = generate_dataset_file(rows, cols)
    validate_py = os.path.join(os.path.dirname(FILE), 'validate.py')

    with tempdir() as dirname: