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

test examples #19

Open
Wouter1 opened this issue Jun 4, 2020 · 79 comments
Open

test examples #19

Wouter1 opened this issue Jun 4, 2020 · 79 comments

Comments

@Wouter1
Copy link
Collaborator

Wouter1 commented Jun 4, 2020

On 03/06/2020 17:12, Aleksander Czechowski wrote:

  1. Revisit the examples directories in aienvs and aiagents.
    All examples should be executable by running "python3 file.py" (or eclipse equivalent..)
    Examples may take much longer than unit tests, so you don't need to run them to the end -- it is enough to kill them after few seconds of execution

Some examples may fail because they are outdated in one way or another, and I think we haven't looked into these directories in a while

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

AgentComponent.py gives

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/examples/AgentComponent.py", line 32, in <module>
    main()
  File "/home/wouter/git/aiagents/examples/AgentComponent.py", line 17, in main
    simpleComponentList.append(RandomAgent(i, action_space))
TypeError: __init__() missing 1 required positional argument: 'observationspace'

Wouter1 pushed a commit that referenced this issue Jun 4, 2020
@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Fixed AgentComponent demo

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

AgentFactory.py

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/examples/AgentFactory.py", line 2, in <module>
    from mock import Mock
ModuleNotFoundError: No module named 'mock'

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Correct import is from unittest.mock import Mock

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/examples/AgentFactory.py", line 29, in <module>
    main()
  File "/home/wouter/git/aiagents/examples/AgentFactory.py", line 17, in main
    parameters = getParameters(filename)
  File "/home/wouter/git/aienvs/aienvs/utils.py", line 12, in getParameters
    with open(filename, 'r') as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/home/wouter/git/aiagents/examples/configs/agentconfig.yaml'

Strange, did someone rename agentconfig.yaml to agent_config.yaml?

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/examples/AgentFactory.py", line 29, in <module>
    main()
  File "/home/wouter/git/aiagents/examples/AgentFactory.py", line 19, in main
    env = FactoryFloor(parameters['environment'])
KeyError: 'environment'

So it seems someone took over and modified agentconfig.yaml or removed it completely, breaking this example

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Trying to use factory_floor_complex.yaml instead

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

That gives

warning: Debugger speedups using cython not found. Run '"/home/wouter/git/aienvs/venv/bin/python" "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/setup_cython.py" build_ext --inplace' to build.
pydev debugger: starting (pid: 3601)
Traceback (most recent call last):
  File "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/pydevd.py", line 2225, in <module>
    main()
  File "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/pydevd.py", line 2218, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/pydevd.py", line 1560, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/pydevd.py", line 1567, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/_pydev_imps/_pydev_execfile.py", line 25, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/wouter/git/aiagents/examples/AgentFactory.py", line 29, in <module>
    main()
  File "/home/wouter/git/aiagents/examples/AgentFactory.py", line 19, in main
    env = FactoryFloor(parameters['environment'])
  File "/home/wouter/git/aienvs/aienvs/FactoryFloor/FactoryFloor.py", line 75, in __init__
    pos = item['pos']
TypeError: list indices must be integers or slices, not str

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

The yaml file is incorrect/not matching the code. The code expects for each robot something like {'id':'robotname', 'pos':[x,y]}.
The yaml file contains just [0,0] for the first robot.

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Fixed that part of the yaml file. Now we get

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/examples/AgentFactory.py", line 29, in <module>
    main()
  File "/home/wouter/git/aiagents/examples/AgentFactory.py", line 22, in main
    complexAgent = createAgent(env.action_space, env.observation_space, parameters['agents'])
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 32, in createAgent
    raise ValueError("Parameters must have key 'class' but got " + str(parameters))
ValueError: Parameters must have key 'class' but got {'iterationLimit': 500, 'treeParameters': {'explorationConstant': 10000, 'samplingLimit': 20}}

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

The 'agents' value in the yaml file is this

    agents:
        iterationLimit: 500
        #timeLimit: 30
        treeParameters: 
            explorationConstant: 10000
            samplingLimit: 20

which does not even remotely resemble what is needed for the factory (it needs a class name etc)

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

@czechows

Basically the yaml files contain a serialized object. What we do is (1) deserialize the yaml to a python dict (2) we have code snippets throughout the code picking parts from this dict (3) build python objects based on these picked parts. Basically we have a distributed hand-built parser that results in a nightmare scenario. You basically have to read through all the code to determine the proper format for your yaml file. Plus all problems you get with simplistic parsing like no /bad error messages. And lots of boilerplate code to fix these bad error messages.

