question

Jonas Fl avatar image
6 Likes"
Jonas Fl asked Phil BoBo commented

Future Python and FlexSim integration

I have seen many posts in the forum regarding Python and Flexim integration.


After reading most of them, my understanding is that:

- There's no "easy" way of connecting Python with Flexim (with easy I mean without having to master client-server connections, dlls, etc).

- Your FlexSim Development Team is working towards easing this integration, but specifically for Reinforcement Learning (RL) applications.


My question is:

Are you planning, maybe for the near future, to provide a "standard" way (for non-programmers, not limited to RL) to connect Python and FlexSim?


In my opinion, having this possibility would facilitate very much the work of simulation engineers and data scientist both in industrial and in academic environments, where Python is becoming ubiquitous, and where there is not much time to be invested in the connection side of the problem (but rather on the python code or on the simulation).


Specifically, what I have in mind regarding the connection between FlexSim-Python, is the academic concept of "simheuristics": https://www.sciencedirect.com/science/article/pii/S221471601500007X. In summary, "simheuristics" require the simulation (FlexSim) and some algorithm/metaheuristic (written in Python) to work closely together, i.e passing information back and forth seamlessly (simulation outputs, re-starting the simulation at certain stages, updating objects...).


I am not assuming that any of this is easy to implement, but this "question" tries only to encourage the development of the software in this direction should you also consider it of interest.


Thank you very much in advance and congratulations for the good work.

FlexSim 21.2.4
python
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

anthony.johnson avatar image
6 Likes"
anthony.johnson answered Jon Abbott commented

I agree that this is a good application of simulation, and many industrial engineers are gravitating toward using python to solve these questions. Over the past week or so I have been thinking myself about the problem of AGV dispatching/scheduling, and have thrown around the idea of creating an example in FlexSim of a tabu search method for optimizing the scheduling of AGVs within some time horizon. As I thought about implementing this, the question came, should I implement the algorithm in FlexScript, or would it be more beneficial to implement the tabu search in a commonly used language like python? The advantage of implementing it in python is that, once the algorithm is written and optimized (and if I have implemented it properly) it would be relatively easy to then plug that python tabu search algorithm into a live system. But, yes, as Phil mentioned, I don't think you're going to get this without some programming, as, obviously, python is a programming language.

The key, though, is implementing the python algorithm such that it is host-agnostic. In other words, the python algorithm needs to not assume that it is communicating with FlexSim, but that there is just some host feeding it information, and it processes that information, and gives back decisions. Thus, it should not use FlexSim-specific types. I think this would be relatively easy to do, because most of FlexSim's Variant types have direct corollaries in python. Flexsim's Map is essentially a python dict. FlexSim's Array is essentially a python list. FlexSim's string is essentially a python str, and so on. The one type that might not translate well would be node references. So the simulation story would be, FlexSim runs my AGV model. At some point in the model, FlexSim needs to schedule AGV job assignment out for the next 20-30 minuts. FlexSim calls the python algorithm, and it passes one or more Maps, Arrays, strings, or numbers into the function, that give enough information to the python algorithm regarding what needs to be scheduled. The FlexSim engine automatically translates the parameters passing into the function into native python types, then calls the function. The algorithm then executes, and gives back one of the same various types. Then FlexSim's engine then translates back into FlexSim-native types, and the function returns.

Anyway, this is something we definitely want to look into for future FlexSim development. It fits well as a digital twin strategy, where FlexSim becomes a testing application for real algorithms that will be deployed in live systems.

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

alan.zhang avatar image
3 Likes"
alan.zhang answered Phil BoBo commented

This a really nice feature. Just tested in the newest FlexSim 22 Update 1 with a very simple model. It works pretty well. Model and Python file are attached. Put them under the same directory to test it. Great work from FlexSim!

python-test.fsm

PyMod.py


python-test.fsm (27.6 KiB)
pymod.py (34 B)
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.