Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import error about build_env and solution #184

Open
Yonv1943 opened this issue Jul 15, 2022 · 0 comments
Open

import error about build_env and solution #184

Yonv1943 opened this issue Jul 15, 2022 · 0 comments
Labels
refactoring Code refactoring

Comments

@Yonv1943
Copy link
Collaborator

Search the funtion build_env in ElegantRL. There are:

21 code results in AI4Finance-Foundation/ElegantRL

The from elegantrl.envs.Gym import build_env could be changed to from elegantrl.train.config import build_env

The function build_env has been moved from elegantrl/envs/Gym.py to elegantrl/train/config.py

def build_env(env=None, env_func=None, env_args=None): # [ElegantRL.2021.12.12]
if env is not None:
env = deepcopy(env)
elif env_func.__module__ == 'gym.envs.registration':
import gym
gym.logger.set_level(40) # Block warning
env = env_func(id=env_args['env_name'])
else:
env = env_func(**kwargs_filter(env_func.__init__, env_args.copy()))
for attr_str in ('state_dim', 'action_dim', 'max_step', 'if_discrete', 'target_return'):
if (not hasattr(env, attr_str)) and (attr_str in env_args):
setattr(env, attr_str, env_args[attr_str])
# env.max_step = env.max_step if hasattr(env, 'max_step') else env_args['max_step']
# env.if_discrete = env.if_discrete if hasattr(env, 'if_discrete') else env_args['if_discrete']
return env

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Code refactoring
Projects
None yet
Development

No branches or pull requests

2 participants