I remember we looked into this before but did not find any suited deserialization mechanism for python.

Now I see that python 3.8.3 has a dataclass annotation. Maybe we can do something with that?
https://docs.python.org/3/library/dataclasses.html

@czechows
Copy link
Contributor

czechows commented Jun 4, 2020

@Wouter1 perhaps let's just fix outdated config files (adapt them to the new, working format).

These config files are not for deserialization but to provide arguments for the constructors/factories (which can do some non-trivial initializations based on these arguments, e.g. creating subclasses).

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

agent_combined_config.yaml seems to contain something that matches what I reverse engineer in the code.

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

@czechows yes I'm trying to fix them.But as said this is not nice and they are almost all broken.

Wouter1 pushed a commit that referenced this issue Jun 4, 2020
@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Exampel AgentFactory is fixed.

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

DQNSingleExample.py does not work

sh: 1: netconvert: not found
CRITICAL:root:LDM start failed
Traceback (most recent call last):
  File "/home/wouter/git/aiagents/examples/DQNSingleExample.py", line 18, in <module>
    'gui': False
  File "/home/wouter/git/aienvs/aienvs/Sumo/GridSumoEnv.py", line 226, in __init__
    super().__init__(parameters=_parameters)
  File "/home/wouter/git/aienvs/aienvs/Sumo/SumoGymAdapter.py", line 78, in __init__
    self._observation_space = self._compute_observation_space()
  File "/home/wouter/git/aienvs/aienvs/Sumo/SumoGymAdapter.py", line 81, in _compute_observation_space
    self._startSUMO(gui=False)
  File "/home/wouter/git/aienvs/aienvs/Sumo/SumoGymAdapter.py", line 170, in _startSUMO
    self._sumo_helper = SumoHelper(self._parameters, self._port, self._seed)
  File "/home/wouter/git/aienvs/aienvs/Sumo/SumoHelper.py", line 25, in __init__
    assert(self.scenario_check(self.parameters['scene']))
  File "/home/wouter/git/aienvs/aienvs/Sumo/SumoHelper.py", line 44, in scenario_check
    self._net_file = os.path.basename(glob.glob(self.scenario_path + '/*.net.xml')[0])
IndexError: list index out of range
Exception ignored in: <bound method ldm.__del__ of <aienvs.Sumo.LDM.ldm object at 0x7fbf6df2bf28>>
Traceback (most recent call last):
  File "/home/wouter/git/aienvs/aienvs/Sumo/LDM.py", line 475, in __del__
    self.SUMO_client.close()
  File "/home/wouter/sumo/tools/traci/__init__.py", line 215, in close
    _connections[""].close(wait)
KeyError: ('',)

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

The error message comes from searching for a non-existing file.

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

The used 'scenario_path' is pointing to '/home/wouter/git/aienvs/aienvs/Sumo/../../scenarios/Sumo/grid_1x1' which is completely wrong. There is no Sumo directory in aienvs

There is a Sumo dir in aienvs, but there is no grid_1x1 in there

there is a aienvs/scenarios/Sumo/one_grid, maybe that's the one intended here

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

the 'scene' parameter contains just "grid_1x1". And even worse, it's computed in GridSumoEnv, so it's not just a text value in a file.
I can't just hack GridSumoEnv because it's used in other files, esp GridSumo.ipynb which I have no idea about.

I'll try renaming the one_grid into grid1x1 and see what happens

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

@czechows

I'm trying to fix DQNSingleExample. One problem is that it uses aienvs.SumoHelper (so this is a different package that might be just pip install'ed). SumoHelper searches relative to its own file position. I happen to have SumoHelper inside Eclipse, so it givs a file inside aienvs. This is already weird, because the test I'm running is in aiagents. I don't know what would happen if you would have just pip installed aienvs.

Should we fix SumoHelper for re-use in other packages? Eg so that it looks in another place ? How? Or do you have a different idea about this?

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

If I copy the directory aienvs/scenarios/Sumo/one_grid to aienvs/scenarios/Sumo/grid_1x1 then SQNSAingleExample seems to start. Unfortunately the map is incorrect, I get

Error: The edge 'e_0_1_l_1_1' within the route '1' is not known.
 The route can not be build.
Quitting (on error).

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Maybe I can find the old grid_1x1 files

@czechows
Copy link
Contributor

czechows commented Jun 4, 2020

@czechows

