Autolev Parser: Status Update

I have a PR for a working parser now with some test cases. The Travis errors I had previously have been fixed.

I am currently going through the chapters of the book Dynamics Online: Theory and Implementation with Autolev and parsing most of the Autolev codes I come across. I feel this would help to make the parser more complete. After getting the desired parsed code I am also running the code and checking that the results are same/similar to the Autolev responses in the .ALL files.

I have parsed the codes of Chapter 1 and 2 of the book and am currently working on Chapter 3. There are 6 Chapters overall and the bulk of the stuff is concentrated in Chapters 4 and 5.

After parsing the codes of this book, I shall update the parser code and the tests in the PR. I will add more test cases as well. I will also send in a file containing all the parsed codes of Dynamics Online.

A lot of the codes are parsing completely fine. A few I feel are quite difficult to parse to SymPy code using a parser and they wouldn’t even be in the spirit of SymPy/Python if parsed exactly. I have marked these for later. A few of them are producing slightly altered expressions or in some cases errors in SymPy. I am classifying all the codes appropriately based on criteria like this.

After parsing the book I plan on finishing up the leftover parts of the Autolev Tutorial examples and making sure the Bicycle Model Autolev code is parsed.

I will then go on to do a complete code cleanup (general cleanup, using standard conventions and better variable names, adding more comments etc).

Finally, I will wrap things up by writing the Documentation and a Final Report. In these I shall discuss: what the parser can do, how it should be used (there are some minor things in some cases that the user should note to get a proper SymPy parse), limitations and future improvements.

Advertisements
Standard

Autolev Parser (using ANTLR v4)

In this post, I shall discuss my project: Autolev Parser (using ANTLR v4). This is the timeline I am proposing. Please suggest any changes if required.

Timeline:

Finalize this after discussing things with the mentors.

Phase 1:

Weeks 1 and 2 (May 15 – May 28): Refactor the grammar and the preprocessing steps. Finish parsing the mathematical entities of Autolev.  Start off with parsing the symbolic dynamics part of Autolev. (Pull request #1)

Weeks 3 and 4 (May 29 – Jun 11): Work on parsing the symbolic dynamics part of Autolev using sympy.physics.vector and sympy.physics.mechanics. (Pull request #2)

 

Phase 2:

Weeks 5 (Jun 12 – Jun 18): Work further on the symbolic dynamics part. Work on the more difficult parts of the parser ie translations which are quite indirect and require more code and tweaking as opposed to calling equivalent SymPy commands. (Pull request #3)

Weeks 6, 7 and 8 (Jun 19 – Jul 9): Work on parsing the solvers and visualization parts. Use sympy.solvers and numerical solvers from the SciPy stack to translate the algebraic, nonlinear and ODE solvers. Use pydy.codegen to solve the equations of motion numerically and use sympy.physics.units to manipulate the units before plugging the values in. Use matplotlib and pydy.viz to translate the plotting parts. (Pull request #4)

 

Phase 3:

Weeks 9, 10 and 11 (Jul 17 – Aug 6): Refactor and tie up all the things done earlier and work on writing lots of test cases and well documented examples. Run benchmarking tests and make sure the results obtained are correct. (Pull request #5)

Week 12: (Jul 10 – Jul 16) Implement the error handling and recovery mechanism discussed in the Design section.

Week 13 (Aug 6 – Aug 14): Wrap everything up. Refactor the code, tests and examples and do a cleanup. (Pull request #6)

 

Code Setup:

Now I shall discuss some of the technical details about how my code is setup. You can find the code on my Github here.

  1. The antlr_essentials directory contains the antlr jar file and some bat files. If you want to run antlr commands, first specify the classpath of this jar file in the commands prompt.
  2. The test files directory contains the example test files on which I run the code. The files example5.1-example5.9 are examples of the same names in the Autolev Tutorial.  I have also included whipple.txt which is the bicycle model Autolev code. The directory also contains png image files of the parse trees generated when the grammar is run on these test files.
  3. Autolev.g4 is the grammar file. AutolevLexer.py, AutolevParser.py and AutolevListener.py are files automatically generated by ANTLR. A listener is basically a tree walker which triggers events when it enters and exits a rule. One can use this mechanism by subclassing AutolevListener.
  4. The file myListener.py contains the myListener class which simply subclasses AutolevListener. This is where I will be putting the majority of the parser code.
  5. The file autolev.py initializes the parser, lexer and listener and is the file you would want to run. Running ‘python autolev.py input.txt’ on the file input.txt which contains Autolev code would generate the parsed SymPy output in an output file of choice.
  6. The pydy_for_autolev_users.rst is a guide and I will keep updating it as I keep parsing more of the Autolev language.

I haven’t put much of an emphasis on code readability. Should this be an aspect to focus on? I am thinking the parsed output and the results are of primary concern. One reason I feel this way is because this isn’t core SymPy code and the project is niche and that the majority of code is based in ANTLR. Please tell me if you don’t think the same.

 

Status of the Project:

I have finished writing the grammar for the Autolev language. I am now partway through parsing the mathematical entities.

Parsing Mathematical Entities :
# Constants ✓
# Variables ✓
# Imaginary ✓
# MotionVariables ✓
# Specifieds ✓
# Expression reconstruction ✓
# Assignments ✓
# Math commands (deal with function calls) and expressions
# Reserved names and constants (T, Pi etc)
# Matrices

I have written code to parse the basic mathematical variable declarations such as constants, variables, specifieds etc.  I have also written code for expression reconstruction and assignment. I will now work all the math commands, reserved names and matrices. I will be handling vectors and dyadics in the physics part as sympy.physics.vector is more appropriate in the sense of Autolev and symbolic dynamics. Go over pydy_for_autolev_users.rst to get an idea of the different mathematical commands and physical entities. You can have a look at input1.txt and the parsed output in output1.txt in the test_files directory of autolev-parser on my Github.

I will get started with the symbolic dynamics part next once I am done with the mathematical entities.

Do you think I am headed in the right direction with the project? Please let me know what you think. Any feedback is much appreciated.

Standard