Exemple #1
0
def create_rollout(spec):
    """
  Takes as input the environment spec for which the rollout is to be generated.
  Returns a bool which indicates whether the new rollout was added to the json file.  

  """
    # Skip platform-dependent
    if should_skip_env_spec_for_tests(spec):
        logger.warn("Skipping tests for {}".format(spec.id))
        return False

    # Skip environments that are nondeterministic
    if spec.nondeterministic:
        logger.warn("Skipping tests for nondeterministic env {}".format(
            spec.id))
        return False

    # Skip broken environments
    # TODO: look into these environments
    if spec.id in [
            'PredictObsCartpole-v0', 'InterpretabilityCartpoleObservations-v0'
    ]:
        logger.warn("Skipping tests for {}".format(spec.id))
        return False

    with open(ROLLOUT_FILE) as data_file:
        rollout_dict = json.load(data_file)

    # Skip generating rollouts that already exist
    if spec.id in rollout_dict:
        logger.warn("Rollout already exists for {}".format(spec.id))
        return False

    logger.info("Generating rollout for {}".format(spec.id))

    try:
        observations_hash, actions_hash, rewards_hash, dones_hash = generate_rollout_hash(
            spec)
    except:
        # If running the env generates an exception, don't write to the rollout file
        logger.warn(
            "Exception {} thrown while generating rollout for {}. Rollout not added."
            .format(sys.exc_info()[0], spec.id))
        return False

    rollout = {}
    rollout['observations'] = observations_hash
    rollout['actions'] = actions_hash
    rollout['rewards'] = rewards_hash
    rollout['dones'] = dones_hash

    rollout_dict[spec.id] = rollout

    with open(ROLLOUT_FILE, "w") as outfile:
        json.dump(rollout_dict, outfile, indent=2)

    return True
Exemple #2
0
def update_rollout_dict(spec, rollout_dict):
    """
  Takes as input the environment spec for which the rollout is to be generated,
  and the existing dictionary of rollouts. Returns True iff the dictionary was
  modified.
  """
    # Skip platform-dependent
    if should_skip_env_spec_for_tests(spec):
        logger.info("Skipping tests for {}".format(spec.id))
        return False

    # Skip environments that are nondeterministic
    if spec.nondeterministic:
        logger.info("Skipping tests for nondeterministic env {}".format(
            spec.id))
        return False

    # Skip broken environments
    # TODO: look into these environments
    if spec.id in [
            'PredictObsCartpole-v0', 'InterpretabilityCartpoleObservations-v0'
    ]:
        logger.info("Skipping tests for {}".format(spec.id))
        return False

    logger.info("Generating rollout for {}".format(spec.id))

    try:
        observations_hash, actions_hash, rewards_hash, dones_hash = generate_rollout_hash(
            spec)
    except:
        # If running the env generates an exception, don't write to the rollout file
        logger.warn(
            "Exception {} thrown while generating rollout for {}. Rollout not added."
            .format(sys.exc_info()[0], spec.id))
        return False

    rollout = {}
    rollout['observations'] = observations_hash
    rollout['actions'] = actions_hash
    rollout['rewards'] = rewards_hash
    rollout['dones'] = dones_hash

    existing = rollout_dict.get(spec.id)
    if existing:
        differs = False
        for key, new_hash in rollout.items():
            differs = differs or existing[key] != new_hash
        if not differs:
            logger.debug("Hashes match with existing for {}".format(spec.id))
            return False
        else:
            logger.warn("Got new hash for {}. Overwriting.".format(spec.id))

    rollout_dict[spec.id] = rollout
    return True
Exemple #3
0
def create_rollout(spec):
  """
  Takes as input the environment spec for which the rollout is to be generated.
  Returns a bool which indicates whether the new rollout was added to the json file.  

  """
  # Skip platform-dependent
  if should_skip_env_spec_for_tests(spec):
    logger.warn("Skipping tests for {}".format(spec.id))
    return False

  # Skip environments that are nondeterministic
  if spec.nondeterministic:
    logger.warn("Skipping tests for nondeterministic env {}".format(spec.id))
    return False

  # Skip broken environments
  # TODO: look into these environments
  if spec.id in ['PredictObsCartpole-v0', 'InterpretabilityCartpoleObservations-v0']:
    logger.warn("Skipping tests for {}".format(spec.id))
    return False

  with open(ROLLOUT_FILE) as data_file:
    rollout_dict = json.load(data_file)

  # Skip generating rollouts that already exist
  if spec.id in rollout_dict:
    logger.warn("Rollout already exists for {}".format(spec.id))
    return False

  logger.info("Generating rollout for {}".format(spec.id))

  try:
    observations_hash, actions_hash, rewards_hash, dones_hash = generate_rollout_hash(spec)
  except:
    # If running the env generates an exception, don't write to the rollout file
    logger.warn("Exception {} thrown while generating rollout for {}. Rollout not added.".format(sys.exc_info()[0], spec.id))
    return False

  rollout = {}
  rollout['observations'] = observations_hash
  rollout['actions'] = actions_hash
  rollout['rewards'] = rewards_hash
  rollout['dones'] = dones_hash

  rollout_dict[spec.id] = rollout

  with open(ROLLOUT_FILE, "w") as outfile:
    json.dump(rollout_dict, outfile, indent=2)

  return True
Exemple #4
0
def update_rollout_dict(spec, rollout_dict):
  """
  Takes as input the environment spec for which the rollout is to be generated,
  and the existing dictionary of rollouts. Returns True iff the dictionary was
  modified.
  """
  # Skip platform-dependent
  if should_skip_env_spec_for_tests(spec):
    logger.info("Skipping tests for {}".format(spec.id))
    return False

  # Skip environments that are nondeterministic
  if spec.nondeterministic:
    logger.info("Skipping tests for nondeterministic env {}".format(spec.id))
    return False

  logger.info("Generating rollout for {}".format(spec.id))

  try:
    observations_hash, actions_hash, rewards_hash, dones_hash = generate_rollout_hash(spec)
  except:
    # If running the env generates an exception, don't write to the rollout file
    logger.warn("Exception {} thrown while generating rollout for {}. Rollout not added.".format(sys.exc_info()[0], spec.id))
    return False

  rollout = {}
  rollout['observations'] = observations_hash
  rollout['actions'] = actions_hash
  rollout['rewards'] = rewards_hash
  rollout['dones'] = dones_hash

  existing = rollout_dict.get(spec.id)
  if existing:
    differs = False
    for key, new_hash in rollout.items():
      differs = differs or existing[key] != new_hash
    if not differs:
      logger.debug("Hashes match with existing for {}".format(spec.id))
      return False
    else:
      logger.warn("Got new hash for {}. Overwriting.".format(spec.id))

  rollout_dict[spec.id] = rollout
  return True