# Path: ldif/inference/experiment.py
# def to_xid(job):
#   def __init__(self, parent_job, idx):
#   def relpath(self):
#   def directory(self):
#   def abspath(self):
#   def __init__(self, parent_experiment, job_str, use_temp_ckpts='warn'):
#   def from_xid(cls, parent_experiment, xid):
#   def _ensure_lazy_attrs_are_zero(self):
#   def set_use_temp_ckpts(self, useable):
#   def is_visible(self):
#   def ensure_visible(self):
#   def ckpt_dir(self):
#   def root_dir(self):
#   def all_checkpoint_indices(self):
#   def all_checkpoints(self):
#   def latest_checkpoint_before(self, idx, must_equal=False):
#   def has_at_least_one_checkpoint(self):
#   def ensure_has_at_least_one_checkpoint(self):
#   def checkpoint_count(self):
#   def newest_checkpoint(self):
#   def k_evenly_spaced_checkpoints(self, k):
#   def hparams(self):
#   def model_config(self):
#   def __init__(self, model_dir, model_name, experiment_name):
#   def set_order(self, ordered_xids):
#   def job_with_xid(self, xid):
#   def filter_jobs_by_xid(self, xids):
#   def visible_jobs(self):
#   def visible_job_count(self):
#   def visible_xids(self):
#   def job_from_xmanager_id(self, xid, must_be_visible=True):
#   def job_from_job_str(self, job_str, must_be_visible=True):
#   def __init__(self, experiment, desired_ckpts=-1):
#   def local_root(self):
#   def remote_root(self):
#   def remote_result_ckpt_dir(self, xid):
#   def local_result_ckpt_dir(self, xid):
#   def ckpts_for_xid_and_split(self, xid, split):
#   def ckpt_for_xid(self, xid, split):
#   def remote_result_base(self, xid, split):
#   def all_remote_mesh_names(self, split, ensure_nonempty=True):
#   def copy_meshes(self, mesh_names, split, overwrite_if_present=True):
#   def random_remote_mesh_names(self, count, split):
#   def remote_path_to_mesh(self, mesh_name, xid, split):
#   def local_path_to_mesh(self, mesh_name, xid, split):
#   def _mesh_relative_path(self, mesh_name):
#   def local_qual_path(self):
#   def __init__(self, hparams):
# class Checkpoint(object):
# class Job(object):
# class Experiment(object):
# class ResultStore(object):
# class ModelConfig(object):
# 
# Path: ldif/inference/util.py
# def parse_xid_str(xidstr):
# def ensure_split_valid(split):
# def ensure_category_valid(category):
# def ensure_synset_valid(synset):
# def ensure_hash_valid(h):
# def parse_xid_to_ckpt(xid_to_ckpt):
# def get_npz_paths(split, category, modifier=''):
# def get_mesh_identifiers(split, category):
# def get_rgb_paths(split, category, modifier=''):
# def rgb_path_to_synset_and_hash(rgb_path):
# def rgb_path_to_npz_path(rgb_path, split, dataset='shapenet-occnet'):
# def parse_npz_path(path):
# def read_png_to_float_npy_with_reraising(path):
# 
# Path: ldif/util/file_util.py
# def readlines(p):
# def readbin(p):
# def writebin(p, s):
# def writetxt(p, s):
# def write_np(path, arr):
# def read_grd(path):
# def read_sif_v1(path, verbose=False):
# def read_lines(p):
# def read_image(p):
# def read_npz(p):
# def read_np(p):
# def read_txt_to_np(p):
# def read_py2_pkl(p):
# def write_mesh(path, mesh):
# def read_mesh(path):
# def read_csv(path):
# def read_normals(path_to_dir, im_count=20, leading='_depth'):
# def write_points(path_ext_optional, points):
# def write_grd(path, volume, world2grid=None):
# def write_depth_image(path, depth_image):


