michele-segata / plexe-pyapi

Python APIs to control Plexe models in SUMO
49 stars 14 forks source link

Question on running joindemo.py #1

Closed lcipolina closed 4 years ago

lcipolina commented 4 years ago

Hello, thanks for this library.

I am trying to run joindemo.py:

$python /home/alpha/plexe-pyapi/examples/joindemo.py

I get the following error:

Retrying in 1 seconds
Loading configuration... done.
No Plexe API implementation found for SUMO UNKNOWN
Traceback (most recent call last):
  File "/home/alpha/plexe-pyapi/examples/joindemo.py", line 217, in <module>
    main(True, False)
  File "/home/alpha/plexe-pyapi/examples/joindemo.py", line 159, in main
    plexe = Plexe()
  File "/home/alpha/plexe-pyapi/examples/plexe.py", line 110, in __init__
    raise Exception()
Exception

Thank you very much!

michele-segata commented 4 years ago

Which version of SUMO are you running? I tried the join demo with SUMO 1.6.0 and it properly works.

lcipolina commented 4 years ago

Hi Michele, thank you very much for your quick reply

Happens that with my SUMO 1.6.0 I was getting the error on your FAQS (when running the examples on the Sumo-plexe tutorial) http://plexe.car2x.org/faq/

Unknown cfmodel when parsing vtype 'vtypeauto'

So I uninstalled all the SUMOs and used your SUMO-PLEXE, as recommended on the FAQs..

My paths are as follows:

export SUMO_HOME=/home/alpha/src/plexe-sumo
export PATH=$PATH:~/src/plexe-sumo/bin

See below for my SUMO version

(plexe) alpha@alpha:~/plexe-pyapi$ which sumo
/home/alpha/src/plexe-sumo/bin/sumo

(plexe) alpha@alpha:~/plexe-pyapi$ sumo --version

 Eclipse SUMO Version UNKNOWN

 Build features: Linux-5.3.0-62-generic Proj GUI GDAL OSG GL2PS SWIG
 Copyright (C) 2001-2018 German Aerospace Center (DLR) and others; http://sumo.dlr.de

Eclipse SUMO Version UNKNOWN is part of SUMO.
This program and the accompanying materials
are made available under the terms of the Eclipse Public License v2.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
lcipolina commented 4 years ago

ok, so now I've installed SUMO 1.6 and change the SUMO_HOME env variable to SUMO's regular version.

I still get the following error...

I did: export SUMO_HOME=/usr/share/sumo

(plexe) alpha@alpha:~/plexe-pyapi$ sudo pip install . Successfully installed PlexeAPI-1.0

(plexe) alpha@alpha:~/plexe-pyapi$ python /home/alpha/plexe-pyapi/examples/joindemo.py

The error:

 Retrying in 1 seconds
Loading configuration ... done.

**No Plexe API implementation found for SUMO 1.6.0**

Traceback (most recent call last):
  File "/home/alpha/plexe-pyapi/examples/joindemo.py", line 217, in <module>
    main(True, False)
  File "/home/alpha/plexe-pyapi/examples/joindemo.py", line 159, in main
    plexe = Plexe()
  File "/home/alpha/plexe-pyapi/examples/plexe.py", line 110, in __init__
    raise Exception()
Exception

I see on plexe.py the following versions allowed:

class Plexe(traci.StepListener):

latest = [1, 1, 0]
versions = {
    'SUMO d1422e4780a': [0, 32, 0],
    'SUMO 619df188ac3': [0, 32, 0],
    'SUMO 1.0.1': [1, 0, 1],
    'SUMO 1.1.0': [1, 1, 0],
    'SUMO v1_1_0': [1, 1, 0]
}

If I install SUMO 0.32 I get the error: unknown car following model 'CC' when parsing vType 'vtypeauto'

michele-segata commented 4 years ago

Can you check that your python APIs are at the latest version, i.e., commit 9a9416e? Because I've added a default fallback in case the SUMO version doesn't match. So if no compatible SUMO version handler is found, there is one handler that it is being used as default. Here is the code indicating that the plexe_sumo_eclipse is the default implementation, while here is the portion of the code that selects the default implementation if a match on the version is not found.

lcipolina commented 4 years ago

Hi Michele, yes, I've downloaded the Repo today... (I see that your changes are dated back from 2 years ago.)

