verivital / hyst

HyST: A Source Transformation and Translation Tool for Hybrid Automaton Models
http://verivital.com/hyst/
Other
15 stars 18 forks source link

Hybridize pysim #31

Closed stanleybak closed 8 years ago

stanleybak commented 8 years ago

This is a large set of changes I've been working on since the beginning of the year.

The main initial change is the removal of the internal simulation engine from Hyst and instead a python-based one, which uses scipy for numerical integration. This allows for simulations of multi-mode automata, and creates another hyst target for simple simulations and plotting called pysim.

This also meant that any pass (Continuization, Pseudo-invariant with sim, Simulation-guided Hybridization) that used simulations needed to be adapted to the new simulation mechanism. This also means making these work for multi-mode systems is possible (journal extensions of the existing papers).

Also, while rewriting, I changed all the passes to use args4j to parse command line arguments, rather than the ad-hoc mechanisms they were using. This required updating associated tests.

Automated support for converting look-up tables to hybrid automata is merged in.

I've added demonstrations and associated hypy scripts to run each of the transformation passes: pseudo-invariants, continuizaton, and hybridization. These are in doc/transformation_passes. There are READMEs in each folder with more details on each example, and a plot.py script which shows the hyst parameters needed to produce the results. This corresponds to the demo given at HSCC2016.

I've added github templates for pull requests and issue submission. See this post for more info on this: https://github.com/blog/2111-issue-and-pull-request-templates

There are also many bug fixes and tests added.

ttj commented 8 years ago

I get some errors on unit tests in Windows:

unit_test:
       [junit] Running com.verivital.hyst.junit.ContinuizationPassTests
       [junit] Testsuite: com.verivital.hyst.junit.ContinuizationPassTests
       [junit] TODO working here, get rid of simulator
       [junit] TODO working here, get rid of simulator
       [junit] TODO working here, get rid of simulator
       [junit] TODO working here, get rid of simulator
       [junit] Tests run: 4, Failures: 0, Errors: 4, Skipped: 0, Time elapsed: 0.191 sec
       [junit] Tests run: 4, Failures: 0, Errors: 4, Skipped: 0, Time elapsed: 0.191 sec
       [junit] ------------- Standard Output ---------------
       [junit] TODO working here, get rid of simulator
       [junit] TODO working here, get rid of simulator
       [junit] TODO working here, get rid of simulator
       [junit] TODO working here, get rid of simulator
       [junit] ------------- ---------------- ---------------
       [junit] Testcase: testContinuizationPassSineWave[0] took 0.155 sec
       [junit]  Caused an ERROR
       [junit] null
       [junit] java.lang.NullPointerException
       [junit]  at com.verivital.hyst.geometry.Interval.mult(Unknown Source)
       [junit]  at com.verivital.hyst.passes.complex.ContinuizationPass.substituteCyberVariables(Unknown Source)
       [junit]  at com.verivital.hyst.passes.complex.ContinuizationPass.runPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runVanillaPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runTransformationPass(Unknown Source)
       [junit]  at com.verivital.hyst.junit.ContinuizationPassTests.testContinuizationPassSineWave(Unknown Source)
       [junit] Testcase: testContinuizationPassDoubleIntegrator[0] took 0.005 sec
       [junit]  Caused an ERROR
       [junit] null
       [junit] java.lang.NullPointerException
       [junit]  at com.verivital.hyst.geometry.Interval.mult(Unknown Source)
       [junit]  at com.verivital.hyst.passes.complex.ContinuizationPass.substituteCyberVariables(Unknown Source)
       [junit]  at com.verivital.hyst.passes.complex.ContinuizationPass.runPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runVanillaPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runTransformationPass(Unknown Source)
       [junit]  at com.verivital.hyst.junit.ContinuizationPassTests.testContinuizationPassDoubleIntegrator(Unknown Source)
       [junit] Testcase: testContinuizationPassSineWave[1] took 0.004 sec
       [junit]  Caused an ERROR
       [junit] null
       [junit] java.lang.NullPointerException
       [junit]  at com.verivital.hyst.geometry.Interval.mult(Unknown Source)
       [junit]  at com.verivital.hyst.passes.complex.ContinuizationPass.substituteCyberVariables(Unknown Source)
       [junit]  at com.verivital.hyst.passes.complex.ContinuizationPass.runPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runVanillaPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runTransformationPass(Unknown Source)
       [junit]  at com.verivital.hyst.junit.ContinuizationPassTests.testContinuizationPassSineWave(Unknown Source)
       [junit] Testcase: testContinuizationPassDoubleIntegrator[1] took 0.003 sec
       [junit]  Caused an ERROR
       [junit] null
       [junit] java.lang.NullPointerException
       [junit]  at com.verivital.hyst.geometry.Interval.mult(Unknown Source)
       [junit]  at com.verivital.hyst.passes.complex.ContinuizationPass.substituteCyberVariables(Unknown Source)
       [junit]  at com.verivital.hyst.passes.complex.ContinuizationPass.runPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runVanillaPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runTransformationPass(Unknown Source)
       [junit]  at com.verivital.hyst.junit.ContinuizationPassTests.testContinuizationPassDoubleIntegrator(Unknown Source)

