# Path: qnd/experiment.py
# def def_def_experiment_fn(batch_inputs=True,
#                           prepare_filename_queues=True,
#                           distributed=False):
#     adder = FlagAdder()
# 
#     for mode in [tf.contrib.learn.ModeKeys.TRAIN,
#                  tf.contrib.learn.ModeKeys.EVAL]:
#         adder.add_flag(
#             "{}_steps".format(mode),
#             type=int,
#             default=(100 if mode == tf.contrib.learn.ModeKeys.EVAL else None),
#             help="Maximum number of {} steps".format(mode))
# 
#     adder.add_flag(
#         "min_eval_frequency", type=int, default=1,
#         help="Minimum evaluation frequency in number of train steps")
# 
#     estimator = def_estimator(distributed)
#     def_train_input_fn = def_def_train_input_fn(batch_inputs,
#                                                 prepare_filename_queues)
#     def_eval_input_fn = def_def_eval_input_fn(batch_inputs,
#                                               prepare_filename_queues)
# 
#     def def_experiment_fn(model_fn,
#                           train_input_fn,
#                           eval_input_fn=None,
#                           serving_input_fn=None):
#         def experiment_fn(output_dir):
#             return tf.contrib.learn.Experiment(
#                 estimator(model_fn, output_dir),
#                 def_train_input_fn(train_input_fn),
#                 def_eval_input_fn(eval_input_fn or train_input_fn),
#                 export_strategies=(serving_input_fn and [
#                     tf.contrib.learn.make_export_strategy(serving_input_fn),
#                 ]),
#                 **adder.flags)
# 
#         return experiment_fn
# 
#     return def_experiment_fn
# 
# Path: qnd/flag.py
# FLAGS = gargparse.ARGS
# 
# def add_output_dir_flag():
#     add_flag("output_dir",
#              default="output",
#              help="Directory where checkpoint and event files are stored")


from tensorflow.contrib.learn.python.learn.learn_runner import run
from .experiment import def_def_experiment_fn
from .flag import FLAGS, add_output_dir_flag

        - Args
            - `model_fn`: A function to construct a model.
                - Types of its arguments must be one of the following:
                    - `Tensor, ...`
                    - `Tensor, ..., mode=ModeKeys`
                - Types of its return values must be one of the following:
                    - `Tensor, Tensor, Operation, eval_metric_ops=dict<str, Tensor>`
                        (predictions, loss, train_op, and eval_metric_ops (if any))
                    - `ModelFnOps`
            - `train_input_fn`, `eval_input_fn`: Functions to create input
                Tensors fed into the model. If `eval_input_fn` is `None`,
                `train_input_fn` will be used instead.
                - Types of its arguments must be one of the following:
                    - `QueueBase` (a filename queue)
                    - No argument if `prepare_filename_queues` of
                        `def_train_and_evaluate()` is `False`.
                - Types of its return values must be one of the following:
                    - `Tensor, Tensor` (features and targets)
                    - `dict<str, Tensor>, dict<str, Tensor>` (features and targets)
                        - The keys in `dict` objects must match with argument
                            names of `model_fn`.

        - Returns
            - Return value of `tf.contrib.learn.python.learn.learn_runner.run()`.
        """
        return run(def_experiment_fn(model_fn,
                                     train_input_fn,
                                     eval_input_fn,
                                     serving_input_fn),

# Path: qnd/experiment.py
# def def_def_experiment_fn(batch_inputs=True,
#                           prepare_filename_queues=True,
#                           distributed=False):
#     adder = FlagAdder()
# 
#     for mode in [tf.contrib.learn.ModeKeys.TRAIN,
#                  tf.contrib.learn.ModeKeys.EVAL]:
#         adder.add_flag(
#             "{}_steps".format(mode),
#             type=int,
#             default=(100 if mode == tf.contrib.learn.ModeKeys.EVAL else None),
#             help="Maximum number of {} steps".format(mode))
# 
#     adder.add_flag(
#         "min_eval_frequency", type=int, default=1,
#         help="Minimum evaluation frequency in number of train steps")
# 
#     estimator = def_estimator(distributed)
#     def_train_input_fn = def_def_train_input_fn(batch_inputs,
#                                                 prepare_filename_queues)
#     def_eval_input_fn = def_def_eval_input_fn(batch_inputs,
#                                               prepare_filename_queues)
# 
#     def def_experiment_fn(model_fn,
#                           train_input_fn,
#                           eval_input_fn=None,
#                           serving_input_fn=None):
#         def experiment_fn(output_dir):
#             return tf.contrib.learn.Experiment(
#                 estimator(model_fn, output_dir),
#                 def_train_input_fn(train_input_fn),
#                 def_eval_input_fn(eval_input_fn or train_input_fn),
#                 export_strategies=(serving_input_fn and [
#                     tf.contrib.learn.make_export_strategy(serving_input_fn),
#                 ]),
#                 **adder.flags)
# 
#         return experiment_fn
# 
#     return def_experiment_fn
# 
# Path: qnd/flag.py
# FLAGS = gargparse.ARGS
# 
# def add_output_dir_flag():
#     add_flag("output_dir",
#              default="output",
#              help="Directory where checkpoint and event files are stored")


# Path: qnd/train_and_evaluate.py
from tensorflow.contrib.learn.python.learn.learn_runner import run
from .experiment import def_def_experiment_fn
from .flag import FLAGS, add_output_dir_flag


        - Args
            - `model_fn`: A function to construct a model.
                - Types of its arguments must be one of the following:
                    - `Tensor, ...`
                    - `Tensor, ..., mode=ModeKeys`
                - Types of its return values must be one of the following:
                    - `Tensor, Tensor, Operation, eval_metric_ops=dict<str, Tensor>`
                        (predictions, loss, train_op, and eval_metric_ops (if any))
                    - `ModelFnOps`
            - `train_input_fn`, `eval_input_fn`: Functions to create input
                Tensors fed into the model. If `eval_input_fn` is `None`,
                `train_input_fn` will be used instead.
                - Types of its arguments must be one of the following:
                    - `QueueBase` (a filename queue)
                    - No argument if `prepare_filename_queues` of
                        `def_train_and_evaluate()` is `False`.
                - Types of its return values must be one of the following:
                    - `Tensor, Tensor` (features and targets)
                    - `dict<str, Tensor>, dict<str, Tensor>` (features and targets)
                        - The keys in `dict` objects must match with argument
                            names of `model_fn`.

        - Returns
            - Return value of `tf.contrib.learn.python.learn.learn_runner.run()`.
        """
        return run(def_experiment_fn(model_fn,
                                     train_input_fn,
                                     eval_input_fn,
                                     serving_input_fn),

                   FLAGS.output_dir)