salina.agents.remote
salina.agents.remote.NRemoteAgent (Agent)
Multiple agents executed in different processes. Use the NRemoteAgent.create function to create such an agent
create(agent, num_processes=0, time_size=None, **extra_kwargs)
staticmethod
Returns a NRemote agent with num_processes copies of agent in different processes Also returns the specific workspace to use with such an agent
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent |
[salina.Agent] |
The agent to execute in multiple processes |
required |
num_processes |
int |
Number of processes to create. If 0, then no processes are created (for debugging). Defaults to 0. |
0 |
time_size |
[type] |
If specified, it forces the created Workspace to have this particular time_size. Defaults to None. |
None |
Returns:
| Type | Description |
|---|---|
[salina.Agent,salina.SharedWorkspace] |
The NRemoteAgent and the corresponding workspace |
Source code in salina/agents/remote.py
@staticmethod
def create(agent, num_processes=0, time_size=None, **extra_kwargs):
"""Returns a NRemote agent with num_processes copies of agent in different processes
Also returns the specific workspace to use with such an agent
Args:
agent ([salina.Agent]): The agent to execute in multiple processes
num_processes (int, optional): Number of processes to create. If 0, then no processes are created (for debugging). Defaults to 0.
time_size ([type], optional): If specified, it forces the created Workspace to have this particular time_size. Defaults to None.
Returns:
[salina.Agent,salina.SharedWorkspace]: The NRemoteAgent and the corresponding workspace
"""
agent.seed(0)
if num_processes == 0:
workspace = Workspace()
_agent = copy.deepcopy(agent)
agent(workspace, **extra_kwargs)
shared_workspace = workspace._convert_to_shared_workspace(
n_repeat=1, time_size=time_size
)
return _agent, shared_workspace
workspace = Workspace()
agents = [copy.deepcopy(agent) for t in range(num_processes)]
agent(workspace, **extra_kwargs)
b = workspace.batch_size()
batch_dims = [(k * b, k * b + b) for k, a in enumerate(agents)]
shared_workspace = workspace._convert_to_shared_workspace(
n_repeat=num_processes, time_size=time_size
)
agents = [RemoteAgent(a) for a in agents]
return NRemoteAgent(agents, batch_dims), shared_workspace