Skip to content

Container Layer

Bases: ComponentManager, Agent

Class that represents a container layer.

Source code in edge_sim_py/components/container_layer.py
 9
10
11
12
13
14
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class ContainerLayer(ComponentManager, Agent):
    """Class that represents a container layer."""

    # Class attributes that allow this class to use helper methods from the ComponentManager
    _instances = []
    _object_count = 0

    def __init__(self, obj_id: int = None, digest: str = "", size: int = 0, instruction: str = "") -> object:
        """Creates an User object.

        Args:
            obj_id (int, optional): Object identifier. Defaults to None.
            digest (str, optional): Layer digest. Defaults to "".
            size (int, optional): Layer size (in megabytes). Defaults to 0.
            instruction (str, optional): Layer instruction. Defaults to "".

        Returns:
            object: Created User object.
        """
        # Adding the new object to the list of instances of its class
        self.__class__._instances.append(self)

        # Object's class instance ID
        self.__class__._object_count += 1
        if obj_id is None:
            obj_id = self.__class__._object_count
        self.id = obj_id

        # Layer's metadata
        self.digest = digest
        self.size = size
        self.instruction = instruction

        # Reference to the server that hosts the layer
        self.server = None

        # Model-specific attributes (defined inside the model's "initialize()" method)
        self.model = None
        self.unique_id = None

    def _to_dict(self) -> dict:
        """Method that overrides the way the object is formatted to JSON."

        Returns:
            dict: JSON-friendly representation of the object as a dictionary.
        """
        dictionary = {
            "attributes": {
                "id": self.id,
                "digest": self.digest,
                "size": self.size,
                "instruction": self.instruction,
            },
            "relationships": {
                "server": {"class": type(self.server).__name__, "id": self.server.id} if self.server else None,
            },
        }
        return dictionary

    def collect(self) -> dict:
        """Method that collects a set of metrics for the object.

        Returns:
            metrics (dict): Object metrics.
        """
        metrics = {}
        return metrics

    def step(self):
        """Method that executes the events involving the object at each time step."""
        ...

__init__(obj_id=None, digest='', size=0, instruction='')

Creates an User object.

Parameters:

Name Type Description Default
obj_id int

Object identifier. Defaults to None.

None
digest str

Layer digest. Defaults to "".

''
size int

Layer size (in megabytes). Defaults to 0.

0
instruction str

Layer instruction. Defaults to "".

''

Returns:

Name Type Description
object object

Created User object.

Source code in edge_sim_py/components/container_layer.py
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
def __init__(self, obj_id: int = None, digest: str = "", size: int = 0, instruction: str = "") -> object:
    """Creates an User object.

    Args:
        obj_id (int, optional): Object identifier. Defaults to None.
        digest (str, optional): Layer digest. Defaults to "".
        size (int, optional): Layer size (in megabytes). Defaults to 0.
        instruction (str, optional): Layer instruction. Defaults to "".

    Returns:
        object: Created User object.
    """
    # Adding the new object to the list of instances of its class
    self.__class__._instances.append(self)

    # Object's class instance ID
    self.__class__._object_count += 1
    if obj_id is None:
        obj_id = self.__class__._object_count
    self.id = obj_id

    # Layer's metadata
    self.digest = digest
    self.size = size
    self.instruction = instruction

    # Reference to the server that hosts the layer
    self.server = None

    # Model-specific attributes (defined inside the model's "initialize()" method)
    self.model = None
    self.unique_id = None

collect()

Method that collects a set of metrics for the object.

Returns:

Name Type Description
metrics dict

Object metrics.

Source code in edge_sim_py/components/container_layer.py
68
69
70
71
72
73
74
75
def collect(self) -> dict:
    """Method that collects a set of metrics for the object.

    Returns:
        metrics (dict): Object metrics.
    """
    metrics = {}
    return metrics

step()

Method that executes the events involving the object at each time step.

Source code in edge_sim_py/components/container_layer.py
77
78
79
def step(self):
    """Method that executes the events involving the object at each time step."""
    ...