class_docstr: ### Description
  
  This environment corresponds to the version of the cart-pole problem described by Barto, Sutton, and Anderson in
  ["Neuronlike Adaptive Elements That Can Solve Difficult Learning Control Problem"](https://ieeexplore.ieee.org/document/6313077).
  A pole is attached by an un-actuated joint to a cart, which moves along a frictionless track.
  The pendulum is placed upright on the cart and the goal is to balance the pole by applying forces
   in the left and right direction on the cart.
  
  ### Action Space
  
  The action is a `ndarray` with shape `(1,)` which can take values `{0, 1}` indicating the direction
   of the fixed force the cart is pushed with.
  
  | Num | Action                 |
  |-----|------------------------|
  | 0   | Push cart to the left  |
  | 1   | Push cart to the right |
  
  **Note**: The velocity that is reduced or increased by the applied force is not fixed and it depends on the angle
   the pole is pointing. The center of gravity of the pole varies the amount of energy needed to move the cart underneath it
  
  ### Observation Space
  
  The observation is a `ndarray` with shape `(4,)` with the values corresponding to the following positions and velocities:
  
  | Num | Observation           | Min                 | Max               |
  |-----|-----------------------|---------------------|-------------------|
  | 0   | Cart Position         | -4.8                | 4.8               |
  | 1   | Cart Velocity         | -Inf                | Inf               |
  | 2   | Pole Angle            | ~ -0.418 rad (-24°) | ~ 0.418 rad (24°) |
  | 3   | Pole Angular Velocity | -Inf                | Inf               |
  
  **Note:** While the ranges above denote the possible values for observation space of each element,
      it is not reflective of the allowed values of the state space in an unterminated episode. Particularly:
  -  The cart x-position (index 0) can be take values between `(-4.8, 4.8)`, but the episode terminates
     if the cart leaves the `(-2.4, 2.4)` range.
  -  The pole angle can be observed between  `(-.418, .418)` radians (or **±24°**), but the episode terminates
     if the pole angle is not in the range `(-.2095, .2095)` (or **±12°**)
  
  ### Rewards
  
  Since the goal is to keep the pole upright for as long as possible, a reward of `+1` for every step taken,
  including the termination step, is allotted. The threshold for rewards is 475 for v1.
  
  ### Starting State
  
  All observations are assigned a uniformly random value in `(-0.05, 0.05)`
  
  ### Episode End
  
  The episode ends if any one of the following occurs:
  
  1. Termination: Pole Angle is greater than ±12°
  2. Termination: Cart Position is greater than ±2.4 (center of the cart reaches the edge of the display)
  3. Truncation: Episode length is greater than 500 (200 for v0)
  
  ### Arguments
  
  ```
  gym.make('CartPole-v1')
  ```
  
  No additional arguments are currently supported.
class_docstr_tok: ["#","#","#","Description","This","environment","corresponds","to","the","version","of","the","cart-pole","problem","described","by","Barto",",","Sutton",",","and","Anderson","in","[","``","Neuronlike","Adaptive","Elements","That","Can","Solve","Difficult","Learning","Control","Problem","''","]","(","https",":","\/\/ieeexplore.ieee.org\/document\/6313077",")",".","A","pole","is","attached","by","an","un-actuated","joint","to","a","cart",",","which","moves","along","a","frictionless","track",".","The","pendulum","is","placed","upright","on","the","cart","and","the","goal","is","to","balance","the","pole","by","applying","forces","in","the","left","and","right","direction","on","the","cart",".","#","#","#","Action","Space","The","action","is","a","`","ndarray","`","with","shape","`","(","1",",",")","`","which","can","take","values","`","{","0",",","1","}","`","indicating","the","direction","of","the","fixed","force","the","cart","is","pushed","with",".","|","Num","|","Action","|","|","--","--","-|","--","--","--","--","--","--","--","--","--","--","--","--","|","|","0","|","Push","cart","to","the","left","|","|","1","|","Push","cart","to","the","right","|","*","*","Note","*","*",":","The","velocity","that","is","reduced","or","increased","by","the","applied","force","is","not","fixed","and","it","depends","on","the","angle","the","pole","is","pointing",".","The","center","of","gravity","of","the","pole","varies","the","amount","of","energy","needed","to","move","the","cart","underneath","it","#","#","#","Observation","Space","The","observation","is","a","`","ndarray","`","with","shape","`","(","4",",",")","`","with","the","values","corresponding","to","the","following","positions","and","velocities",":","|","Num","|","Observation","|","Min","|","Max","|","|","--","--","-|","--","--","--","--","--","--","--","--","--","--","--","-|","--","--","--","--","--","--","--","--","--","--","-|","--","--","--","--","--","--","--","--","--","-|","|","0","|","Cart","Position","|","-4.8","|","4.8","|","|","1","|","Cart","Velocity","|","-Inf","|","Inf","|","|","2","|","Pole","Angle","|","~","-0.418","rad","(","-24\u00b0",")","|","~","0.418","rad","(","24\u00b0",")","|","|","3","|","Pole","Angular","Velocity","|","-Inf","|","Inf","|","*","*","Note",":","*","*","While","the","ranges","above","denote","the","possible","values","for","observation","space","of","each","element",",","it","is","not","reflective","of","the","allowed","values","of","the","state","space","in","an","unterminated","episode",".","Particularly",":","-","The","cart","x-position","(","index","0",")","can","be","take","values","between","`","(","-4.8",",","4.8",")","`",",","but","the","episode","terminates","if","the","cart","leaves","the","`","(","-2.4",",","2.4",")","`","range",".","-","The","pole","angle","can","be","observed","between","`","(","-.418",",",".418",")","`","radians","(","or","*","*","\u00b124\u00b0","*","*",")",",","but","the","episode","terminates","if","the","pole","angle","is","not","in","the","range","`","(","-.2095",",",".2095",")","`","(","or","*","*","\u00b112\u00b0","*","*",")","#","#","#","Rewards","Since","the","goal","is","to","keep","the","pole","upright","for","as","long","as","possible",",","a","reward","of","`","+1","`","for","every","step","taken",",","including","the","termination","step",",","is","allotted",".","The","threshold","for","rewards","is","475","for","v1",".","#","#","#","Starting","State","All","observations","are","assigned","a","uniformly","random","value","in","`","(","-0.05",",","0.05",")","`","#","#","#","Episode","End","The","episode","ends","if","any","one","of","the","following","occurs",":","1",".","Termination",":","Pole","Angle","is","greater","than","\u00b112\u00b0","2",".","Termination",":","Cart","Position","is","greater","than","\u00b12.4","(","center","of","the","cart","reaches","the","edge","of","the","display",")","3",".","Truncation",":","Episode","length","is","greater","than","500","(","200","for","v0",")","#","#","#","Arguments","``","`","gym.make","(","'CartPole-v1","'",")","``","`","No","additional","arguments","are","currently","supported","."]
code: def __init__(self, render_mode: Optional[str] = None):
      self.gravity = 9.8
      self.masscart = 1.0
      self.masspole = 0.1
      self.total_mass = self.masspole + self.masscart
      self.length = 0.5  # actually half the pole's length
      self.polemass_length = self.masspole * self.length
      self.force_mag = 10.0
      self.tau = 0.02  # seconds between state updates
      self.kinematics_integrator = "euler"
  
      # Angle at which to fail the episode
      self.theta_threshold_radians = 12 * 2 * math.pi / 360
      self.x_threshold = 2.4
  
      # Angle limit set to 2 * theta_threshold_radians so failing observation
      # is still within bounds.
      high = np.array(
          [
              self.x_threshold * 2,
              np.finfo(np.float32).max,
              self.theta_threshold_radians * 2,
              np.finfo(np.float32).max,
          ],
          dtype=np.float32,
      )
  
      self.action_space = spaces.Discrete(2)
      self.observation_space = spaces.Box(-high, high, dtype=np.float32)
  
      self.render_mode = render_mode
  
      self.screen_width = 600
      self.screen_height = 400
      self.screen = None
      self.clock = None
      self.isopen = True
      self.state = None
  
      self.steps_beyond_terminated = None
  
file_path: gym/gym/envs/classic_control/cartpole.py
imports: import math
  from typing import Optional, Union
  import numpy
  import gym
  from gym import logger, spaces
  from gym.envs.classic_control import utils
  from gym.error import DependencyNotInstalled
label_desc: Use image node_id 1 to create a new CartPoleEnv object from inherited base classes: gym.Env with example: obj = CartPoleEnv(render_mode)