question

Sean Webster avatar image
0 Likes"
Sean Webster asked Sean Webster commented

Does the experimenter work with python scripts?

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?

FlexSim 22.1.1
experimenterpython
· 4
5 |100000

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

Joerg Vogel avatar image Joerg Vogel commented ·
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 0 ·
Sean Webster avatar image Sean Webster Joerg Vogel commented ·

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 0 ·
Joerg Vogel avatar image Joerg Vogel Sean Webster commented ·
But 3 scenarios are running simultaneously, as you may see in experimenter run.
0 Likes 0 ·
Show more comments
Phil BoBo avatar image
1 Like"
Phil BoBo answered Sean Webster commented

@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.

· 1
5 |100000

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

Sean Webster avatar image Sean Webster commented ·
Got it, thank you.
0 Likes 0 ·
Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered

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.

5 |100000

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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