Skip to content

swarmrl.agents.classical_agent Module API Reference

Class for classical agents. These are agents not controlled by machine learning. They should also not be trainable.

ClassicalAgent

Bases: Agent

Class to handle the actor-critic RL Protocol.

Source code in swarmrl/agents/classical_agent.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class ClassicalAgent(Agent):
    """
    Class to handle the actor-critic RL Protocol.
    """

    def __init__(
        self,
        particle_type: int,
        actions: dict,
        task: Task = None,
        observable: Observable = None,
    ):
        """
        Constructor for the actor-critic protocol.

        Parameters
        ----------
        network : Network
                Shared Actor-Critic Network for the RL protocol. The apply function
                should return a tuple of (logits, value).
        particle_type : int
                Particle ID this RL protocol applies to.
        observable : Observable
                Observable for this particle type and network input
        task : Task
                Task for this particle type to perform.
        actions : dict
                Actions allowed for the particle.
        """
        self.particle_type = particle_type
        self.task = task
        self.observable = observable
        self.actions = actions

    def calc_action(self, colloids: typing.List[Colloid]) -> typing.List[Action]:
        """
        Copmute the new state for the agent.

        Returns the chosen actions to the force function which
        talks to the espresso engine.

        Parameters
        ----------
        colloids : List[Colloid]
                List of colloids in the system.
        """
        raise NotImplementedError("Implement in subclass")

__init__(particle_type, actions, task=None, observable=None)

Constructor for the actor-critic protocol.

Parameters

network : Network Shared Actor-Critic Network for the RL protocol. The apply function should return a tuple of (logits, value). particle_type : int Particle ID this RL protocol applies to. observable : Observable Observable for this particle type and network input task : Task Task for this particle type to perform. actions : dict Actions allowed for the particle.

Source code in swarmrl/agents/classical_agent.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def __init__(
    self,
    particle_type: int,
    actions: dict,
    task: Task = None,
    observable: Observable = None,
):
    """
    Constructor for the actor-critic protocol.

    Parameters
    ----------
    network : Network
            Shared Actor-Critic Network for the RL protocol. The apply function
            should return a tuple of (logits, value).
    particle_type : int
            Particle ID this RL protocol applies to.
    observable : Observable
            Observable for this particle type and network input
    task : Task
            Task for this particle type to perform.
    actions : dict
            Actions allowed for the particle.
    """
    self.particle_type = particle_type
    self.task = task
    self.observable = observable
    self.actions = actions

calc_action(colloids)

Copmute the new state for the agent.

Returns the chosen actions to the force function which talks to the espresso engine.

Parameters

colloids : List[Colloid] List of colloids in the system.

Source code in swarmrl/agents/classical_agent.py
49
50
51
52
53
54
55
56
57
58
59
60
61
def calc_action(self, colloids: typing.List[Colloid]) -> typing.List[Action]:
    """
    Copmute the new state for the agent.

    Returns the chosen actions to the force function which
    talks to the espresso engine.

    Parameters
    ----------
    colloids : List[Colloid]
            List of colloids in the system.
    """
    raise NotImplementedError("Implement in subclass")