import sys
from ldif.inference import experiment
from ldif.inference import util as inference_util
from ldif.util.file_util import log
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""Builds the worker tasks for the beam job."""


# LDIF is an internal package, should be imported last.
# pylint: disable=g-bad-import-order
# pylint: enable=g-bad-import-order


def generate_models(flags):
  """Makes all the dictionaries that workers can process in parallel."""

  # TODO(kgenova) If the code fails here, add a model_dir argument.
  cur_experiment = experiment.Experiment(flags.model_dir,
                                         flags.model_name,
                                         flags.experiment_name)

  xids = inference_util.parse_xid_str(flags.xids)
  cur_experiment.filter_jobs_by_xid(xids)
  cur_experiment.set_order(xids)
  log.info('XIDs to run on: %s' % repr(cur_experiment.visible_xids))

  if not (flags.ckpt or flags.xid_to_ckpt):
    log.info('Choose a checkpoint and rerun:')
    for job in cur_experiment.visible_jobs:
      if not job.has_at_least_one_checkpoint:

# Path: ldif/inference/experiment.py
# def to_xid(job):
#   def __init__(self, parent_job, idx):
#   def relpath(self):
#   def directory(self):
#   def abspath(self):
#   def __init__(self, parent_experiment, job_str, use_temp_ckpts='warn'):
#   def from_xid(cls, parent_experiment, xid):
#   def _ensure_lazy_attrs_are_zero(self):
#   def set_use_temp_ckpts(self, useable):
#   def is_visible(self):
#   def ensure_visible(self):
#   def ckpt_dir(self):
#   def root_dir(self):
#   def all_checkpoint_indices(self):
#   def all_checkpoints(self):
#   def latest_checkpoint_before(self, idx, must_equal=False):
#   def has_at_least_one_checkpoint(self):
#   def ensure_has_at_least_one_checkpoint(self):
#   def checkpoint_count(self):
#   def newest_checkpoint(self):
#   def k_evenly_spaced_checkpoints(self, k):
#   def hparams(self):
#   def model_config(self):
#   def __init__(self, model_dir, model_name, experiment_name):
#   def set_order(self, ordered_xids):
#   def job_with_xid(self, xid):
#   def filter_jobs_by_xid(self, xids):
#   def visible_jobs(self):
#   def visible_job_count(self):
#   def visible_xids(self):
#   def job_from_xmanager_id(self, xid, must_be_visible=True):
#   def job_from_job_str(self, job_str, must_be_visible=True):
#   def __init__(self, experiment, desired_ckpts=-1):
#   def local_root(self):
#   def remote_root(self):
#   def remote_result_ckpt_dir(self, xid):
#   def local_result_ckpt_dir(self, xid):
#   def ckpts_for_xid_and_split(self, xid, split):
#   def ckpt_for_xid(self, xid, split):
#   def remote_result_base(self, xid, split):
#   def all_remote_mesh_names(self, split, ensure_nonempty=True):
#   def copy_meshes(self, mesh_names, split, overwrite_if_present=True):
#   def random_remote_mesh_names(self, count, split):
#   def remote_path_to_mesh(self, mesh_name, xid, split):
#   def local_path_to_mesh(self, mesh_name, xid, split):
#   def _mesh_relative_path(self, mesh_name):
#   def local_qual_path(self):
#   def __init__(self, hparams):
# class Checkpoint(object):
# class Job(object):
# class Experiment(object):
# class ResultStore(object):
# class ModelConfig(object):
# 
# Path: ldif/inference/util.py
# def parse_xid_str(xidstr):
# def ensure_split_valid(split):
# def ensure_category_valid(category):
# def ensure_synset_valid(synset):
# def ensure_hash_valid(h):
# def parse_xid_to_ckpt(xid_to_ckpt):
# def get_npz_paths(split, category, modifier=''):
# def get_mesh_identifiers(split, category):
# def get_rgb_paths(split, category, modifier=''):
# def rgb_path_to_synset_and_hash(rgb_path):
# def rgb_path_to_npz_path(rgb_path, split, dataset='shapenet-occnet'):
# def parse_npz_path(path):
# def read_png_to_float_npy_with_reraising(path):
# 
# Path: ldif/util/file_util.py
# def readlines(p):
# def readbin(p):
# def writebin(p, s):
# def writetxt(p, s):
# def write_np(path, arr):
# def read_grd(path):
# def read_sif_v1(path, verbose=False):
# def read_lines(p):
# def read_image(p):
# def read_npz(p):
# def read_np(p):
# def read_txt_to_np(p):
# def read_py2_pkl(p):
# def write_mesh(path, mesh):
# def read_mesh(path):
# def read_csv(path):
# def read_normals(path_to_dir, im_count=20, leading='_depth'):
# def write_points(path_ext_optional, points):
# def write_grd(path, volume, world2grid=None):
# def write_depth_image(path, depth_image):


# Path: ldif/results/build_inputs.py
import sys
from ldif.inference import experiment
from ldif.inference import util as inference_util
from ldif.util.file_util import log

# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""Builds the worker tasks for the beam job."""


# LDIF is an internal package, should be imported last.
# pylint: disable=g-bad-import-order
# pylint: enable=g-bad-import-order


def generate_models(flags):
  """Makes all the dictionaries that workers can process in parallel."""

  # TODO(kgenova) If the code fails here, add a model_dir argument.
  cur_experiment = experiment.Experiment(flags.model_dir,
                                         flags.model_name,
                                         flags.experiment_name)

  xids = inference_util.parse_xid_str(flags.xids)
  cur_experiment.filter_jobs_by_xid(xids)
  cur_experiment.set_order(xids)
  log.info('XIDs to run on: %s' % repr(cur_experiment.visible_xids))

  if not (flags.ckpt or flags.xid_to_ckpt):
    log.info('Choose a checkpoint and rerun:')
    for job in cur_experiment.visible_jobs:
      if not job.has_at_least_one_checkpoint:

        log.info('XID %i: No checkpoints written.' % job.xid)