Closed slinlee closed 3 years ago
@slinlee right, someone set the is_pathmind_simulation
flag to true, which is incorrect. The PathmindSimulation
interface indeed has an action_space
. The above cart pole example is already a PathmindEnvironment
class and should be loaded as such.
@maxpumperla Hmm. When I remove is_pathmind_simulation
it gives this error:
tests/test_training.py:48:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
run.py:155: in main
env_instance = env_creator(env_config=env_config)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pathmind_training.environments.PathmindEnvironment object at 0x7e33f0427d90>
env_config = {'alphas': array(1.), 'num_reward_terms': None, 'reward_balance_period': 1, 'use_reward_terms': False}
def __init__(self, env_config):
# AnyLogic needs this to find its database
os.chdir(jar_dir)
# Put all JAR files found here in the class path
jars = glob.glob(jar_dir + "/**/*.jar", recursive=True)
# Initialize nativerl
nativerl.init(
[
"-Djava.class.path=" + os.pathsep.join(jars + [jar_dir]),
f"-Xmx{max_memory_in_mb}m",
]
)
# Instantiate the native environment, or mock it with pynativerl
if is_pathmind_simulation:
self.nativeEnv = get_native_env_from_simulation(
environment_name, obs_selection, reward_function_name
)
else:
> self.nativeEnv = nativerl.createEnvironment(environment_name)
E AttributeError: module 'pathmind_training.pynativerl' has no attribute 'createEnvironment'
pathmind_training/environments.py:112: AttributeError
@slinlee got it, so that's apparently missing (now?) from pynativerl, but it definitely exists in "normal" nativerl. I think that's the error message we want :D
k. I'll have to dig more to set up the tests properly for this one.
nah, I'm pretty sure this worked at some point, the setup is right. At least it's what I would expect. This is essentially the Python version of what we do in Java, so in a way it's the easiest case. Just need to (re-)introduce createEnvironment
to pynativerl
.
yeah, found it in an old commit:
I think I accidentally removed it bc I thought it was unused... we can just put this back in and it should work right away.
import importlib
def get_environment_class(env_name):
"""Get environment class instance from a string, interpreted as Python module
:param env_name:
:return:
"""
class_name = env_name.split('.')[-1]
module = env_name.replace(f'.{class_name}', '')
lib = importlib.import_module(module)
return getattr(lib, class_name)
def createEnvironment(env_name):
clazz = get_environment_class(env_name)
obj = clazz()
return obj
More context