Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pufferlib/emulation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import numpy as np
import warnings
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import pufferlib

def try_import(module_path, package_name=None):
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/atari/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np
import functools

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/box2d/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import gymnasium
import functools
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/bsuite/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import gym
import functools

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/butterfly/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
from pettingzoo.utils.conversions import aec_to_parallel_wrapper
import functools

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/crafter/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import gym
import gymnasium
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/dm_control/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import gym
import shimmy
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/dm_lab/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import gym
import shimmy
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/griddly/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import gym
import shimmy
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/gvgai/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np
import functools

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/links_awaken/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import gymnasium

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/magent/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
from pettingzoo.utils.conversions import aec_to_parallel_wrapper
import functools

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/microrts/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np

import warnings
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/minerl/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import gym
import shimmy
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/minigrid/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import gymnasium
import functools
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/minihack/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import gym
import shimmy
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/minihack/torch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import pufferlib.pytorch
from pufferlib.environments.nethack import Policy
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/mujoco/environment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

from pdb import set_trace as T

import functools

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/nethack/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import shimmy
import gym
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/nethack/torch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import torch
import torch.nn as nn
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/nmmo/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np
import functools

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/nmmo/torch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import torch
import torch.nn.functional as F
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/open_spiel/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np
import functools

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/open_spiel/gymnasium_environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np

from open_spiel.python.algorithms import mcts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np

import pufferlib
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/open_spiel/torch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np

import torch
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/open_spiel/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np

import gymnasium
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/pokemon_red/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T

import gymnasium
import functools
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/procgen/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np

import gym
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/procgen/torch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
from torch import nn
import pufferlib.models

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/slimevolley/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np
import functools

Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/stable_retro/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np

import gymnasium as gym
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/test/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np

import time
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/test/mock_environments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np

import time
Expand Down
1 change: 0 additions & 1 deletion pufferlib/environments/vizdoom/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np
import functools

Expand Down
1 change: 0 additions & 1 deletion pufferlib/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np

import torch
Expand Down
8 changes: 0 additions & 8 deletions pufferlib/ocean/environment.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import importlib
import pufferlib.emulation

def lazy_import(module_path, attr):
"""
Returns a callable that, when called with any arguments, will
import the module, retrieve the attribute (usually a class or factory)
and then call it with the given arguments.
"""
return lambda *args, **kwargs: getattr(__import__(module_path, fromlist=[attr]), attr)(*args, **kwargs)

def make_foraging(width=1080, height=720, num_agents=4096, horizon=512,
discretize=True, food_reward=0.1, render_mode='rgb_array'):
from .grid import grid
Expand Down
1 change: 0 additions & 1 deletion pufferlib/ocean/moba/moba.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np
import os

Expand Down
1 change: 0 additions & 1 deletion pufferlib/ocean/nmmo3/nmmo3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pdb import set_trace as T
import numpy as np
from types import SimpleNamespace
import gymnasium
Expand Down
6 changes: 0 additions & 6 deletions pufferlib/pufferl.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,6 @@ def dist_sum(value, device):
torch.distributed.all_reduce(tensor, op=torch.distributed.ReduceOp.SUM)
return tensor.item()

def dist_mean(value, device):
if not torch.distributed.is_initialized():
return value

return dist_sum(value, device) / torch.distributed.get_world_size()

class Profile:
def __init__(self, frequency=5):
self.profiles = defaultdict(lambda: defaultdict(float))
Expand Down
32 changes: 0 additions & 32 deletions pufferlib/pytorch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import sys
from pdb import set_trace as T
from typing import Dict, List, Tuple, Union

import numpy as np
import torch
from torch import nn
from torch.distributions import Categorical
from torch.distributions.utils import logits_to_probs

import pufferlib
Expand Down Expand Up @@ -103,23 +101,6 @@ def nativize_tensor(observation: torch.Tensor, native_dtype: NativeDType):
return _nativize_tensor(observation, native_dtype)


# torch.view(dtype) does not compile
# This is a workaround hack
# @thatguy - can you figure out a more robust way to handle cast?
# I think it may screw up for non-uint data... so I put a hard .view
# fallback that breaks compile
def compilable_cast(u8, dtype):
if dtype in (torch.uint8, torch.uint16, torch.uint32, torch.uint64):
n = dtype.itemsize
bytes = [u8[..., i::n].to(dtype) for i in range(n)]
if not LITTLE_BYTE_ORDER:
bytes = bytes[::-1]

bytes = sum(bytes[i] << (i * 8) for i in range(n))
return bytes.view(dtype)
return u8.view(dtype) # breaking cast


def _nativize_tensor(observation: torch.Tensor, native_dtype: NativeDType):
if isinstance(native_dtype, tuple):
dtype, shape, offset, delta = native_dtype
Expand All @@ -141,15 +122,6 @@ def _nativize_tensor(observation: torch.Tensor, native_dtype: NativeDType):
return subviews


def nativize_observation(observation, emulated):
# TODO: Any way to check that user has not accidentally cast data to float?
# float is natively supported, but only if that is the actual correct type
return nativize_tensor(
observation,
emulated['observation_dtype'],
emulated['emulated_observation_dtype'],
)

def flattened_tensor_size(native_dtype):
return _flattened_tensor_size(native_dtype)

Expand Down Expand Up @@ -182,10 +154,6 @@ def entropy(logits):
p_log_p = logits * logits_to_probs(logits)
return -p_log_p.sum(-1)

def entropy_probs(logits, probs):
p_log_p = logits * probs
return -p_log_p.sum(-1)

def sample_logits(logits, action=None):
is_discrete = isinstance(logits, torch.Tensor)
if isinstance(logits, torch.distributions.Normal):
Expand Down
1 change: 0 additions & 1 deletion pufferlib/vector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# TODO: Check actions passed to envs are right shape? On first call at least

from pdb import set_trace as T

import numpy as np
import time
Expand Down