I'm trying to fix DQNSingleExample. One problem is that it uses aienvs.SumoHelper (so this is a different package that might be just pip install'ed). SumoHelper searches relative to its own file position. I happen to have SumoHelper inside Eclipse, so it givs a file inside aienvs. This is already weird, because the test I'm running is in aiagents. I don't know what would happen if you would have just pip installed aienvs.

Should we fix SumoHelper for re-use in other packages? Eg so that it looks in another place ? How? Or do you have a different idea about this?

How does it use SumoHelper?

For me it works (my config is aienvs, aiagents on PYTHONPATH and not installed via pip).

Is the problem in GridSumoEnv?

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

@czechows do you know if we ever had a grid_1x1 sumo scenario folder? The DQNSingleExample needs it

@czechows
Copy link
Contributor

czechows commented Jun 4, 2020

Ah indeed I have this folder locally but not in the repo. Perhaps it is generated by GridSumoEnv?

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

@czechows Yes I was just thinking that.
But the example is in aiagents and generates files in aiagents. See my previous post on this. SumoHelper looks elsewhere...

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

I'll skip this for now till we have an idea how to fix this.

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

@czechows I'm puzzled by the agent_combined_config.yaml that is used for MctsAggrExample

MctsAgent is a single agent. That means FAIK that it is connected to a single entity in the env. So it can't have the id "robots", it should have a existing robot name eg robotN with N in [1,2,3].

Also MCTS agent does not seem to be simple because it contains several like treeAgent, rolloutAgent etc?

@czechows
Copy link
Contributor

czechows commented Jun 4, 2020

This is an example to show how to aggregate entities (using some of the functionality you wrote for us some time ago like PackedSpace etc.). Therefore multiple robots are controlled by a single agent.

treeAgent, rolloutAgent are specific to internals of MCTS; you have to specify what algorithm of picking actions (=agent) one uses at certain parts within MCTS (e.g. random)

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

@czechows But then the RobotAgent (MctsAgent) should get a VALID agentid. 'robots' is not a valid ID?

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

@czechows also, if the MctsAgent is only acting for one entity (say robot1), then who is determining the actions for the other robots?

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

The MctsExample uses agent_config.yaml which seems to contain a more complete and up-to-date content. Still no 'simulator' here though

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 48, in createAgent
    obj = klass(parameters['id'], actionspace, observationspace, class_parameters)
  File "/home/wouter/git/aiagents/aiagents/single/mcts/MctsAgent.py", line 56, in __init__
    envparams = parameters['simulator']
KeyError: 'simulator'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/examples/MctsExample.py", line 79, in <module>
    main()
  File "/home/wouter/git/aiagents/examples/MctsExample.py", line 57, in main
    complexAgent = createAgent(env.action_space, env.observation_space, agent_parameters)
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 54, in createAgent
    subAgentList.append(createAgent(actionspace, observationspace, subAgentParameters))
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 50, in createAgent
    raise ValueError(classname + " failed on __init__:") from error
ValueError: aiagents.single.mcts.MctsAgent.MctsAgent failed on __init__:

@czechows
Copy link
Contributor

czechows commented Jun 4, 2020

@Wouter1 it is acting for all robots at once
See line:
packedActionSpace = PackedSpace(baseEnv.action_space, {"robots":["robot1", "robot2", "robot3"]})

According to this line the new (combined) id is "robots".

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

AgentFactory line 56 is weird

    elif 'subAgentList' in parameters:
        subAgentList = []
        for subAgentParameters in parameters['subAgentList']:
            subAgentList.append(createAgent(actionspace, observationspace, subAgentParameters))
            try:
                obj = klass(subAgentList, actionspace, observationspace, class_parameters)
            except Exception as error:
                raise ValueError(classname + " failed on __init__:") from error

Why are we calling the constructor multiple times and doing nothing with obj? Only the last value seems returned

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

It seems that the indentation is incorrect, I assume that obj should be called only when the subAgentList is complete.

Wouter1 pushed a commit that referenced this issue Jun 4, 2020
@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Getting in MctsExample

