the-anylogic-company / AnyLogic-Pypeline

A custom AnyLogic library for running Python inside an AnyLogic model (Java)
https://github.com/the-anylogic-company/AnyLogic-Pypeline/wiki
MIT License
107 stars 27 forks source link

Run AnyLogic from PyPeline #5

Closed EladRa closed 4 years ago

EladRa commented 4 years ago

Hello,

Is there a way to run AnyLogic simulation with a command from the PyCommunicator? If yes - Is there a way to provide an arguments to the simulation from PyCommunicator?

Is there an option to observe the simulation results when ended from the PyCommunicator?

Thanks and Regards, Elad

t-wolfeadam commented 4 years ago

Is there a way to run AnyLogic simulation with a command from the PyCommunicator?

No, the purpose of Pypeline is to run Python from within a running AL model. Python is only able to communicate with your model while the model is running. Every time the model starts, a new, clean Python environment is created. Every time the model stops, the Python environment (including any imports or variables you created) is destroyed.

Think of it like a child process - much like you cannot run AnyLogic without your computer's operating system, you cannot use Pypeline to have Python run an AnyLogic model.

In short: it's AL that's creating the Python environment, not the other way around.

Is there a way to provide an arguments to the simulation from PyCommunicator?

Sort of. You can set parameters when the model starts up - like this.

However, this would need to query some 'live service' or Python code that read/modifies a file to get the next value. This is because every time you start a model, the Python environment is reset - nothing from the previous runs are stored.

Is there an option to observe the simulation results when ended from the PyCommunicator?

I don't understand what you're asking to do. Anytime you can call on the PyCommunicator object, you inherently also have access to your simulation model.

t-wolfeadam commented 4 years ago

I'm closing this for now, but feel free to ask follow-ups and I can re-open.