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

RRT integration issues #37

Open
stanleybak opened this issue Jul 21, 2016 · 5 comments
Open

RRT integration issues #37

stanleybak opened this issue Jul 21, 2016 · 5 comments

Comments

@stanleybak
Copy link
Contributor

stanleybak commented Jul 21, 2016

I've made an initial integration of Aviral's rrt-hybrid repository code into the hyst repostory. Use this branch to perform further development: https://github.com/stanleybak/hyst/tree/rrt-printer

There are several things that need to be addressed before we integrate it into the main release.

First, I get errors when I run the rrt tool. I tried it on three models in our examples folder and got three different errors for each one. I suggest we make sure the tool works on the examples in the examples directory. I added to our regression tests which runs all tools on all models. You can run that script by going to src/tests/regression and doing python run_tests.py. Here's a snippet of the current output:

Test failed for 2/90 model lorenz with pyrrt: Error (Tool)

Log:
Running pyrrt on model /home/stan/repositories/hyst/src/tests/regression/models/lorenz/lorenz.xml
Hyst command: ['java', '-jar', '/home/stan/repositories/hyst/src/Hyst.jar', '/home/stan/repositories/hyst/src/tests/regression/models/lorenz/lorenz.xml', '-o', '/home/stan/repositories/hyst/src/tests/regression/result/lorenz_pyrrt.py', '-pyrrt']

Finished converting in 522 ms
Seconds for Hyst conversion: 2.05994796753
Traceback (most recent call last):
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/tool_pyrrt.py", line 54, in <module>
    tool_main(PyRrtTool())
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/hybrid_tool.py", line 75, in tool_main
    code = tool_obj.run()
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/hybrid_tool.py", line 271, in run
    rv = self._run_tool()
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/tool_pyrrt.py", line 30, in _run_tool
    self._result = run()
  File "/tmp/pyrrt_823_491011/lorenz_pyrrt.py", line 40, in run
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/pyrrt/expt_opt.py", line 1133, in run
    my_rrt = RRT(ha, list_of_initial_states, init_states[0][0])
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/pyrrt/expt_opt.py", line 342, in __init__
    self.ha.modes[modes].inv_strings, self.ha.variables)
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/pyrrt/util.py", line 34, in parser
    eq = eq.replace(" ", "")
AttributeError: 'bool' object has no attribute 'replace'
Elapsed Seconds: 2.66518187523
Result: Error (Tool)

Error detected running regression tests.

The second issue is code quality and customization. For customization, the expt_opt function needs to take in parameters like the amount of time per step. The plotting function should automatically detect a reasonable plot range, in addition to being able to used fixed coordinates. The script outputs random output to stdout. A percent done or # of iterations might be okay, but it looks like debugging output at this point. The names are unclear, why is it called expt_opt? I renamed test_cvxopt to util since it looks like utilities. I moved the global variable t = np.linspace(0, 0.2, 4) into functions (why was it global?). There may be other such issues in the code which should be cleaned up. The global pylint score for pyrrt is currently 6.71/10, let's try to get it above 9.

@aviralkumar2907
Copy link

Can you tell the path to the nav_*.py file describing hybrid automaton for the case you ran the rrt code? The first error seems to be an error, where the guard_sympy expression declared in this file is boolean and not a string.

@stanleybak
Copy link
Contributor Author

It's probably better if you get my branch and can run the scripts yourself rather than having to interact with me for each problem. The script will not produce *.py files, as it's using hypy which puts them in temporary directories behind the scenes unless an explicit output file is requested.

To produce the model file for debugging, you need to run Hyst on the input .xml file, with the flag to use the rrt printer. In this case, since the file causing the issue is lorenz, we go the the src folder which contains Hyst.jar and run java -jar Hyst.jar -pyrrt ../examples/lorenz/lorenz.xml -o output.py. This produces output.py in the local directory.

As for this particular case, the latest rrt code doesn't use sympy. It's true that it looks like the parser function is using sympy due to its signature: def parser(guard_sympy, varorder):, but the actual call to the function is using something else: A, b = test_cvxopt.parser(self.ha.modes[modes].inv_strings, self.ha.variables). In this case, it's using inv_strings. We should probably update the variable names in the code to fix this.

For this case, after producing the output.py, I saw in the model definition running.inv_strings = [True]. The bug, then, was in Hyst's PyRRT printer. This file is part of Hyst, located at hyst/src/java/com/verivital/hyst/printers/PyRrtPrinter.java. I would then edit this file, run ant to rebuild Hyst.jar, and try again.

In the RRT printer file, there is a RrtSymbolicPrinter class that has methods printTrue and printFalse, which affect the printing for such constants in the output .py file. The question then is, what should the correct printing be for an invariant that is true? For now, I've replaced it with 0 == 0 for true and 0 == 1 for false, although that seems like a little bit of a hack.

After that fix, I get a different error:

Test failed for 2/90 model lorenz with pyrrt: Error (Tool)

Log:
Running pyrrt on model /home/stan/repositories/hyst/src/tests/regression/models/lorenz/lorenz.xml
Hyst command: ['java', '-jar', '/home/stan/repositories/hyst/src/Hyst.jar', '/home/stan/repositories/hyst/src/tests/regression/models/lorenz/lorenz.xml', '-o', '/home/stan/repositories/hyst/src/tests/regression/result/lorenz_pyrrt.py', '-pyrrt']

Finished converting in 385 ms
Seconds for Hyst conversion: 2.02757406235
Traceback (most recent call last):
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/tool_pyrrt.py", line 54, in <module>
    tool_main(PyRrtTool())
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/hybrid_tool.py", line 75, in tool_main
    code = tool_obj.run()
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/hybrid_tool.py", line 271, in run
    rv = self._run_tool()
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/tool_pyrrt.py", line 30, in _run_tool
    self._result = run()
  File "/tmp/pyrrt_759_1466558/lorenz_pyrrt.py", line 40, in run
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/pyrrt/expt_opt.py", line 1133, in run
    my_rrt = RRT(ha, list_of_initial_states, init_states[0][0])
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/pyrrt/expt_opt.py", line 342, in __init__
    self.ha.modes[modes].inv_strings, self.ha.variables)
  File "/home/stan/repositories/hyst/src/hybridpy/hybridpy/pyrrt/util.py", line 45, in parser
    b.append(float(eq_1[1]))
IndexError: list index out of range
Elapsed Seconds: 2.76715898514
Result: Error (Tool)



Error detected running regression tests.

I've attached the output.py file for this model, although I hope you can repeat the steps above yourself to find and fix any remaining errors. I'll be traveling for two weeks so I won't be able to be re-running these. The rrt source files are located in hyst/src/hybridpy/hybridpy/pyrrt if you need to change them. There's a readme in the main hyst folder for getting setup with hypy (you may need to adjust your PYTHONPATH environment variable).

@stanleybak
Copy link
Contributor Author

stanleybak commented Jul 21, 2016

One small correction: The regression test script does output the intermediate files with the models so you may not need to run the Hyst jar manually, unless you want to. They are placed in hyst/src/tests/regression/result, and in this case the model file is called lorenz_pyrrt.py.

@aviralkumar2907
Copy link

I think for the true invariant, we can simply write it as "True" (boolean) and I will incorporate this in the RRT code (utils.py) .

@stanleybak
Copy link
Contributor Author

go ahead and try to update the PyRrtPrinter.java file yourself. Once all the tests pass you can submit the changes to my branch as a pull request.

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