Default config 
{'seed': None, 'max_steps': 40, 'environment': {'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}}
{'class': 'aiagents.multi.BasicComplexAgent.BasicComplexAgent', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.mcts.MctsAgent.MctsAgent', 'id': 'robot1', 'parameters': {'simulator': {'fullname': 'aienvs.FactoryFloor.FactoryFloor.FactoryFloor', 'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}, 'treeAgent': {'class': 'aiagents.single.RandomAgent.RandomAgent', 'id': 'robot1', 'parameters': {}}, 'rolloutAgent': {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot1', 'parameters': {}}, 'otherAgents': {'class': 'aiagents.multi.BasicComplexAgent.BasicComplexAgent', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot2', 'parameters': {}}, {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot3', 'parameters': {}}]}, 'iterationLimit': 500, 'diyBonus': 0.0, 'treeParameters': {'explorationConstant': 1, 'samplingLimit': 30, 'maxSteps': 10}}}, {'class': 'aiagents.single.mcts.MctsAgent.MctsAgent', 'id': 'robot2', 'parameters': {'simulator': {'fullname': 'aienvs.FactoryFloor.FactoryFloor.FactoryFloor', 'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}, 'treeAgent': {'class': 'aiagents.single.RandomAgent.RandomAgent', 'id': 'robot2', 'parameters': {}}, 'rolloutAgent': {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot2', 'parameters': {}}, 'otherAgents': {'class': 'aiagents.multi.FactoryFloorIterativeGreedy.FactoryFloorIterativeGreedy', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot1', 'parameters': {}}, {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot3', 'parameters': {}}]}, 'iterationLimit': 500, 'diyBonus': 0.0, 'treeParameters': {'explorationConstant': 1, 'samplingLimit': 30, 'maxSteps': 10}}}, {'class': 'aiagents.single.mcts.MctsAgent.MctsAgent', 'id': 'robot3', 'parameters': {'simulator': {'fullname': 'aienvs.FactoryFloor.FactoryFloor.FactoryFloor', 'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}, 'treeAgent': {'class': 'aiagents.single.RandomAgent.RandomAgent', 'id': 'robot3', 'parameters': {}}, 'rolloutAgent': {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot3', 'parameters': {}}, 'otherAgents': {'class': 'aiagents.multi.FactoryFloorIterativeGreedy.FactoryFloorIterativeGreedy', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot1', 'parameters': {}}, {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot2', 'parameters': {}}]}, 'iterationLimit': 500, 'diyBonus': 0.0, 'treeParameters': {'explorationConstant': 1, 'samplingLimit': 30}}}]}
No SLURM_JOB_ID found
Traceback (most recent call last):
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 56, in createAgent
    obj = klass(subAgentList, actionspace, observationspace, class_parameters)
TypeError: __init__() takes from 3 to 4 positional arguments but 5 were given

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 48, in createAgent
    obj = klass(parameters['id'], actionspace, observationspace, class_parameters)
  File "/home/wouter/git/aiagents/aiagents/single/mcts/MctsAgent.py", line 72, in __init__
    self._rolloutAgent = createAgent(self._simulator.action_space, self._simulator.observation_space, rolloutAgentDict)
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 58, in createAgent
    raise ValueError(classname + " failed on __init__:") from error
ValueError: aiagents.multi.FactoryFloorIterativeGreedy.FactoryFloorIterativeGreedy failed on __init__:

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/examples/MctsExample.py", line 84, in <module>
    main()
  File "/home/wouter/git/aiagents/examples/MctsExample.py", line 62, in main
    complexAgent = createAgent(env.action_space, env.observation_space, agent_parameters)
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 54, in createAgent
    subAgentList.append(createAgent(actionspace, observationspace, subAgentParameters))
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 50, in createAgent
    raise ValueError(classname + " failed on __init__:") from error
ValueError: aiagents.single.mcts.MctsAgent.MctsAgent failed on __init__:

The error message is saying that FactoryFloorIterativeGreedy has incorrect constructor, but the errormessage itself is also confusing. The 'self' parameter is not shown.

The problem is that it should take actionspace:Dict, observationspace but takes environment.

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Fixed that. Now getting

warning: Debugger speedups using cython not found. Run '"/home/wouter/git/aienvs/venv/bin/python" "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/setup_cython.py" build_ext --inplace' to build.
pydev debugger: starting (pid: 11543)
Default config 
{'seed': None, 'max_steps': 40, 'environment': {'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}}
{'class': 'aiagents.multi.BasicComplexAgent.BasicComplexAgent', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.mcts.MctsAgent.MctsAgent', 'id': 'robot1', 'parameters': {'simulator': {'fullname': 'aienvs.FactoryFloor.FactoryFloor.FactoryFloor', 'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}, 'treeAgent': {'class': 'aiagents.single.RandomAgent.RandomAgent', 'id': 'robot1', 'parameters': {}}, 'rolloutAgent': {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot1', 'parameters': {}}, 'otherAgents': {'class': 'aiagents.multi.BasicComplexAgent.BasicComplexAgent', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot2', 'parameters': {}}, {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot3', 'parameters': {}}]}, 'iterationLimit': 500, 'diyBonus': 0.0, 'treeParameters': {'explorationConstant': 1, 'samplingLimit': 30, 'maxSteps': 10}}}, {'class': 'aiagents.single.mcts.MctsAgent.MctsAgent', 'id': 'robot2', 'parameters': {'simulator': {'fullname': 'aienvs.FactoryFloor.FactoryFloor.FactoryFloor', 'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}, 'treeAgent': {'class': 'aiagents.single.RandomAgent.RandomAgent', 'id': 'robot2', 'parameters': {}}, 'rolloutAgent': {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot2', 'parameters': {}}, 'otherAgents': {'class': 'aiagents.multi.FactoryFloorIterativeGreedy.FactoryFloorIterativeGreedy', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot1', 'parameters': {}}, {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot3', 'parameters': {}}]}, 'iterationLimit': 500, 'diyBonus': 0.0, 'treeParameters': {'explorationConstant': 1, 'samplingLimit': 30, 'maxSteps': 10}}}, {'class': 'aiagents.single.mcts.MctsAgent.MctsAgent', 'id': 'robot3', 'parameters': {'simulator': {'fullname': 'aienvs.FactoryFloor.FactoryFloor.FactoryFloor', 'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}, 'treeAgent': {'class': 'aiagents.single.RandomAgent.RandomAgent', 'id': 'robot3', 'parameters': {}}, 'rolloutAgent': {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot3', 'parameters': {}}, 'otherAgents': {'class': 'aiagents.multi.FactoryFloorIterativeGreedy.FactoryFloorIterativeGreedy', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot1', 'parameters': {}}, {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot2', 'parameters': {}}]}, 'iterationLimit': 500, 'diyBonus': 0.0, 'treeParameters': {'explorationConstant': 1, 'samplingLimit': 30}}}]}
No SLURM_JOB_ID found
>>> ffAgentList[0]
<aiagents.single.FactoryFloorAgent.FactoryFloorAgent object at 0x7fba1a9ed6d8>
Traceback (most recent call last):
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 56, in createAgent
    obj = klass(subAgentList, actionspace, observationspace, class_parameters)
  File "/home/wouter/git/aiagents/aiagents/multi/FactoryFloorIterativeGreedy.py", line 18, in __init__
    self.pathDict = ffAgentList[0].pathDict
AttributeError: 'FactoryFloorAgent' object has no attribute 'pathDict'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 48, in createAgent
    obj = klass(parameters['id'], actionspace, observationspace, class_parameters)
  File "/home/wouter/git/aiagents/aiagents/single/mcts/MctsAgent.py", line 72, in __init__
    self._rolloutAgent = createAgent(self._simulator.action_space, self._simulator.observation_space, rolloutAgentDict)
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 58, in createAgent
    raise ValueError(classname + " failed on __init__:") from error
ValueError: aiagents.multi.FactoryFloorIterativeGreedy.FactoryFloorIterativeGreedy failed on __init__:

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/pydevd.py", line 2225, in <module>
    main()
  File "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/pydevd.py", line 2218, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/pydevd.py", line 1560, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/pydevd.py", line 1567, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/wouter/eclipse/plugins/org.python.pydev.core_7.1.0.201902031515/pysrc/_pydev_imps/_pydev_execfile.py", line 25, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/wouter/git/aiagents/examples/MctsExample.py", line 84, in <module>
    main()
  File "/home/wouter/git/aiagents/examples/MctsExample.py", line 62, in main
    complexAgent = createAgent(env.action_space, env.observation_space, agent_parameters)
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 54, in createAgent
    subAgentList.append(createAgent(actionspace, observationspace, subAgentParameters))
  File "/home/wouter/git/aiagents/aiagents/AgentFactory.py", line 50, in createAgent
    raise ValueError(classname + " failed on __init__:") from error
ValueError: aiagents.single.mcts.MctsAgent.MctsAgent failed on __init__:

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

It seems FactoryFloorIterativeGreedy is assuming it can access a 'pathDict' field inside the FactoryFloorAgent. But this is not thhe case. There is a pathDict but it is generated only after step. Also I doubt that it should be visible.

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Moved that part of the code to FactoryFloorIterativeGreedy#step

Wouter1 pushed a commit that referenced this issue Jun 4, 2020
@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Yes, now we have

Default config 
{'seed': None, 'max_steps': 40, 'environment': {'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}}
{'class': 'aiagents.multi.BasicComplexAgent.BasicComplexAgent', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.mcts.MctsAgent.MctsAgent', 'id': 'robot1', 'parameters': {'simulator': {'fullname': 'aienvs.FactoryFloor.FactoryFloor.FactoryFloor', 'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}, 'treeAgent': {'class': 'aiagents.single.RandomAgent.RandomAgent', 'id': 'robot1', 'parameters': {}}, 'rolloutAgent': {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot1', 'parameters': {}}, 'otherAgents': {'class': 'aiagents.multi.BasicComplexAgent.BasicComplexAgent', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot2', 'parameters': {}}, {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot3', 'parameters': {}}]}, 'iterationLimit': 500, 'diyBonus': 0.0, 'treeParameters': {'explorationConstant': 1, 'samplingLimit': 30, 'maxSteps': 10}}}, {'class': 'aiagents.single.mcts.MctsAgent.MctsAgent', 'id': 'robot2', 'parameters': {'simulator': {'fullname': 'aienvs.FactoryFloor.FactoryFloor.FactoryFloor', 'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}, 'treeAgent': {'class': 'aiagents.single.RandomAgent.RandomAgent', 'id': 'robot2', 'parameters': {}}, 'rolloutAgent': {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot2', 'parameters': {}}, 'otherAgents': {'class': 'aiagents.multi.FactoryFloorIterativeGreedy.FactoryFloorIterativeGreedy', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot1', 'parameters': {}}, {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot3', 'parameters': {}}]}, 'iterationLimit': 500, 'diyBonus': 0.0, 'treeParameters': {'explorationConstant': 1, 'samplingLimit': 30, 'maxSteps': 10}}}, {'class': 'aiagents.single.mcts.MctsAgent.MctsAgent', 'id': 'robot3', 'parameters': {'simulator': {'fullname': 'aienvs.FactoryFloor.FactoryFloor.FactoryFloor', 'steps': 10, 'robots': [{'id': 'robot2', 'pos': 'random'}, {'id': 'robot1', 'pos': 'random'}, {'id': 'robot3', 'pos': 'random'}], 'tasks': ['random', 'random'], 'P_action_succeed': {'LEFT': 0.9, 'RIGHT': 0.9, 'ACT': 0.8, 'UP': 0.9, 'DOWN': 0.9, 'robot1': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot2': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}, 'robot3': {'LEFT': 0.2, 'RIGHT': 0.2, 'ACT': 0.2, 'UP': 0.2, 'DOWN': 0.2}}, 'P_task_appears': 1.0, 'N_task_appears': 4, 'allow_robot_overlap': True, 'allow_task_overlap': True, 'map': ['11111', '11111', '11111', '11111']}, 'treeAgent': {'class': 'aiagents.single.RandomAgent.RandomAgent', 'id': 'robot3', 'parameters': {}}, 'rolloutAgent': {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot3', 'parameters': {}}, 'otherAgents': {'class': 'aiagents.multi.FactoryFloorIterativeGreedy.FactoryFloorIterativeGreedy', 'parameters': {}, 'subAgentList': [{'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot1', 'parameters': {}}, {'class': 'aiagents.single.FactoryFloorAgent.FactoryFloorAgent', 'id': 'robot2', 'parameters': {}}]}, 'iterationLimit': 500, 'diyBonus': 0.0, 'treeParameters': {'explorationConstant': 1, 'samplingLimit': 30}}}]}
No SLURM_JOB_ID found
Action: {'robot1': 3} child value 3.5904761904761906 numVisits 105 totalReward 377.0 variance 0.02552294568621099
Action: {'robot1': 1} child value 3.5 numVisits 100 totalReward 350.0 variance 0.023699999999999992
Action: {'robot1': 2} child value 3.347826086956522 numVisits 92 totalReward 308.0 variance 0.027512944850826
Traceback (most recent call last):
  File "/home/wouter/git/aiagents/examples/MctsExample.py", line 84, in <module>
Action: {'robot1': 4} child value 3.6513761467889907 numVisits 109 totalReward 398.0 variance 0.020768646879722383
Action: {'robot1': 0} child value 3.382978723404255 numVisits 94 totalReward 318.0 variance 0.02650665074212843
    main()
  File "/home/wouter/git/aiagents/examples/MctsExample.py", line 67, in main
    rewards = experiment.run()
  File "/home/wouter/git/aienvs/aienvs/runners/Experiment.py", line 58, in run
    episodeSteps, episodeReward = episode.run()
  File "/home/wouter/git/aienvs/aienvs/runners/Episode.py", line 51, in run
    obs, globalReward, done = self.step(obs, globalReward, done)
  File "/home/wouter/git/aienvs/aienvs/runners/Episode.py", line 32, in step
    actions = self._agent.step(obs, globalReward, done)
  File "/home/wouter/git/aiagents/aiagents/multi/BasicComplexAgent.py", line 17, in step
    agentActions = agentComponent.step(state, reward, done)
  File "/home/wouter/git/aiagents/aiagents/single/mcts/MctsAgent.py", line 93, in step
    root.executeRound()
  File "/home/wouter/git/aiagents/aiagents/single/mcts/nodes.py", line 77, in executeRound
    selectedNode, rolloutReward = selectedNode.expand()
  File "/home/wouter/git/aiagents/aiagents/single/mcts/nodes.py", line 111, in expand
    expandedNode = self._children[key].expand()
  File "/home/wouter/git/aiagents/aiagents/single/mcts/nodes.py", line 186, in expand
    otherActions = self.otherAgents.step(self._parent.getState(), self._parent.immediateReward, self._parent.isTerminal)
  File "/home/wouter/git/aiagents/aiagents/multi/FactoryFloorIterativeGreedy.py", line 27, in step
    pathDict = self._agentSubcomponents[0].pathDict
AttributeError: 'FactoryFloorAgent' object has no attribute 'pathDict'

@czechows
Copy link
Contributor

czechows commented Jun 4, 2020

It seems FactoryFloorIterativeGreedy is assuming it can access a 'pathDict' field inside the FactoryFloorAgent. But this is not thhe case. There is a pathDict but it is generated only after step. Also I doubt that it should be visible.

Yes so this code was not used for a while but I remember that it was the only way to engineer it in a sane way. Perhaps pathDict should be an empty pointer in FactoryFloorAgent on initialization? Everything is by reference so it will work well.

PathDict being public is OK

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

The problem is that even in FactoryFloorIterativeGreedy#step we don't always have pathDict in FactoryFloor.pathDict.

It seems better to make a function getPathDict() or so so that FactoryFloorAgent can compute it if necessary.

@czechows
Copy link
Contributor

czechows commented Jun 4, 2020

The problem is that even in FactoryFloorIterativeGreedy#step we don't always have pathDict in FactoryFloor.pathDict.

It seems better to make a function getPathDict() or so so that FactoryFloorAgent can compute it if necessary.

Well so it does compute it each step for itself anyways.

In general I would be careful with any non-trivial refactoring FactoryFloorAgent because test coverage is not great and it is easy to make things very sub-optimal in terms of computation.

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

Better. Now

Traceback (most recent call last):
  File "/home/wouter/git/aiagents/examples/MctsExample.py", line 84, in <module>
    main()
  File "/home/wouter/git/aiagents/examples/MctsExample.py", line 67, in main
    rewards = experiment.run()
  File "/home/wouter/git/aienvs/aienvs/runners/Experiment.py", line 58, in run
    episodeSteps, episodeReward = episode.run()
  File "/home/wouter/git/aienvs/aienvs/runners/Episode.py", line 51, in run
    obs, globalReward, done = self.step(obs, globalReward, done)
  File "/home/wouter/git/aienvs/aienvs/runners/Episode.py", line 32, in step
    actions = self._agent.step(obs, globalReward, done)
  File "/home/wouter/git/aiagents/aiagents/multi/BasicComplexAgent.py", line 17, in step
    agentActions = agentComponent.step(state, reward, done)
  File "/home/wouter/git/aiagents/aiagents/single/mcts/MctsAgent.py", line 93, in step
    root.executeRound()
  File "/home/wouter/git/aiagents/aiagents/single/mcts/nodes.py", line 77, in executeRound
    selectedNode, rolloutReward = selectedNode.expand()
  File "/home/wouter/git/aiagents/aiagents/single/mcts/nodes.py", line 111, in expand
    expandedNode = self._children[key].expand()
  File "/home/wouter/git/aiagents/aiagents/single/mcts/nodes.py", line 186, in expand
    otherActions = self.otherAgents.step(self._parent.getState(), self._parent.immediateReward, self._parent.isTerminal)
  File "/home/wouter/git/aiagents/aiagents/multi/FactoryFloorIterativeGreedy.py", line 42, in step
    action = ffAgent.getAction(stayInPlacePath)
AttributeError: 'FactoryFloorAgent' object has no attribute 'getAction'

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

The problem is that even in FactoryFloorIterativeGreedy#step we don't always have pathDict in FactoryFloor.pathDict.
It seems better to make a function getPathDict() or so so that FactoryFloorAgent can compute it if necessary.

Well so it does compute it each step for itself anyways.

In general I would be careful with any non-trivial refactoring FactoryFloorAgent because test coverage is not great and it is easy to make things very sub-optimal in terms of computation.

@czechows thanks but I take that as a comment on my fixes; I can not do much with your comment. pathDict was used before it was even computed so the caller's code was broken. I had to clean that up.

Can you please answer the open questions I asked earlier? Progress there is blocked awaiting your answers

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

It seems FactoryFloorIterativeGreedy is assuming it can access a 'pathDict' field inside the FactoryFloorAgent. But this is not thhe case. There is a pathDict but it is generated only after step. Also I doubt that it should be visible.

Yes so this code was not used for a while but I remember that it was the only way to engineer it in a sane way. Perhaps pathDict should be an empty pointer in FactoryFloorAgent on initialization? Everything is by reference so it will work well.

PathDict being public is OK

No it's not OK. It's not even available until an undefined moment. And if it's not avaialble the caller will use a bogus pathDict with your solution.

I fixed this by making an explicit function getPathDict in FactoryFloorAgent that will compute the value if it was not yet computed, and cache it for future use.

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

@czechows This ticket is MUCH more work than anticipated. Maybe we should make a separate ticket for each example. That also allows us to prioritize the work on this. I worked basically the entire day with just 5 examples and they are not even fully fixed yet.

@czechows
Copy link
Contributor

czechows commented Jun 4, 2020

@Wouter1 which questions do you refer to?

It is fine that things are not fully fixed. I didn't know what needed fixing.

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 4, 2020

@czechows I'm out of time already, just writing a quick update

Fixed many things but not nearly enough. Almost all examples are broken and in many ways.

@Wouter1 it is acting for all robots at once
See line:
packedActionSpace = PackedSpace(baseEnv.action_space, {"robots":["robot1", "robot2", "robot3"]})

According to this line the new (combined) id is "robots".

Ah I missed that line. Then there must be something else broken that I still missed

We have to make separate tickets for each example as the amount of work on each is so much. And we then may have to find back the open ends here and collect them.

BTW I put the tickets in aienvs/aiagents but I forgot about them being public.
Are all these reports now visible for public? We may must move them then to the private ticket system....

@czechows
Copy link
Contributor

czechows commented Jun 4, 2020

@czechows I'm out of time already, just writing a quick update

Fixed many things but not nearly enough. Almost all examples are broken and in many ways.

That is fine, perhaps even expected. They were not updated during many revisions,
because they cannot be ran automatically like the tests (I think?) so this work accumulated over some weeks.

@Wouter1 it is acting for all robots at once
See line:
packedActionSpace = PackedSpace(baseEnv.action_space, {"robots":["robot1", "robot2", "robot3"]})

According to this line the new (combined) id is "robots".

Ah I missed that line. Then there must be something else broken that I still missed

We have to make separate tickets for each example as the amount of work on each is so much. And we then may have to find back the open ends here and collect them.

Whether you track it in one or several threads is all fine by me.

BTW I put the tickets in aienvs/aiagents but I forgot about them being public.
Are all these reports now visible for public? We may must move them then to the private ticket system....

Yes they are all public as indicated in my emails from some time ago.
Can you transfer issues yourself -- do you have the button transfer issue? If not, send me the links to the ones you want to hide and I will move them to aienvs-conf-issues (our folder for confidential issues, code there is irrelevant). For me it doesn't matter.

@czechows
Copy link
Contributor

czechows commented Jun 8, 2020

Can you please transfer these? Thanks!
INFLUENCEorg/aienvs#39
INFLUENCEorg/aienvs#40
INFLUENCEorg/aienvs#41
INFLUENCEorg/aienvs#42
INFLUENCEorg/aienvs#43
INFLUENCEorg/aienvs#44

done!

#16
#17
#18
#19

Why would it be impossible to make unit tests for these?

I think examples serve a different purpose than unit tests, and they also sometimes take much longer to finish..

@Wouter1
Copy link
Collaborator Author

Wouter1 commented Jun 8, 2020

@czechows

The unit tests show that the code works.
"the code" now includes examples. And we also want to make sure that the examples work.

So there's nothing wrong with testing the examples.
Yes they need to be tested quickly so we have to make unit tests that test these without doing the full run but only run say a minute or 10 sec, depending on what we know is sufficient to check that they weork properly. And we may also want to change some examples to improve their testability

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

No branches or pull requests

2 participants