Skip to content

salina.agents.utils

salina.agents.utils.Agents (Agent)

An agent that contains multiple agents that will be executed sequentially

Parameters:

Name Type Description Default
Agent [salina.Agent]

The agents

required

__init__(self, *agents, *, name=None) special

Creates the agent from multiple agents

Parameters:

Name Type Description Default
name [str]

[name of the resulting agent]. Defaults to None.

None
Source code in salina/agents/utils.py
def __init__(self, *agents, name=None):
    """ Creates the agent from multiple agents

    Args:
        name ([str], optional): [name of the resulting agent]. Defaults to None.
    """
    super().__init__(name=name)
    for a in agents:
        assert isinstance(a, Agent)
    self.agents = nn.ModuleList(agents)

salina.agents.utils.TemporalAgent (Agent)

Execute one Agent over multiple timesteps

__call__(self, workspace, t=0, n_steps=None, stop_variable=None, **kwargs) special

Execute the agent starting at time t, for n_steps

Parameters:

Name Type Description Default
workspace [salina.Workspace] required
t int

The starting timestep. Defaults to 0.

0
n_steps [type]

The number of steps. Defaults to None.

None
stop_variable [type]

if True everywhere (at time t), execution is stopped. Defaults to None = not used.

None
Source code in salina/agents/utils.py
def __call__(self, workspace, t=0, n_steps=None, stop_variable=None, **kwargs):
    """Execute the agent starting at time t, for n_steps

    Args:
        workspace ([salina.Workspace]):
        t (int, optional): The starting timestep. Defaults to 0.
        n_steps ([type], optional): The number of steps. Defaults to None.
        stop_variable ([type], optional): if True everywhere (at time t), execution is stopped. Defaults to None = not used.
    """

    assert not (n_steps is None and stop_variable is None)
    _t = t
    while True:
        self.agent(workspace, t=_t, **kwargs)
        if not stop_variable is None:
            s = workspace.get(stop_variable, _t)
            if s.all():
                break
        _t += 1
        if not n_steps is None:
            if _t >= t + n_steps:
                break

__init__(self, agent, name=None) special

The agent to transform to a temporal agent

Parameters:

Name Type Description Default
agent [salina.Agent]

The agent to encapsulate

required
name [str]

Name of the agent

None
Source code in salina/agents/utils.py
def __init__(self, agent, name=None):
    """ The agent to transform to a temporal agent

    Args:
        agent ([salina.Agent]): The agent to encapsulate
        name ([str], optional): Name of the agent
    """
    super().__init__(name=name)
    self.agent = agent

salina.agents.utils.CopyTAgent (Agent)

An agent that copies a variable

Parameters:

Name Type Description Default
input_name [str]

The variable to copy from

required
output_name [str]

The variable to copy to

required
detach [bool]

copy with detach if True

required

salina.agents.utils.PrintAgent (Agent)

An agent to generate print in the console (mainly for debugging)

Parameters:

Name Type Description Default
Agent [type]

[description]

required

__init__(self, *names, *, name=None) special

Parameters:

Name Type Description Default
names [str]

The variables to print

()
Source code in salina/agents/utils.py
def __init__(self, *names, name=None):
    """
    Args:
        names ([str], optional): The variables to print
    """
    super().__init__(name=name)
    self.names = names