human
Complete the below
def learn(env, q_func, lr=0.0005, max_timesteps=100000, buffer_size=50000, exploration_fraction=0.1, exploration_final_eps=0.02, train_freq=1, batch_size=32, print_freq=1, checkpoint_freq=10000, learning_starts=1000, gamma=1.0, target_network_update_freq=500, prioritized_replay=False, prioritized_replay_alpha=0.6, prioritized_replay_beta0=0.4, prioritized_replay_beta_iters=None, prioritized_replay_eps=1e-06, num_cpu=16, param_noise=False, param_noise_threshold=0.05, callback=None):

    ''''Train a deepq model.
    Parameters
    env: gym.Env
    environment to train on
    q_func: (tf.Variable, int, str, bool) -> tf.Variable
    the model that takes the following inputs:
    observation_in: object
    the output of observation placeholder
    num_actions: int
    number of actions
    scope: str
    reuse: bool
    should be passed to outer variable scope
    and returns a tensor of shape (batch_size, num_actions) with values of every action.
    lr: float
    learning rate for adam optimizer
    max_timesteps: int
    number of env steps to optimizer for
    buffer_size: int
    size of the replay buffer
    exploration_fraction: float
    fraction of entire training period over which the exploration rate is annealed
    exploration_final_eps: float
    final value of random action probability
    train_freq: int
    update the model every `train_freq` steps.
    set to None to disable printing
    batch_size: int
    size of a batched sampled from replay buffer for training
    print_freq: int
    how often to print out training progress
    set to None to disable printing
    checkpoint_freq: int
    how often to save the model. This is so that the best version is restored
    at the end of the training. If you do not wish to restore the best version at
    the end of the training set this variable to None.
    learning_starts: int
    how many steps of the model to collect transitions for before learning starts
    gamma: float
    discount factor
    target_network_update_freq: int
    update the target network every `target_network_update_freq` steps.
    prioritized_replay: True
    if True prioritized replay buffer will be used.
    prioritized_replay_alpha: float
    alpha parameter for prioritized replay buffer
    prioritized_replay_beta0: float
    initial value of beta for prioritized replay buffer
    prioritized_replay_beta_iters: int
    number of iterations over which beta will be annealed from initial value
    to 1.0. If set to None equals to max_timesteps.
   ...'''
 ... Give me a Python program to print out training progress?
assistant
#Here is Python program to print out training progress
.
    sess = U.make_session(num_cpu=num_cpu)
    sess.__enter__()
    def make_obs_ph(name):
        return U.BatchInput(env.observation_space.shape, name=name)
    (act, train, update_target, debug) = deepq.build_train(make_obs_ph=make_obs_ph, q_func=q_func, num_actions=env.action_space.n, optimizer=tf.train.AdamOptimizer(learning_rate=lr), gamma=gamma, grad_norm_clipping=10, param_noise=param_noise)
    act_params = {'make_obs_ph': make_obs_ph, 'q_func': q_func, 'num_actions': env.action_space.n}
    if prioritized_replay:
        replay_buffer = PrioritizedReplayBuffer(buffer_size, alpha=prioritized_replay_alpha)
        if (prioritized_replay_beta_iters is None):
            prioritized_replay_beta_iters = max_timesteps
        beta_schedule = LinearSchedule(prioritized_replay_beta_iters, initial_p=prioritized_replay_beta0, final_p=1.0)
    else:
        replay_buffer = ReplayBuffer(buffer_size)
        beta_schedule = None
    exploration = LinearSchedule(schedule_timesteps=int((exploration_fraction * max_timesteps)), initial_p=1.0, final_p=exploration_final_eps)
    U.initialize()
    update_target()
    episode_rewards = [0.0]
    saved_mean_reward = None
    obs = env.reset()
    reset = True
    with tempfile.TemporaryDirectory() as td:
        model_saved = False
        model_file = os.path.join(td, 'model')
        for t in range(max_timesteps):
            if (callback is not None):
                if callback(locals(), globals()):
                    break
            kwargs = {}
            if (not param_noise):
                update_eps = exploration.value(t)
                update_param_noise_threshold = 0.0
            else:
                update_eps = 0.0
                if (param_noise_threshold >= 0.0):
                    update_param_noise_threshold = param_noise_threshold
                else:
                    update_param_noise_threshold = (- np.log(((1.0 - exploration.value(t)) + (exploration.value(t) / float(env.action_space.n)))))
                kwargs['reset'] = reset
        ...