# 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
    if tool == 'timers':
        env.setdefault('TREECAT_PROFILE', '1')
        env.setdefault('TREECAT_LOG_LEVEL', '20')
        check_call_env([PYTHON, '-O'] + cmd, env)
    elif tool == 'time':
        if platform.platform().startswith('Darwin'):
            gnu_time = 'gtime'
        else:
            gnu_time = '/usr/bin/time'
        check_call_env([gnu_time, '-v', PYTHON, '-O'] + cmd, env)
    elif tool == 'snakeviz':
        check_call_env([PYTHON, '-m', 'cProfile', '-o', profile_path] + cmd,
                       env)
        check_call(['snakeviz', profile_path])
    elif tool == 'line_profiler':
        check_call_env(['kernprof', '-l', '-v', '-o', profile_path] + cmd, env)
    elif tool == 'pdb':
        check_call_env([PYTHON, '-m', 'pdb'] + cmd, env)
    else:
        raise ValueError('Unknown tool: {}'.format(tool))


@parsable
def train_files(dataset_path, config_path):
    """INTERNAL Train from pickled dataset, config."""
    dataset = pickle_load(dataset_path)
    table = dataset['table']
    V = table.num_cols
    K = V * (V - 1) // 2
    tree_prior = np.zeros(K, dtype=np.float32)

# 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

    if tool == 'timers':
        env.setdefault('TREECAT_PROFILE', '1')
        env.setdefault('TREECAT_LOG_LEVEL', '20')
        check_call_env([PYTHON, '-O'] + cmd, env)
    elif tool == 'time':
        if platform.platform().startswith('Darwin'):
            gnu_time = 'gtime'
        else:
            gnu_time = '/usr/bin/time'
        check_call_env([gnu_time, '-v', PYTHON, '-O'] + cmd, env)
    elif tool == 'snakeviz':
        check_call_env([PYTHON, '-m', 'cProfile', '-o', profile_path] + cmd,
                       env)
        check_call(['snakeviz', profile_path])
    elif tool == 'line_profiler':
        check_call_env(['kernprof', '-l', '-v', '-o', profile_path] + cmd, env)
    elif tool == 'pdb':
        check_call_env([PYTHON, '-m', 'pdb'] + cmd, env)
    else:
        raise ValueError('Unknown tool: {}'.format(tool))


@parsable
def train_files(dataset_path, config_path):
    """INTERNAL Train from pickled dataset, config."""
    dataset = pickle_load(dataset_path)
    table = dataset['table']
    V = table.num_cols
    K = V * (V - 1) // 2
    tree_prior = np.zeros(K, dtype=np.float32)

    config = pickle_load(config_path)