Does the experimenter work with python scripts?

Does the experimenter work with python scripts?

sean_w4
Not applicable
142 Views
7 Replies
Message 1 of 8

Does the experimenter work with python scripts?

sean_w4
Not applicable

[ FlexSim 22.1.1 ]

I'm working on a model that uses a lot of external python to communicate with a database and make decisions about routing. I wanted to use the experimenter to do simultaneous testing of the model using different datasets which are held in different databases on the same server. I created an integer parameter [1,3] which changes which of the 3 databases the model uses.


This works fine when running the model normally - when I change the parameter everything works as expected with that database. However, when I use the experimenter with 3 scenarios, one for each of the options for the parameter, all of the user commands that call python functions are giving exceptions.


I know python integration is new so maybe it is not supported with the experimenter yet? If it is, was anyone able to do it successfully and is there anything you can think of which would cause the problem I'm having?

0 Likes
Accepted solutions (1)
143 Views
7 Replies
Replies (7)
Message 2 of 8

joerg_vogel_HsH
Mentor
Mentor
You link FlexSim to external databases. Each database must be static while a model runs, because in an Experiment you run multiple instances of your Model simultaneously. If you write and read values while you run a model, there will be inconstancies, because your database won’t run independent instances parallel too. Nor those instances won’t merge at the end. Maybe you test an experiment on a single cpu core and only one thread to verify if you still get those exceptions.
0 Likes
Message 3 of 8

sean_w4
Not applicable

I was only running one iteration of the model for each of the 3 scenarios, each of which is an independent database. I was already planning on creating multiple copies of each starting database in the future to run different iterations simultaneously for the same dataset.

0 Likes
Message 4 of 8

joerg_vogel_HsH
Mentor
Mentor
But 3 scenarios are running simultaneously, as you may see in experimenter run.
0 Likes
Message 5 of 8

sean_w4
Not applicable
Yes, but each one is using a separate database with no shared data. I don't understand why running them simultaneously would be a problem.
0 Likes
Message 6 of 8

JordanLJohnson
Autodesk
Autodesk

I think this is a bug. I made an extremely simple case, attempting to connect to Python in the Experimenter, and it didn't work. I don't think it's related to your databases.

@Joerg Vogel may have a point about simultaneous access, but it depends on the kind of database you are using. If it's a server-side database, then having multiple readers/writers won't be a problem.; most of the big ones (MySQL, Postgres, etc.) are designed for that use case. If it's SQLite, then you may run into a problem where writers block readers.

.


Jordan Johnson
Principal Software Engineer
>

0 Likes
Message 7 of 8

philboboADSK
Autodesk
Autodesk
Accepted solution

@Sean Webster

The issue is in how FlexSim finds the path to the Python DLL. External code paths are stored in VIEW:/environment/ExternalCode, which is where Global Preferences are stored.

The experimenter doesn't have access to that node because it doesn't include the VIEW tree, so it can't find the DLL path.

If you copy the VIEW:/environment/ExternalCode to MODEL:/Tools/ExternalCode, then it will work properly.

We'll fix it on our end so that it works without this workaround, but you can use this workaround to get it working right now in the current version.



Phil BoBo
Sr. Manager, Software Development
Message 8 of 8

sean_w4
Not applicable
Got it, thank you.
0 Likes