Python scripting in AnyLogic

At AnyLogic Conference 2021, AnyLogic Principal Software Engineer, Nikolay Churkov, presented research on making Python a second native scripting language in AnyLogic.

Increasingly, data analysts and consultants know how to code with Python and tap into its ecosystem of data processing, data connectivity, and AI-related modules. These facts, combined with easier code-writing and relaxed type handling make Python an attractive coding option for AnyLogic.

Nikolay’s presentation included an experimental version of AnyLogic where all code fields (actions, expressions, etc.) could take Python code while retaining full access to the APIs of the AnyLogic engine and libraries.

Python to AnyLogic Java Engine and Libraries connection
The highlighted Java code goes away when re-written in Python. (Click/Tap to enlarge)

Results from the research show that Python is slower than Java. The slowdown factor, however, is different for different types of models.

For models where most computational complexity is in the code of the engine and libraries (e.g., in Pedestrian or Material Handling models), tested models run 1.5 to 2 times slower. In comparison, for models that are full of frequent user code callbacks (e.g., agent based models of disease diffusion, or in simplistic process models), the factor can be as high as 75. Despite the slower runtime performance, overall project time can still be shorter due to easier and faster code writing and access to the extensive Python ecosystem.

So, if you are keen to part in the ongoing research, let us know! Email us at – we are planning limited access to the experimental Python-scripting version of AnyLogic 8.

Related posts