Inputs Needed please : ExternalProgramServer Object

107 views
Skip to first unread message

Archana R

unread,
Nov 28, 2022, 2:54:17 AM11/28/22
to Jaamsim Users Discussion Group
Hi Harry,
I have seen your basic implementation for the External Program Server object with a Python file. I had used your example and expanded it to "Online Scheduling " for my Production line. 
This means , at a given time certain jobs will be processed based on their start time == initial start time and there will be a Time Jump when a workpackage for a Job is completed And then , There will be a new schedule / plan for Production at this new Time post the time jump.

I am not able to carry out this Time jump and feed the Information ( about the workpackage completion ) back to the External Program Server to generate a New Plan.

What are your thoughts on this case please. 

Thanks,
Archana

Harry King

unread,
Nov 28, 2022, 11:33:41 AM11/28/22
to Jaamsim Users Discussion Group
Archana,

A new plan needs to be created each time your model completes a workpackage for a job. This can be accomplished by sending the workpackage entity to the ExternalProgramServer object, which triggers it to perform its calculation. That arrangement will perform the time jump portion of your question.

Information is fed to the ExternalProgramServer object through its DataSource input. If your workpackage entity has an attribute such as 'jobNumber' that identifies it, then all you need to do is to set the DataSource input to { this.obj.jobNumber }. Your Python program can maintain a list of jobs to be performed and remove the completed job from the list. The returned value from the ExternalProgramServer would be the next job to perform. If more information is needed about the next job, you can add these outputs to the array of values returned by the ExternalProgramServer.

Harry

Archana R

unread,
Nov 30, 2022, 4:27:10 AM11/30/22
to Jaamsim Users Discussion Group
A quick follow up question on the External Program Object:
If in my python file (.py) , a class object is initialised outside the function ( Method ) , will the class object be called everytime a SimEntity enters the External Program Server ? I am trying to understand the difference between ExternalProgramServer and External Program .  What do you mean by ' long running external server ' ?

Eg:

import json
import sys
from retrieval import Retrieval

r = Retrieval()
best_schedule = r.sort_schedule()


def get_plan(args):
        .... << using args[0] as serial number i get in the plan steps >>
       return location, type, product_id, workpackage,duration,start_time

methods = {}
methods["senddetails"] = get_plan



Thanks!

ExternalServerProgram.PNG

Harry King

unread,
Nov 30, 2022, 2:33:04 PM11/30/22
to Jaamsim Users Discussion Group
Archana,

The ExternalProgram object launches the external program each time it calculates a result. The overhead required to launch and close the program each time makes this object very slow. Its only advantage is that it is simpler to implement than the ExternalProgramServer.

The ExternalProgramServer launches the external program just once at the start of the simulation and then waits for the simulation to make queries. You need to set up the external program appropriately for it to function as a server. The attached example shows how to do this. Note that the file extension .py.txt should be changed to just .py.
 
I am not experienced with the Python language, so I cannot give you any detailed help with your program.

Harry

server.py.txt
ExternalProgramServer Example.cfg

Archana R

unread,
Dec 8, 2022, 2:27:58 AM12/8/22
to Jaamsim Users Discussion Group
Thank you Harry . Also quick question - 

When i try any print statements in the .py method - I run into the ExternalProgramServer returning "null" . Somehow when i do not keep them, it runs perfectly. Have you noticed that ? Are there certain limitations to JSON RPC ? What are the other alternatives that you can suggest aside from JSON RPC please ?

Thanks . 

Harry King

unread,
Dec 8, 2022, 11:38:39 PM12/8/22
to Jaamsim Users Discussion Group
Archana,

The Python server code communicates with JaamSim through sys.stdin and sys.stdout. If you add print statements, their output will go to sys.stdout and interfere with this communication. Writing your print statements to sys.stderr might solve this problem.

Harry

Archana R

unread,
Dec 13, 2022, 3:55:53 AM12/13/22
to Jaamsim Users Discussion Group
Hi Harry,
This works now ! Thank you

But I get an error message when i run External Program Server ( EPS error.PNG ) 

existing production plan outside the method called when the simulation starts 
1. I pass in input arguments to the EPS input file
2. I process the data  and modify existing production plan   
3. I return the data based on JSON RPC 
     : {"jsonrpc": "2.0", "id": 1722.0, "result": [1, "T27", 3, 0.0, 12228.283333, 213.4, "2022-12-13 11:48:17"]} being passed back to Jaamsim

and now i observe that even though the result has been generated to pass on to JaamSim , there seems to be an error at this point. 

I have tried different ways to resolve this before reaching out to you seeking for direction. 
EPS error.PNG
EPS error_image.PNG

Harry King

unread,
Dec 13, 2022, 11:28:41 AM12/13/22
to Jaamsim Users Discussion Group
Archana,

I can't give you any guidance without more information. Please prepare a simple example model that reproduces this error and attach it to your next post. I will need both your external Python program and your .cfg file.

Harry

Reply all
Reply to author
Forward
Message has been deleted
0 new messages