# Path: src/tests/pipeline.py
# def some_small_clusters_some_empty(K, q):
# def one_small_rare_cluster(K):
#     def __init__(self, j, n_obs, d, C, ver='A'):
#     def generate_data(self, savedir):
#     def data(self):
#     def p(self):
#     def __init__(self, j, n_obs, d=3, C=4, ver='A'):
#     def __init__(self, j, n_obs, d=2, C=None, ver='A'):
#     def __init__(self, J, K, N, d, C=None, data_class=SynSample, ver='A',
#                  par_file='src/tests/param/0.py', run=None,
#                  copy_data=False, comm=MPI.COMM_WORLD):
#     def generate_data(self):
#     def setup_run(self):
#     def init_hGMM(self, method='EM_pooled', WIS=False, rho=2, n_iter=20,
#                   n_init=10, plotting=False, selection='likelihood', gamma=2):
#     def pre_burnin(self):
#     def MCMC(self, plot_sim=False, save_hGMM=False):
#     def load_res(self, comm=MPI.COMM_SELF):
#     def postproc(self, comm=MPI.COMM_SELF):
#     def number_label_switches(self):
#     def quality_check(self):
#     def plot(self):
#     def clean_up(self):
#     def run(self, init_method='EM_pooled', WIS=False, rho=2, init_n_iter=20,
#             n_init=10, init_plotting=False, init_selection='likelihood', gamma=2,
#             plot_sim=False, pre_burnin=True, save_hGMM=False):
# class SynSamp(object):
# class SynSample(SynSamp):
# class SynSample2(SynSamp):
# class Pipeline(object):
# 
# Path: src/tests/test_modified_label_sw.py
# class TrackDict(SaveDict):
# 
#     def add_to(self, key, value=1):
#         self.load()
#         try:
#             self._dic[key] += value
#         except KeyError:
#             self._dic[key] = value
#         self.save()
# 
#     def append_to(self, key, value):
#         self.load()
#         try:
#             self._dic[key].append(value)
#         except KeyError:
#             self._dic[key] = [value]
#         self.save()
# 
#     def print_table(self):
#         self.load()
#         dict_ = self._dic
#         width = min(max([len(str(key)) for key in dict_.keys()]), 15)
#         print("\n".join("{:<{width}s}  {}".format(
#             str(key), dict_[key], width=width) for key in sorted(dict_.keys())))


import os
import numpy as np
import matplotlib.pyplot as plt
from mpi4py import MPI
from .pipeline import Pipeline, SynSample2, BadQualityError
from .test_modified_label_sw import TrackDict
        os.mkdir('src/tests/cache')
    quality_res = TrackDict(fname)

    fname = 'src/tests/cache/initialization_runs.pkl'
    run_res = TrackDict(fname)

n_iters = [50, 100, 200, 500]

if 0:
    for i in range(10):
        for n_iter in n_iters:
            pipeline = Pipeline(J=5, K=15, N=1000, d=3,
                                data_class=SynSample2, ver='C', copy_data=True,
                                par_file='src/tests/param/0.py', comm=comm)
            pipeline.run(init_method='EM_pooled', WIS=False, rho=2, init_n_iter=n_iter,
                         n_init=10, init_plotting=False, init_selection='likelihood', gamma=2)
            if rank == 0:
                run_res.append_to(n_iter, (pipeline.run_nbr, pipeline.logdata['t_init']))
                run_res.print_table()

if rank == 0:
    emd_all = []
    log_lik_all = []
    for n_iter in n_iters:

        if 1:
            runinfos = run_res.get(n_iter)
            for (run_nbr, time) in runinfos:
                quality_res.append_to('Initialization time, iterations: {}, '.format(n_iter),
                                      time)

# Path: src/tests/pipeline.py
# def some_small_clusters_some_empty(K, q):
# def one_small_rare_cluster(K):
#     def __init__(self, j, n_obs, d, C, ver='A'):
#     def generate_data(self, savedir):
#     def data(self):
#     def p(self):
#     def __init__(self, j, n_obs, d=3, C=4, ver='A'):
#     def __init__(self, j, n_obs, d=2, C=None, ver='A'):
#     def __init__(self, J, K, N, d, C=None, data_class=SynSample, ver='A',
#                  par_file='src/tests/param/0.py', run=None,
#                  copy_data=False, comm=MPI.COMM_WORLD):
#     def generate_data(self):
#     def setup_run(self):
#     def init_hGMM(self, method='EM_pooled', WIS=False, rho=2, n_iter=20,
#                   n_init=10, plotting=False, selection='likelihood', gamma=2):
#     def pre_burnin(self):
#     def MCMC(self, plot_sim=False, save_hGMM=False):
#     def load_res(self, comm=MPI.COMM_SELF):
#     def postproc(self, comm=MPI.COMM_SELF):
#     def number_label_switches(self):
#     def quality_check(self):
#     def plot(self):
#     def clean_up(self):
#     def run(self, init_method='EM_pooled', WIS=False, rho=2, init_n_iter=20,
#             n_init=10, init_plotting=False, init_selection='likelihood', gamma=2,
#             plot_sim=False, pre_burnin=True, save_hGMM=False):
# class SynSamp(object):
# class SynSample(SynSamp):
# class SynSample2(SynSamp):
# class Pipeline(object):
# 
# Path: src/tests/test_modified_label_sw.py
# class TrackDict(SaveDict):
# 
#     def add_to(self, key, value=1):
#         self.load()
#         try:
#             self._dic[key] += value
#         except KeyError:
#             self._dic[key] = value
#         self.save()
# 
#     def append_to(self, key, value):
#         self.load()
#         try:
#             self._dic[key].append(value)
#         except KeyError:
#             self._dic[key] = [value]
#         self.save()
# 
#     def print_table(self):
#         self.load()
#         dict_ = self._dic
#         width = min(max([len(str(key)) for key in dict_.keys()]), 15)
#         print("\n".join("{:<{width}s}  {}".format(
#             str(key), dict_[key], width=width) for key in sorted(dict_.keys())))


# Path: src/tests/test_initialization_iterations.py
import os
import numpy as np
import matplotlib.pyplot as plt
from mpi4py import MPI
from .pipeline import Pipeline, SynSample2, BadQualityError
from .test_modified_label_sw import TrackDict

        os.mkdir('src/tests/cache')
    quality_res = TrackDict(fname)

    fname = 'src/tests/cache/initialization_runs.pkl'
    run_res = TrackDict(fname)

n_iters = [50, 100, 200, 500]

if 0:
    for i in range(10):
        for n_iter in n_iters:
            pipeline = Pipeline(J=5, K=15, N=1000, d=3,
                                data_class=SynSample2, ver='C', copy_data=True,
                                par_file='src/tests/param/0.py', comm=comm)
            pipeline.run(init_method='EM_pooled', WIS=False, rho=2, init_n_iter=n_iter,
                         n_init=10, init_plotting=False, init_selection='likelihood', gamma=2)
            if rank == 0:
                run_res.append_to(n_iter, (pipeline.run_nbr, pipeline.logdata['t_init']))
                run_res.print_table()

if rank == 0:
    emd_all = []
    log_lik_all = []
    for n_iter in n_iters:

        if 1:
            runinfos = run_res.get(n_iter)
            for (run_nbr, time) in runinfos:
                quality_res.append_to('Initialization time, iterations: {}, '.format(n_iter),
                                      time)

                pipeline = Pipeline(J=5, K=15, N=1000, d=3, data_class=SynSample2, ver='B',