I can try to debug the code and see where the version is failing

One question.... what SUMO_HOME (and any other SUMO related env variable) should be on my .bashrc?

This is my latest configuration (I reverted to SUMO 0.32)

export SUMO_HOME=/usr/share/sumo 
#export SUMO_HOME=/home/alpha/src/plexe-sumo
export PATH=$PATH:/home/alpha/Downloads/omnetpp-5.6.2/bin
export PATH=$PATH:~/src/plexe-sumo/bin

Thanks! and sorry for having so many questions!

michele-segata commented 4 years ago

I can try to debug the code and see where the version is failing

This would really help me fixing the bug. Just put a couple of print around the place where the default implementation should be selected and try to see why it is not selected.

One question.... what SUMO_HOME (and any other SUMO related env variable) should be on my .bashrc?

You should have SUMO_HOME in order for python to find the libraries. This is not Plexe specific, this is required by SUMO.

This is my latest configuration (I reverted to SUMO 0.32)

I would avoid using SUMO 0.32.0. I would keep 1.6.0 and try to find why the Python API are not "accepting" it. It should be an easy fix.

export SUMO_HOME=/usr/share/sumo 
#export SUMO_HOME=/home/alpha/src/plexe-sumo
export PATH=$PATH:/home/alpha/Downloads/omnetpp-5.6.2/bin
export PATH=$PATH:~/src/plexe-sumo/bin

Careful here! You are mixing up different installations. You have the standard SUMO in /usr/share and plexe-sumo in ~/src/plexe-sumo. If you don't plan to modify SUMO, just keep the binary version and get rid of any reference to plexe-sumo in your .bashrc file.

lcipolina commented 4 years ago

ok, I commented theplexe-sumo in .bashrc and I re-installed SUMO 1.6.0... and I still get the same error. (we can discuss this later, I was trying to run the Plexe tutorials, which I succeded having those env variables in place.., but thought this API will be more handy as it's python-based)

To give you some color, my research is to do some Platooning + Reinforcement Learning. So a python API sounds great.

Just to rule out the obvious before debugging, is this meant to run in Python 3?

michele-segata commented 4 years ago

Just to rule out the obvious before debugging, is this meant to run in Python 3?

Yes, I am using it with Python 3.

lcipolina commented 4 years ago

I am debugging with Pycharm... I see the following

Script: plexe.py Line: 107

 if self.plexe is None:
            self.plexe = default_impl

however, the value of default_impl = none as it was set on line 85

I see that this value should be set on lines 104-105 but this loop is skipped

   if 'default' in versions:
                    default_impl = instance
plexe-error

Regarding line 95:

     try:
                    instance = mod.PlexeImp()

AttributeError: module 'plexe.plexe_imp.__init__' has no attribute 'PlexeImp'

Command: imp.load_module("plexe.plexe_imp." + name, mod_f, mod_fn, mod_d)

Output: ModuleNotFoundError: No module named 'plexe.plexe_imp'; 'plexe' is not a package

However I do see the file there...

plexe-error2
michele-segata commented 4 years ago

This is very strange. I tried to change the library used to perform the import as the old one was marked as obsolete. Can you fetch the changes and re-install the package with

pip install --user --upgrade .
lcipolina commented 4 years ago

Michele, thank you very much for all the time you've put into solving this issue. I've finally made it work! I'll close the issue since it's resolved.

These were my steps in case someone find it useful.

# Download the library

cd to the folder you want to download the library

git clone https://github.com/michele-segata/plexe-pyapi.git

# Build (outside any conda environment)

cd plexe-pyapi sudo pip install . (notice the dot at the end) pip install --user .

#Usage

conda activate plexe (I've build an environment to install q5) cd ~plexe-pyapi/examples SUMO_HOME=/usr/share/sumo/ #set the PATH environment for latest SUMO version (in case you have other versions installed. ) python joindemo.py

michele-segata commented 4 years ago

Just a quick note. You shouldn't do both

sudo pip install .

and

pip install --user .

You either have to choose whether to install it system-wide (run the first) or install it for the current user only (run the second).

lcipolina commented 4 years ago

Thank you very much for all this time Michele. I will create a tutorial for you and make a "Pull request" in case you find it useful for other folks navigating this page.