Hi, I am wondering if as XML-RPC client there is meanwhile a solution to pause a simulation run after a pre-defined amount of elapsed time. I do see the method pause under an object of xmlrpc class, i.e.
plecs = xmlrpc.client.ServerProxy(“``http://localhost``:XXXX”).plecs
That is to say, one may create an object using the command:
plecs.pause
However, I have no idea about parametrization of this method and how plecs.pause works.
Any ideas / solutions to my questions would be appreatiated.
Cheers!
Navid
There is not a pause method. With XML-RPC you can create a method object with an arbitrary name. However, when you actually call the method you will see receive an error message: server error: requested method not found as there is no corresponding implementation on the server side. You can verify this using listMethods:
proxy = xmlrpc.client.ServerProxy("http://localhost:1080")
proxy.system.listMethods()
Is the amount of elapsed time wall-clock time or simulation time?
The way to stop a simulation after an elapsed amount of wall-clock time is to use the Timeout option set in the SolverOpts field. From the documentation:
Timeout: A non-negative number that specifies the maximum number of seconds (wall-clock time) that a simulation or analysis is allowed to run. After this period the simulation or analysis is stopped with a timeout error. A value of 0 disables the timeout.
Pausing the simulation implies the simulation must continue after the pause. You can save and restore the system state to continue the simulation from where it stopped and even change system parameters in between. The code below provides an example, noting that you’ll have to manage and store data between the runs (save scope traces or results returned by the simulate command).
import xmlrpc.client
proxy = xmlrpc.client.ServerProxy("http://localhost:1080")
print(proxy.system.listMethods())
MODEL_NAME = 'your_model_name'
Timeout = 0.01
TotalSimTime = 10
opts = {
'SolverOpts':
{
'TimeSpan':TotalSimTime,
'Timeout':Timeout,
'InitialSystemState':'',
}
}
try:
proxy.plecs.simulate(MODEL_NAME,opts)
except xmlrpc.client.Fault:
user_response = input("Simulation stopped after {Timeout} seconds. Do you want to continue? (y/n): ").lower()
if user_response == 'y':
print("Continuing with the operation...")
SystemState = proxy.plecs.get(MODEL_NAME,'SystemState')
StopTime = SystemState['StopTime']
opts['SolverOpts']['Timeout'] = 0 # Don't pause
opts['SolverOpts']['InitialSystemState'] = SystemState # Restore state
opts['SolverOpts']['TimeSpan'] = TotalSimTime - StopTime # Continue for desired sim run
proxy.plecs.simulate(MODEL_NAME,opts)
elif user_response == 'n':
print("Exiting the operation.")
else:
print("Invalid input. Please enter 'y' or 'n'.")