Skip to content

Commit

Permalink
refactor: remove redudant features (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
typoverflow authored Aug 30, 2023
1 parent a680eb5 commit 25989d0
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 898 deletions.
9 changes: 1 addition & 8 deletions UtilsRL/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@

__version__ = "0.5.9"

from UtilsRL import data_structure, env, exp, logger, math, misc, plot, rl, monitor
from UtilsRL import exp, logger
__all__ = [
"data_structure",
"env",
"exp",
"logger",
"math",
"misc",
"plot",
"rl",
"monitor"
]
6 changes: 1 addition & 5 deletions UtilsRL/exp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from UtilsRL.exp.argparse import parse_args, argparse_callbacks, register_argparse_callback
from UtilsRL.exp._seed import *
from UtilsRL.exp._device import *
from UtilsRL.exp.snapshot import make_snapshot
from UtilsRL.exp.precision import set_precision

from UtilsRL.logger import BaseLogger
from UtilsRL.logger import logger as url_internal_logger
Expand Down Expand Up @@ -63,6 +61,4 @@ def setup(args,

return args


register_argparse_callback("UtilsRL.snapshot", make_snapshot)
register_argparse_callback("UtilsRL.precision", set_precision)

14 changes: 0 additions & 14 deletions UtilsRL/exp/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,6 @@ def traverse_add(old, new, current_key=""):

traverse_add(file_args, cmd_args)

# check if there is a callback
for key in argparse_callbacks:
_args = file_args
_keys = key.split(".")
for k in _keys:
_args = _args.get(k, None)
if _args is None:
ret = argparse_callbacks[key](None) # call callback with default None and then break
file_args = update_args(file_args, ret, eval=False)
break
else:
ret = argparse_callbacks[key](_args)
file_args = update_args(file_args, ret, eval=False)

return file_args

def update_args(args, new_args: Optional[Union[dict, list]] = None, eval=True):
Expand Down
53 changes: 0 additions & 53 deletions UtilsRL/exp/precision.py

This file was deleted.

33 changes: 0 additions & 33 deletions UtilsRL/exp/snapshot.py

This file was deleted.

15 changes: 6 additions & 9 deletions UtilsRL/logger/base_logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict, Optional, Sequence, Union

import os
import torch
import pickle
from datetime import datetime

Expand All @@ -26,18 +27,14 @@ def numpy_save(obj, file):
with open(file, "w") as fp:
np.save(fp, obj)

if protocol == "torch":
import torch
return torch.save
else:
return {
"pickle": pickle_save,
"numpy": numpy_save
}.get(protocol)
return {
"torch": torch.save,
"pickle": pickle_save,
"numpy": numpy_save
}.get(protocol)

def load_fn(protocol: str="torch"):
def torch_load(file):
import torch
return torch.load(file, map_location="cpu")

def pickle_load(file):
Expand Down
Loading

0 comments on commit 25989d0

Please sign in to comment.