SepShr / MLCSHE

This repo houses the ML-Component Systemic Hazard Envelope project, or MILSCHE (pronounced /'mɪlʃ/).
MIT License
3 stars 0 forks source link

install error (run_iccea.py) #30

Closed donghwan-shin closed 2 years ago

donghwan-shin commented 2 years ago

After installing everything (except pywin32), I execute run_iccea.py and got the following error:

(venv) ubuntu@ip-172-31-35-138:~/MLCSHE$ python run_iccea.py 
Traceback (most recent call last):
  File "run_iccea.py", line 5, in <module>
    from src.main.ICCEA import ICCEA
  File "/home/ubuntu/MLCSHE/src/main/ICCEA.py", line 8, in <module>
    from problem_utils import (run_carla, run_pylot, update_sim_config)
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 12, in <module>
    logging.basicConfig(file_name='sim_log.log', level=logging.DEBUG,
  File "/usr/lib/python3.8/logging/__init__.py", line 2009, in basicConfig
    raise ValueError('Unrecognised argument(s): %s' % keys)
ValueError: Unrecognised argument(s): file_name
donghwan-shin commented 2 years ago

This could be fixed by replacing

https://github.com/SepShr/MLCSHE/blob/dd66241cf50446283e4a059ea9ea118f61ceff25/problem_utils.py#L12

into

logging.basicConfig(filename='sim_log.log', level=logging.DEBUG,

However, another error occurs as follows:

(venv) ubuntu@ip-172-31-35-138:~/MLCSHE$ python run_iccea.py 
popScen is: [[1, 1, 0], [0, 4, 1]]
PopMLCO is: [[2, 0, 0], [0, 1, 0]]
the current generation is: 0
scenario_list is: [1, 1, 0]
mlco_list is: 
Resetting the simulation setup.
Traceback (most recent call last):
  File "run_iccea.py", line 17, in <module>
    solution = solver.solve(max_gen=2)
  File "/home/ubuntu/MLCSHE/src/main/ICCEA.py", line 41, in solve
    completeSolSet, popScen, popMLCO = self.evaluate(
  File "/home/ubuntu/MLCSHE/src/main/ICCEA.py", line 195, in evaluate
    c.fitness.values = self.evaluate_joint_fitness(c)
  File "/home/ubuntu/MLCSHE/src/main/ICCEA.py", line 114, in evaluate_joint_fitness
    joint_fitness_value = self.toolbox.problem_jfit(x, y)
  File "/home/ubuntu/MLCSHE/problem.py", line 108, in problem_joint_fitness
    DfC_min, DfV_max, DfP_max, DfM_max, DT_max, traffic_lights_max = run_simulation(
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 350, in run_simulation
    update_sim_config(scenario_list_deepcopy, mlco_list_deepcopy)
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 227, in update_sim_config
    mlco_flag = translate_mlco_list(mlco_list)
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 113, in translate_mlco_list
    copy_to_container(container_name, source_path, destination_path)
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 156, in copy_to_container
    container_id = find_container_id(container_name)
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 188, in find_container_id
    return container_id
UnboundLocalError: local variable 'container_id' referenced before assignment

The UnboundLocalError could be solved by adding an init of container_id before line 188 at File "/home/ubuntu/MLCSHE/problem_utils.py"

donghwan-shin commented 2 years ago

In the end, I was able to run the python script and got the following results:

(venv) ubuntu@ip-172-31-35-138:~/MLCSHE$ cat sim_log.log 
2022-02-13 21:49:10,353:DEBUG:simulator_weather set to CloudySunset
2022-02-13 21:49:10,353:DEBUG:Number of pedestrians is set to 0
2022-02-13 21:53:41,513:DEBUG:simulator_weather set to CloudySunset
2022-02-13 21:53:41,514:DEBUG:Number of pedestrians is set to 18
2022-02-13 21:53:59,219:DEBUG:simulator_weather set to HardRainNoon
2022-02-13 21:53:59,220:DEBUG:Number of pedestrians is set to 18
2022-02-13 21:57:30,715:DEBUG:simulator time of day is set to night.
2022-02-13 21:57:30,715:DEBUG:simulator_weather set to HardRainSunset
2022-02-13 21:57:30,715:DEBUG:Number of pedestrians is set to 18
2022-02-13 21:59:56,042:WARNING:Did not find the simulation results, i.e., results/[2, 5, 1]
2022-02-13 21:59:56,042:WARNING:Returning 1000 for all simulation results.
2022-02-13 21:59:56,116:DEBUG:simulator time of day is set to night.
2022-02-13 21:59:56,116:DEBUG:simulator_weather set to HardRainSunset
2022-02-13 21:59:56,116:DEBUG:Number of pedestrians is set to 18
2022-02-13 22:02:21,535:WARNING:Did not find the simulation results, i.e., results/[2, 5, 1]
2022-02-13 22:02:21,535:WARNING:Returning 1000 for all simulation results.
2022-02-13 22:02:21,606:DEBUG:simulator_weather set to ClearSunset
2022-02-13 22:02:21,607:DEBUG:Number of pedestrians is set to 0
2022-02-13 22:04:46,895:WARNING:Did not find the simulation results, i.e., results/[1, 0, 0]
2022-02-13 22:04:46,895:WARNING:Returning 1000 for all simulation results.
2022-02-13 22:04:46,966:DEBUG:simulator_weather set to ClearSunset
2022-02-13 22:04:46,966:DEBUG:Number of pedestrians is set to 0
2022-02-13 22:07:12,563:WARNING:Did not find the simulation results, i.e., results/[1, 0, 0]
2022-02-13 22:07:12,563:WARNING:Returning 1000 for all simulation results.
2022-02-13 22:07:12,639:DEBUG:simulator time of day is set to night.
2022-02-13 22:07:12,639:DEBUG:simulator_weather set to HardRainSunset
2022-02-13 22:07:12,639:DEBUG:Number of pedestrians is set to 18
2022-02-13 22:09:38,044:WARNING:Did not find the simulation results, i.e., results/[2, 5, 1]
2022-02-13 22:09:38,045:WARNING:Returning 1000 for all simulation results.
2022-02-13 22:09:38,122:DEBUG:simulator time of day is set to night.
2022-02-13 22:09:38,122:DEBUG:simulator_weather set to HardRainSunset
2022-02-13 22:09:38,122:DEBUG:Number of pedestrians is set to 18
2022-02-13 22:12:03,510:WARNING:Did not find the simulation results, i.e., results/[2, 5, 1]
2022-02-13 22:12:03,510:WARNING:Returning 1000 for all simulation results.
2022-02-13 22:12:03,583:DEBUG:simulator_weather set to SoftRainNoon
2022-02-13 22:12:03,584:DEBUG:Number of pedestrians is set to 0
2022-02-13 22:14:28,954:WARNING:Did not find the simulation results, i.e., results/[0, 6, 0]
2022-02-13 22:14:28,954:WARNING:Returning 1000 for all simulation results.
2022-02-13 22:14:29,029:DEBUG:simulator_weather set to SoftRainNoon
2022-02-13 22:14:29,029:DEBUG:Number of pedestrians is set to 0
2022-02-13 22:16:54,413:WARNING:Did not find the simulation results, i.e., results/[0, 6, 0]
2022-02-13 22:16:54,413:WARNING:Returning 1000 for all simulation results.
2022-02-13 22:16:54,484:DEBUG:simulator_weather set to SoftRainNoon
2022-02-13 22:16:54,484:DEBUG:Number of pedestrians is set to 0
2022-02-13 22:19:19,826:WARNING:Did not find the simulation results, i.e., results/[0, 6, 0]
2022-02-13 22:19:19,826:WARNING:Returning 1000 for all simulation results.

I will continue investigating the code tomorrow. :)

SepShr commented 2 years ago

Regarding your last comment, it shows that either the simulation log files that contain the fitness values are not being created by the container, which can be checked by looking inside the /home/erdos/workspace/results/ folder; or the copy_to_host() function is not working.

SepShr commented 2 years ago

After installing everything (except pywin32), I execute run_iccea.py and got the following error:

(venv) ubuntu@ip-172-31-35-138:~/MLCSHE$ python run_iccea.py 
Traceback (most recent call last):
  File "run_iccea.py", line 5, in <module>
    from src.main.ICCEA import ICCEA
  File "/home/ubuntu/MLCSHE/src/main/ICCEA.py", line 8, in <module>
    from problem_utils import (run_carla, run_pylot, update_sim_config)
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 12, in <module>
    logging.basicConfig(file_name='sim_log.log', level=logging.DEBUG,
  File "/usr/lib/python3.8/logging/__init__.py", line 2009, in basicConfig
    raise ValueError('Unrecognised argument(s): %s' % keys)
ValueError: Unrecognised argument(s): file_name

Apologies for the bugs, I was experimenting with some refactoring and logging and synced them with repo so that I can work on it on my Ubuntu machine. The commit ID of the code that I used for my EC2 instance is b14d45fef37456b326da6a6c4fd10dfc5fa7ebc6.

I also suppose that the error with the requirements.txt was due to the fact that I froze the requirements of my Windows machine instead of Ubuntu. I will fix that as well.

SepShr commented 2 years ago

This could be fixed by replacing

https://github.com/SepShr/MLCSHE/blob/dd66241cf50446283e4a059ea9ea118f61ceff25/problem_utils.py#L12

into

logging.basicConfig(filename='sim_log.log', level=logging.DEBUG,

However, another error occurs as follows:

(venv) ubuntu@ip-172-31-35-138:~/MLCSHE$ python run_iccea.py 
popScen is: [[1, 1, 0], [0, 4, 1]]
PopMLCO is: [[2, 0, 0], [0, 1, 0]]
the current generation is: 0
scenario_list is: [1, 1, 0]
mlco_list is: 
Resetting the simulation setup.
Traceback (most recent call last):
  File "run_iccea.py", line 17, in <module>
    solution = solver.solve(max_gen=2)
  File "/home/ubuntu/MLCSHE/src/main/ICCEA.py", line 41, in solve
    completeSolSet, popScen, popMLCO = self.evaluate(
  File "/home/ubuntu/MLCSHE/src/main/ICCEA.py", line 195, in evaluate
    c.fitness.values = self.evaluate_joint_fitness(c)
  File "/home/ubuntu/MLCSHE/src/main/ICCEA.py", line 114, in evaluate_joint_fitness
    joint_fitness_value = self.toolbox.problem_jfit(x, y)
  File "/home/ubuntu/MLCSHE/problem.py", line 108, in problem_joint_fitness
    DfC_min, DfV_max, DfP_max, DfM_max, DT_max, traffic_lights_max = run_simulation(
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 350, in run_simulation
    update_sim_config(scenario_list_deepcopy, mlco_list_deepcopy)
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 227, in update_sim_config
    mlco_flag = translate_mlco_list(mlco_list)
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 113, in translate_mlco_list
    copy_to_container(container_name, source_path, destination_path)
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 156, in copy_to_container
    container_id = find_container_id(container_name)
  File "/home/ubuntu/MLCSHE/problem_utils.py", line 188, in find_container_id
    return container_id
UnboundLocalError: local variable 'container_id' referenced before assignment

The UnboundLocalError could be solved by adding an init of container_id before line 188 at File "/home/ubuntu/MLCSHE/problem_utils.py"

I was not able to reproduce this error.

donghwan-shin commented 2 years ago

The last error was fixed by simply adding

container_id = ''

just before the for loop in https://github.com/SepShr/MLCSHE/blob/3d2d1f44869b3583c743929879b0de9a383b28bc/problem_utils.py#L176-L188

p.s. independently from the init error, you can simply use

        if container_name in i:

instead of

        if i.__contains__(container_name):