def build_config(dataset, datasets_dir, phase, problem=None, output_dir='data/output'):
    """
    root@d3m-example-pod:/# cat /input/185_baseball/test_config.json
    {
      "problem_schema": "/input/TEST/problem_TEST/problemDoc.json",
      "problem_root": "/input/TEST/problem_TEST",
      "dataset_schema": "/input/TEST/dataset_TEST/datasetDoc.json",
      "test_data_root": "/input/TEST/dataset_TEST",
      "results_root": "/output/predictions",
      "executables_root": "/output/executables",
      "temp_storage_root": "/output/supporting_files"
    }
    root@d3m-example-pod:/# cat /input/185_baseball/search_config.json
    {
      "problem_schema": "/input/TRAIN/problem_TRAIN/problemDoc.json",
      "problem_root": "/input/TRAIN/problem_TRAIN",
      "dataset_schema": "/input/TRAIN/dataset_TRAIN/datasetDoc.json",
      "training_data_root": "/input/TRAIN/dataset_TRAIN",
      "pipeline_logs_root": "/output/pipelines",
      "executables_root": "/output/executables",
      "user_problems_root": "/output/user_problems",
      "temp_storage_root": "/output/supporting_files"
    }

    """

    if problem:
        full_phase = phase + '_' + problem
    else:
        full_phase = phase

    root_dir = os.path.join(datasets_dir, dataset, full_phase)
    problem_root = os.path.join(root_dir, 'problem_' + phase)
    data_root = os.path.join(root_dir, 'dataset_' + phase)

    config = {
        'problem_root': problem_root,
        'problem_schema': os.path.join(problem_root, 'problemDoc.json'),
        'dataset_schema': os.path.join(data_root, 'datasetDoc.json'),
        'executables_root': os.path.join(output_dir, 'executables'),
        'temp_storage_root': os.path.join(output_dir, 'supporting_files'),
    }

    if phase == 'TRAIN':
        config['training_data_root'] = data_root
        config['pipeline_logs_root'] = os.path.join(output_dir, 'pipelines')
    else:
        config['test_data_root'] = data_root
        config['results_root'] = os.path.join(output_dir, 'predictions')

    return config