BUILD FAILED
D:\Dropbox\Research\verivital_repos\hyst-stan\src\build.xml:173: Test com.verivital.hyst.junit.ContinuizationPassTests failed
stanleybak commented 8 years ago

This may be from an old version. Be sure to sure the hybridize-pysim branch, not master.

ttj commented 8 years ago

Ok, sorry, I did the switch. The order reduction pass now has some unit tests failing, probably related to the change in the pass parameters (as it requires a parameter), so I will try to debug a little:

[junit] Running com.verivital.hyst.junit.PassTests
       [junit] Testsuite: com.verivital.hyst.junit.PassTests
       [junit] tests/unit/models/order_reduction/
       [junit] tests/unit/models/order_reduction/
       [junit] Tests run: 6, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 38.113 sec
       [junit] Tests run: 6, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 38.113 sec
       [junit] ------------- Standard Output ---------------
       [junit] tests/unit/models/order_reduction/
       [junit] tests/unit/models/order_reduction/
       [junit] ------------- ---------------- ---------------
       [junit] Testcase: testSubConstantsPll[0] took 0.374 sec
       [junit] Testcase: testOrderReductionpass[0] took 37.415 sec
       [junit]  Caused an ERROR
       [junit] Error Parsing Order Reduction (decrease dimensionality) Pass,
       [junit]  Message: No argument is allowed: 3
       [junit] Arguments: '3'
       [junit]  -reducedOrder NUM : reduced order dimensionality
       [junit] com.verivital.hyst.ir.AutomatonExportException: Error Parsing Order Reduction (decrease dimensionality) Pass,
       [junit]  Message: No argument is allowed: 3
       [junit] Arguments: '3'
       [junit]  -reducedOrder NUM : reduced order dimensionality
       [junit]  at com.verivital.hyst.passes.TransformationPass.runPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runVanillaPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runTransformationPass(Unknown Source)
       [junit]  at com.verivital.hyst.junit.PassTests.testOrderReductionpass(Unknown Source)
       [junit] Testcase: testSimplifyExpressions[0] took 0.002 sec
       [junit] Testcase: testSubConstantsPll[1] took 0.029 sec
       [junit] Testcase: testOrderReductionpass[1] took 0.235 sec
       [junit]  Caused an ERROR
       [junit] Error Parsing Order Reduction (decrease dimensionality) Pass,
       [junit]  Message: No argument is allowed: 3
       [junit] Arguments: '3'
       [junit]  -reducedOrder NUM : reduced order dimensionality
       [junit] com.verivital.hyst.ir.AutomatonExportException: Error Parsing Order Reduction (decrease dimensionality) Pass,
       [junit]  Message: No argument is allowed: 3
       [junit] Arguments: '3'
       [junit]  -reducedOrder NUM : reduced order dimensionality
       [junit]  at com.verivital.hyst.passes.TransformationPass.runPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runVanillaPass(Unknown Source)
       [junit]  at com.verivital.hyst.passes.TransformationPass.runTransformationPass(Unknown Source)
       [junit]  at com.verivital.hyst.junit.PassTests.testOrderReductionpass(Unknown Source)
       [junit] Testcase: testSimplifyExpressions[1] took 0.001 sec

BUILD FAILED
D:\Dropbox\Research\verivital_repos\hyst-stan\src\build.xml:174: Test com.verivital.hyst.junit.PassTests failed
stanleybak commented 8 years ago

Yes, I think you're right. Instead of using an agument 3, try -reducedOrder 3.

I wonder why this test didn't run on my computer...

ttj commented 8 years ago

Yes, that allows the tests to pass on my machine on Windows now at least. You probably didn't see this one as it requires matlab.

ttj commented 8 years ago

