code: def estimate_value(
      episodes: int, max_horizon: int, policy: RLPolicy, gamma: float
  ):
      avg = RunningAverage()
      env = gym.make("CartPole-v0")
      for _ in range(episodes):
          init_state = env.reset()
          cur_state = init_state
          r = 0.0
          discount = 1.0
          for _ in range(max_horizon):
              action_dist = policy(State(cur_state))
              action = action_dist.sample()[0].value
              next_state, _, done, _ = env.step(action)
              reward = 1.0
              r += reward * discount
              discount *= gamma
              if done:
                  break
              cur_state = next_state
          avg.add(r)
      return avg.average
  
imports: import logging
  import gym
  import torch
  from reagent.ope.estimators.sequential_estimators import Action, ActionDistribution, ActionSpace, IPSEstimator, Model, NeuralDualDICE, RandomRLPolicy, RewardProbability, RLEstimatorInput, RLPolicy, State, StateDistribution, Transition
  from reagent.ope.utils import RunningAverage
label_desc: Use image node_id 3 for calling a global function with example usage: estimate_value(episodes, max_horizon, policy, gamma) and returns: avg