Page 1 of 1

How to run multiple instances in newest version of CoppeliaSim

Posted: 10 Feb 2022, 08:18
by r_dhak
Hello,
So I am doing some learning tasks for a manipulator. However the simulation normally take several hours with the parameters I need (e.g. no. of steps, no. of episodes, etc.).

So I would like to run several simulations in parallel so that I could try different hyperparameters parallely.
I read about questions on similar topics, however I would like to have a general answer to it (Sorry for that).

System Specifications:
  • OS - Ubuntu 20.04
  • CPU - Intel i7-11700KF (3.6 Ghz), 16 Cores
  • GPU - Nvidia RTX 3060
  • CoppeliaSim ver 4.3.0 (rev0)
I am using the ZMQ remote api.

So I would like to know the answers for following queestions:
  • How to run multiple instances, which are independent of each other (changing the port number?, which is 23000 by default for ZMQ)

Code: Select all

/CoppeliaSim/programming/zmqRemoteApi/clients/python/zmqRemoteApi/__init__.py

Code: Select all

class RemoteAPIClient:
    """Client to connect to CoppeliaSim's ZMQ Remote API."""

    def __init__(self, host='localhost', port=23000, cntport=None, *, verbose=None):
  • How can I assign separate cores for individual simulation instances
  • I want to run the same script (with different parameters) on same the Scene (but multiple), do I have to create separate project files for all of them?
I am looking for a general answer on how to achieve this.

Thank You.

Re: How to run multiple instances in newest version of CoppeliaSim

Posted: 10 Feb 2022, 09:16
by coppelia
Hello,

to run several instances of CoppeliaSim, then indeed, you will have to make sure that each instance runs its ZeroMQ remote API server on a different port. You can do this via command-line and named parameters, e.g.:

Code: Select all

coppeliaSim.sh -GzmqRemoteApi.rpcPort=23002
There are actually two ports needed, there is also zmqRemoteApi.cntPort which by default is zmqRemoteApi.rpcPort+1

Cheers

Re: How to run multiple instances in newest version of CoppeliaSim

Posted: 10 Feb 2022, 13:01
by r_dhak
I gave it a try, the first instance starts properly.
However for the second instance, in the CoppeliaSim Lua console it says

Code: Select all

[WebSocket remote API server@addOnScript:error] 113: in simWS.start@simExtWS: Address already in use
    stack traceback:
        [C]: in function 'simWS-typecheck.start'
        [string "WebSocket remote API server@addOnScript"]:113: in function 'sysCall_init'
the first instance I ran with coppeliaSim.sh -GzmqRemoteApi.rpcPort=23002

and for the second one, coppeliaSim.sh -GzmqRemoteApi.rpcPort=23004

as you said the second port takes port+1

Re: How to run multiple instances in newest version of CoppeliaSim

Posted: 10 Feb 2022, 13:28
by coppelia
For the websocket add-on, you will have to do something similar, with the named parameter wsRemoteApi, e.g.:

Code: Select all

coppeliaSim.sh -GzmqRemoteApi.rpcPort=23002 -GwsRemoteApi.port=23051
But the websocket add-on is probably not needed in your case.

Cheers

Re: How to run multiple instances in newest version of CoppeliaSim

Posted: 10 Feb 2022, 13:49
by r_dhak
So I just ignored the Websocket warning and went on running the simulation.
I copied the complete CoppeliaSim folder as well as my project folder.

In the CoppeliaSim folder (/CoppeliaSim/programming/zmqRemoteApi/clients/python/zmqRemoteApi/__init__.py)
I changed the port number, and used the same port to connect to to Python client.

[__init__.py ]

Code: Select all

 class RemoteAPIClient:
    """Client to connect to CoppeliaSim's ZMQ Remote API."""

    def __init__(self, host='localhost', port=23010, cntport=None, *, verbose=None):
[Python client connection]

Code: Select all

client = RemoteAPIClient('localhost',23010)
And for the second one (from the second directory in terminal I just run)
coppeliaSim.sh -GzmqRemoteApi.rpcPort=23000
I did the same and just changed the port number at both the places and also in the running from terminal command.

I believe this is the right way to do it.

Result: Both the simulation seems to be running properly also saving results properly.

Re: How to run multiple instances in newest version of CoppeliaSim

Posted: 10 Feb 2022, 16:25
by coppelia
you should also be able to run several instances from the same folder. Check additional possible settings in system/usrset.txt.

Cheers

Re: How to run multiple instances in newest version of CoppeliaSim

Posted: 11 Feb 2022, 10:47
by r_dhak
Thank you for the information.

I was successful running my simulations in parallel.
However I could only run 5 instances.

When I try to run more instances in parallel, I get "RuntimeError: CUDA error: out of memory".

So I was wondering if it is possible to run CoppeliaSim on GPU (for rendering, as I suspect its only the rendering which might be using all the memory).

Re: How to run multiple instances in newest version of CoppeliaSim

Posted: 11 Feb 2022, 11:29
by coppelia
CoppeliaSim renders via GPU, it would be super slow otherwise. You can run CoppeliaSim in headless mode (switch -h), which should reduce GPU usage, and running several CoppeliaSim instances not in headless mode rarely makes sense.
If you do not use/need vision sensors, then you can also run in true headless mode by using the true headless library libcoppeliaSimHeadless.so: simply rename it to libcoppeliaSim.so. Then could still connect to individual instances via the visualization stream add-on, and connect via a browser to the CoppeliaSim instance.

Cheers