The regression tests have some problems now (trying to call tools although they don't exist):

regression_test:
        [exec] flowstar not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/flowstar-1.2.3/flowstar. Environment variable FLOWSTAR_BIN was NOT set. Tool will be set as non-runnable.
        [exec] hycreate not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/hycreate2. Environment variable HYCREATE_BIN was NOT set. Tool will be set as non-runnable.
        [exec] spaceex not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/spaceex/spaceex. Environment variable SPACEEX_BIN was NOT set. Tool will be set as non-runnable.
        [exec] dreach not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/dreach/dReal-2.15.01-linux/bin/dReach. Environment variable DREACH_BIN was NOT set. Tool will be set as non-runnable.
        [exec] Script results (plots / model files / work dirs) will be saved to: D:\Dropbox\Research\verivital_repos\hyst-stan\src\tests\regression/result
        [exec] Using single-threaded tests
        [exec] 1/80 Running 3d_stable with flowstar
        [exec] Timeouts not supported on windows... skipping
        [exec] 1/80 Finished 3d_stable with flowstar
        [exec] 2/80 Running 3d_stable with hycreate
        [exec] Timeouts not supported on windows... skipping
        [exec] 2/80 Finished 3d_stable with hycreate
        [exec] 3/80 Running 3d_stable with dreach
        [exec] Timeouts not supported on windows... skipping
        [exec] 3/80 Finished 3d_stable with dreach
        [exec] 4/80 Running 3d_stable with pysim
        [exec] flowstar not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/flowstar-1.2.3/flowstar. Environment variable FLOWSTAR_BIN was NOT set. Tool will be set as non-runnable.
        [exec] hycreate not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/hycreate2. Environment variable HYCREATE_BIN was NOT set. Tool will be set as non-runnable.
        [exec] spaceex not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/spaceex/spaceex. Environment variable SPACEEX_BIN was NOT set. Tool will be set as non-runnable.
        [exec] dreach not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/dreach/dReal-2.15.01-linux/bin/dReach. Environment variable DREACH_BIN was NOT set. Tool will be set as non-runnable.
        [exec] Timeouts not supported on windows... skipping
        [exec] 4/80 Finished 3d_stable with pysim
        [exec] Test failed for 4/80 model 3d_stable with pysim: Error (Tool)
        [exec] Log:
        [exec] flowstar not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/flowstar-1.2.3/flowstar. Environment variable FLOWSTAR_BIN was NOT set. Tool will be set as non-runnable.
        [exec] flowstar cannot be run; skipping. Did you set FLOWSTAR_BIN?
        [exec] Tool script exit code: 3
        [exec] Elapsed Seconds: 0.055999994278
        [exec] Result: Error (Unsupported Dynamics)
        [exec] hycreate not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/hycreate2. Environment variable HYCREATE_BIN was NOT set. Tool will be set as non-runnable.
        [exec] hycreate cannot be run; skipping. Did you set HYCREATE_BIN?
        [exec] Tool script exit code: 3
        [exec] Elapsed Seconds: 0.055999994278
        [exec] Result: Error (Unsupported Dynamics)
        [exec] Starting dReach. If you kill the tool early, be sure to kill any spawned subprocesses ('killall dReal').
        [exec] dreach not found at path: D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy/dreach/dReal-2.15.01-linux/bin/dReach. Environment variable DREACH_BIN was NOT set. Tool will be set as non-runnable.
        [exec] dreach cannot be run; skipping. Did you set DREACH_BIN?
        [exec] Tool script exit code: 3
        [exec] Elapsed Seconds: 0.0540001392365
        [exec] Result: Error (Unsupported Dynamics)
        [exec] Traceback (most recent call last):
        [exec]   File "D:\Dropbox\Research\verivital_repos\hyst-stan\src\hybridpy\hybridpy\tool_pysim.py", line 3, in <module>
        [exec]     from hybridpy.hybrid_tool import HybridTool
        [exec] ImportError: No module named hybridpy.hybrid_tool
        [exec] Elapsed Seconds: 0.0260000228882
        [exec] Result: Error (Tool)
        [exec] Error detected running regression tests.

BUILD FAILED
D:\Dropbox\Research\verivital_repos\hyst-stan\src\build.xml:190: exec returned: 1

Total time: 1 second
stanleybak commented 8 years ago

Ok, so what's happening is since your PYTHONPATH is not including hypy, it adds it to the python process. but then pysim spawns a new python process without PYTHONPATH, which makes it miss the import: ImportError: No module named hybridpy.hybrid_tool

I didn't see this since my PYTHONPATH is set beforehand.

fixing now...

stanleybak commented 8 years ago

Should be fixed now, I added the assignment to the environment variable in the regression tests which affects child processes: os.environ['PYTHONPATH'] = pre_pythonpath + hypy_path

stanleybak commented 8 years ago

Ok, the regression tests now pass on my (clean install) Windows. There were two problems in the run_tests.py script (not Hyst), and one issue with Hyst itself where it tried to use python to simplify expressions after converting LUT tables, even though python didn't have the required libraries. This could be detected in the printers test by making them parameterized tests, like the other unit tests. I did that now and added a test so it shouldn't happen again.

Give it a try and let me know...

ttj commented 8 years ago

Ok, yes, all unit and regression tests pass on my set up now, so I'll merge it now.