Skip to content

Commit 16afc6a

Browse files
Merge pull request #35 from agustin-recoba/feature/network_rename
Network -> DirectedNetwork class rename
2 parents e6008b9 + c5c6e2c commit 16afc6a

17 files changed

+58
-53
lines changed

docs/reference/networkbehavior.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class defines the three parameters that are used to model the communication prop
1616
#. How fast a node can process a message. This is used to model the case where a node can only process a certain
1717
number of messages per time unit.
1818

19-
To apply these properties to a network, simply set :attr:`Network.behavioral_properties` to an instance of
19+
To apply these properties to a network, simply set :attr:`NetworkType.behavioral_properties` to an instance of
2020
:class:`NetworkBehaviorModel`.
2121

2222

docs/reference/networkmixin.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PyDistSim uses the library :mod:`networkx` to represent graphs. :mod:`networkx`
1111
In order to extend the defined :class:`networkx.Graph` and :class:`networkx.DiGraph` in :mod:`networkx`, PyDistSim uses a mixin class.
1212

1313
This mixin class is called NetworkMixin and is defined in the network module.
14-
For the development of the framework, we have used this mixin to define :class:`Network` and :class:`BidirectionalNetwork`,
14+
For the development of the framework, we have used this mixin to define :class:`DirectedNetwork` and :class:`BidirectionalNetwork`,
1515
which are subclasses of :class:`networkx.Graph` and :class:`networkx.DiGraph` respectively.
1616

1717
In broad terms, these NetworkMixin subclasses are responsible for the following:
@@ -23,5 +23,5 @@ In broad terms, these NetworkMixin subclasses are responsible for the following:
2323

2424
For class and method documentation refer to :class:`NetworkMixin`.
2525

26-
.. inheritance-diagram:: Network BidirectionalNetwork
27-
:caption: Inheritance diagram for Network and BidirectionalNetwork
26+
.. inheritance-diagram:: DirectedNetwork BidirectionalNetwork
27+
:caption: Inheritance diagram for DirectedNetwork and BidirectionalNetwork

docs/reference/observers.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Standardize the use of observers in the framework, we implemented a mixin class
2828
can be used to add observer functionality to any class. The mixin class provides methods to add and remove observers,
2929
and to notify the observers of changes in the observable object.
3030

31-
.. inheritance-diagram:: ObserverManagerMixin pydistsim.algorithm.BaseAlgorithm pydistsim.simulation.Simulation pydistsim.network.network.Network pydistsim.network.network.BidirectionalNetwork pydistsim.network.node.Node
31+
.. inheritance-diagram:: ObserverManagerMixin pydistsim.algorithm.BaseAlgorithm pydistsim.simulation.Simulation pydistsim.network.network.DirectedNetwork pydistsim.network.network.BidirectionalNetwork pydistsim.network.node.Node
3232
:top-classes: ObserverManagerMixin
3333
:parts: 1
3434
:caption: ObserverManagerMixin inheritance diagram

pydistsim/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
from pydistsim.algorithm import NodeAlgorithm, StatusValues
3232
from pydistsim.benchmark import AlgorithmBenchmark
3333
from pydistsim.logging import disable_logger, enable_logger, logger
34-
from pydistsim.network import BidirectionalNetwork, Network, NetworkGenerator, Node
34+
from pydistsim.network import (
35+
BidirectionalNetwork,
36+
DirectedNetwork,
37+
NetworkGenerator,
38+
Node,
39+
)
3540
from pydistsim.simulation import Simulation
3641

3742
__path__ = extend_path(__path__, __name__) # @ReservedAssignment

pydistsim/algorithm/base_algorithm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class SomeAlgorithm(NodeAlgorithm):
8888
required_params = ('rp1',)
8989
default_params = {'dp1': 'dv1',}
9090
91-
>>> net = Network()
91+
>>> net = DirectedNetwork()
9292
>>> alg = SomeAlgorithm(net, rp1='rv1')
9393
>>> alg.rp1
9494
'rv1'

pydistsim/benchmark.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
from pydistsim.metrics import MetricCollector
1616
from pydistsim.network.behavior import NetworkBehaviorModel
1717
from pydistsim.network.generator import NetworkGenerator
18-
from pydistsim.network.network import BidirectionalNetwork, Network, NetworkType
18+
from pydistsim.network.network import BidirectionalNetwork, DirectedNetwork, NetworkType
1919
from pydistsim.simulation import AlgorithmsParam, Simulation
2020

2121

2222
def decide_directed_class(directed: bool):
2323
if directed:
24-
return Network
24+
return DirectedNetwork
2525
else:
2626
return BidirectionalNetwork
2727

pydistsim/gui/drawing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def draw_current_state(
366366
Automatically determines the current algorithm and draws the network accordingly. This includes a mapping of
367367
node colors to the status of the nodes, as well as the messages in the network.
368368
369-
:param sim: Simulation or Network object
369+
:param sim: Simulation or NetworkType object
370370
:param axes: matplotlib axes object
371371
:param clear: boolean to clear the axes before drawing
372372
:param tree_key: key in nodes memory (dictionary) where tree data is stored

pydistsim/network/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pydistsim.network.generator import NetworkGenerator, NetworkGeneratorException
88
from pydistsim.network.network import (
99
BidirectionalNetwork,
10-
Network,
10+
DirectedNetwork,
1111
NetworkException,
1212
NetworkType,
1313
)

pydistsim/network/generator.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from numpy.random import rand
77

88
from pydistsim.logging import logger
9-
from pydistsim.network.network import BidirectionalNetwork, Network
9+
from pydistsim.network.network import BidirectionalNetwork, DirectedNetwork
1010
from pydistsim.network.node import Node
1111
from pydistsim.network.rangenetwork import BidirectionalRangeNetwork, RangeNetwork
1212

@@ -303,7 +303,7 @@ def generate_complete_network(cls, n: int, network_type: type[T] = None, directe
303303
>>> net1 = NetworkGenerator.generate_complete_network(5)
304304
<BidirectionalNetwork object with 5 nodes and 10 edges>
305305
>>> net2 = NetworkGenerator.generate_complete_network(5, directed_network=True)
306-
<Network object with 5 nodes and 20 edges>
306+
<DirectedNetwork object with 5 nodes and 20 edges>
307307
>>> net3 = NetworkGenerator.generate_complete_network(5, network_type=BidirectionalNetwork)
308308
<BidirectionalNetwork object with 5 nodes and 10 edges>
309309
@@ -322,7 +322,7 @@ def generate_complete_network(cls, n: int, network_type: type[T] = None, directe
322322
directed_network = False
323323

324324
if network_type is None:
325-
network_type = Network if directed_network else BidirectionalNetwork
325+
network_type = DirectedNetwork if directed_network else BidirectionalNetwork
326326

327327
net = network_type()
328328
node_pos_list = cls.__get_ring_pos(n, net.environment)
@@ -349,7 +349,7 @@ def generate_ring_network(cls, n: int, network_type: type[T] = None, directed_ne
349349
>>> net = NetworkGenerator.generate_ring_network(6)
350350
<BidirectionalNetwork object with 6 nodes and 6 edges>
351351
>>> net = NetworkGenerator.generate_ring_network(6, directed_network=False)
352-
<Network object with 6 nodes and 6 edges>
352+
<DirectedNetwork object with 6 nodes and 6 edges>
353353
354354
DO NOT instantiate the class, this is a class method.
355355
@@ -366,7 +366,7 @@ def generate_ring_network(cls, n: int, network_type: type[T] = None, directed_ne
366366
directed_network = False
367367

368368
if network_type is None:
369-
network_type = Network if directed_network else BidirectionalNetwork
369+
network_type = DirectedNetwork if directed_network else BidirectionalNetwork
370370

371371
net = network_type()
372372
node_pos_list = cls.__get_ring_pos(n, net.environment)
@@ -409,7 +409,7 @@ def generate_star_network(cls, n: int, network_type: type[T] = None, directed_ne
409409
directed_network = False
410410

411411
if network_type is None:
412-
network_type = Network if directed_network else BidirectionalNetwork
412+
network_type = DirectedNetwork if directed_network else BidirectionalNetwork
413413

414414
net = network_type()
415415
node_pos_list = cls.__get_ring_pos(n - 1, net.environment)
@@ -447,7 +447,7 @@ def generate_hypercube_network(
447447
>>> net = NetworkGenerator.generate_hypercube_network(dimension=3)
448448
<BidirectionalNetwork object with 8 nodes and 12 edges>
449449
>>> net2 = NetworkGenerator.generate_hypercube_network(dimension=3, directed_network=True)
450-
<Network object with 8 nodes and 24 edges>
450+
<DirectedNetwork object with 8 nodes and 24 edges>
451451
>>> net3 = NetworkGenerator.generate_complete_network(n=8)
452452
<BidirectionalNetwork object with 8 nodes and 12 edges>
453453
@@ -477,7 +477,7 @@ def generate_hypercube_network(
477477
directed_network = False
478478

479479
if network_type is None:
480-
network_type = Network if directed_network else BidirectionalNetwork
480+
network_type = DirectedNetwork if directed_network else BidirectionalNetwork
481481

482482
LABEL_KEY = "HYPERCUBE_LABEL"
483483

@@ -616,7 +616,7 @@ def generate_mesh_network(
616616
directed_network = False
617617

618618
if network_type is None:
619-
network_type = Network if directed_network else BidirectionalNetwork
619+
network_type = DirectedNetwork if directed_network else BidirectionalNetwork
620620

621621
if a is None or b is None:
622622
if n is None:

pydistsim/network/network.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class NetworkMixin(ObserverManagerMixin, with_typehint(Graph)):
3434
"""
3535
Mixin to extend Graph and DiGraph. The result represents a network in a distributed simulation.
3636
37-
The Network classes (:class:`Network` and :class:`BidirectionalNetwork`) extend the Graph class and provides additional functionality
37+
The Network classes (:class:`DirectedNetwork` and :class:`BidirectionalNetwork`) extend the Graph class and provides additional functionality
3838
for managing nodes and network properties.
3939
4040
:param environment: The environment in which the network operates. If not provided, a new Environment instance will be created.
@@ -64,7 +64,7 @@ def __init__(
6464

6565
@staticmethod
6666
def to_directed_class():
67-
return Network
67+
return DirectedNetwork
6868

6969
@staticmethod
7070
def to_undirected_class():
@@ -269,14 +269,14 @@ def subnetwork(
269269
edges: None | Iterable[tuple[Node, Node]] = None,
270270
):
271271
"""
272-
Returns a Network instance with the specified nodes and edges.
272+
Returns a NetworkType instance with the specified nodes and edges.
273273
274274
:param nbunch: A list of nodes to include in the subnetwork.
275275
:type nbunch: list[Node]
276276
:param edges: A list of edges to include in the subnetwork. Defaults to None.
277277
:type edges: Iterable[tuple[Node, Node]], optional
278-
:return: A Network instance representing the subnetwork.
279-
:rtype: Network
278+
:return: A NetworkType instance representing the subnetwork.
279+
:rtype: NetworkType
280280
"""
281281

282282
return self.__deepcopy__({}, nodes, edges)
@@ -649,7 +649,7 @@ def validate_params(self, params: dict):
649649
assert sensor.probabilityFunction.scale == value
650650

651651

652-
class Network(NetworkMixin, DiGraph):
652+
class DirectedNetwork(NetworkMixin, DiGraph):
653653
"""
654654
A directed graph representing a network in a distributed simulation.
655655
"""
@@ -661,5 +661,5 @@ class BidirectionalNetwork(NetworkMixin, Graph):
661661
"""
662662

663663

664-
NetworkType = Network | BidirectionalNetwork
664+
NetworkType = DirectedNetwork | BidirectionalNetwork
665665
"A network in a distributed simulation."

pydistsim/network/node.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Node(ObserverManagerMixin):
4949
Represents a node in a network.
5050
5151
:param network: Optional network object to which the node belongs.
52-
:type network: Network, optional
52+
:type network: NetworkType, optional
5353
:param commRange: Communication range of the node.
5454
:type commRange: int, optional
5555
:param sensors: Tuple of sensor types or names.

pydistsim/network/rangenetwork.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pydistsim.logging import logger
99
from pydistsim.network.environment import Environment
10-
from pydistsim.network.network import BidirectionalNetwork, Network
10+
from pydistsim.network.network import BidirectionalNetwork, DirectedNetwork
1111
from pydistsim.utils.helpers import with_typehint
1212

1313
if TYPE_CHECKING:
@@ -36,7 +36,7 @@ def in_comm_range(self, network: "RangeNetworkType", node1: "Node", node2: "Node
3636
are within communication range.
3737
3838
:param network: The network in which the nodes are connected.
39-
:type network: Network
39+
:type network: RangeNetworkType
4040
:param node1: The first node.
4141
:type node1: Node
4242
:param node2: The second node.
@@ -65,7 +65,7 @@ def in_comm_range(self, network: "RangeNetworkType", node1: "Node", node2: "Node
6565
positioned so that their distance is smaller than the communication range.
6666
6767
:param network: The network in which the nodes are connected.
68-
:type network: Network
68+
:type network: RangeNetworkType
6969
:param node1: The first node.
7070
:type node1: Node
7171
:param node2: The second node.
@@ -99,7 +99,7 @@ def in_comm_range(self, network: "RangeNetworkType", node1: "Node", node2: "Node
9999
communication range.
100100
101101
:param network: The network in which the nodes are connected.
102-
:type network: Network
102+
:type network: RangeNetworkType
103103
:param node1: The first node.
104104
:type node1: Node
105105
:param node2: The second node.
@@ -129,7 +129,7 @@ def in_comm_range(self, network: "RangeNetworkType", node1: "Node", node2: "Node
129129
probability of connection.
130130
131131
:param network: The network in which the nodes are connected.
132-
:type network: Network
132+
:type network: RangeNetworkType
133133
:param node1: The first node.
134134
:type node1: Node
135135
:param node2: The second node.
@@ -147,7 +147,7 @@ def in_comm_range(self, network: "RangeNetworkType", node1: "Node", node2: "Node
147147
return False
148148

149149

150-
class RangeNetworkMixin(with_typehint(Network)):
150+
class RangeNetworkMixin(with_typehint(DirectedNetwork)):
151151
"""
152152
Mixin to define a type of network that decides which nodes are connected based on their
153153
communication range.
@@ -295,7 +295,7 @@ def modify_avg_degree(self, value):
295295
logger.trace("Modified degree to {}", self.avg_degree())
296296

297297

298-
class RangeNetwork(RangeNetworkMixin, Network):
298+
class RangeNetwork(RangeNetworkMixin, DirectedNetwork):
299299
"""
300300
Type of network that decides which nodes are connected based on their communication range.
301301

pydistsim/tests/test_network.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
BidirectionalNetwork,
99
BidirectionalRangeNetwork,
1010
CompleteRangeType,
11-
Network,
11+
DirectedNetwork,
1212
NetworkException,
1313
NetworkType,
1414
Node,

pydistsim/tests/test_npickle.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import unittest
33

44
from pydistsim.demo_algorithms.broadcast import Flood
5-
from pydistsim.network import Network, NetworkGenerator, NetworkType
5+
from pydistsim.network import DirectedNetwork, NetworkGenerator, NetworkType
66
from pydistsim.utils.npickle import read_npickle, write_npickle
77

88

@@ -23,7 +23,7 @@ def setUp(self):
2323

2424
def test_write_read(self):
2525
for i, (size, net) in enumerate(self.nets):
26-
net: Network
26+
net: DirectedNetwork
2727
with self.subTest(net=net):
2828
try:
2929
write_npickle(net, f"net_test_{i}.tar.gz")

pydistsim/tests/test_restrictions.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pydistsim.message import Message
44
from pydistsim.network import NetworkGenerator
55
from pydistsim.network.behavior import NetworkBehaviorModel
6-
from pydistsim.network.network import Network
6+
from pydistsim.network.network import DirectedNetwork
77
from pydistsim.restrictions.communication import (
88
BidirectionalLinks,
99
MessageOrdering,
@@ -81,7 +81,7 @@ def test_MessageOrdering(self):
8181
assert not MessageOrdering.check(net)
8282

8383
def test_ReciprocalCommunication(self):
84-
net = Network() # directed graph
84+
net = DirectedNetwork() # directed graph
8585
n1, n2, n3 = net.add_node(), net.add_node(), net.add_node()
8686

8787
net.add_edge(n1, n2)
@@ -217,7 +217,7 @@ def test_Connectivity(self):
217217
net = NetworkGenerator(10, enforce_connected=True).generate_random_network()
218218
assert Connectivity.check(net)
219219

220-
net = Network()
220+
net = DirectedNetwork()
221221
net.add_node()
222222
net.add_node()
223223
assert not Connectivity.check(net)
@@ -238,7 +238,7 @@ def test_UniqueInitiator(self):
238238
assert UniqueInitiator.check(net)
239239

240240
def test_CompleteGraph(self):
241-
net = Network()
241+
net = DirectedNetwork()
242242

243243
nodes = [net.add_node() for _ in range(10)]
244244
for i, n1 in enumerate(nodes):
@@ -252,7 +252,7 @@ def test_CompleteGraph(self):
252252
assert not CompleteGraph.check(net)
253253

254254
def test_CycleGraph(self):
255-
net = Network()
255+
net = DirectedNetwork()
256256
LEN = 10
257257
nodes = [net.add_node() for _ in range(LEN)]
258258
for i, n1 in enumerate(nodes):
@@ -261,7 +261,7 @@ def test_CycleGraph(self):
261261

262262
assert CycleGraph.check(net)
263263

264-
net = Network()
264+
net = DirectedNetwork()
265265
nodes = [net.add_node() for _ in range(LEN)]
266266
for i, n1 in enumerate(nodes[:-2]):
267267
n2 = nodes[(i + 1) % LEN]
@@ -270,7 +270,7 @@ def test_CycleGraph(self):
270270
assert not CycleGraph.check(net)
271271

272272
def test_TreeGraph(self):
273-
net = Network()
273+
net = DirectedNetwork()
274274
n1, n2, n3, n4, n5 = net.add_node(), net.add_node(), net.add_node(), net.add_node(), net.add_node()
275275

276276
net.add_edge(n1, n2), net.add_edge(n1, n3), net.add_edge(n2, n4), net.add_edge(n2, n5)
@@ -280,7 +280,7 @@ def test_TreeGraph(self):
280280
assert not TreeGraph.check(net)
281281

282282
def test_StarGraph(self):
283-
net = Network()
283+
net = DirectedNetwork()
284284
n1, n2, n3, n4, n5 = net.add_node(), net.add_node(), net.add_node(), net.add_node(), net.add_node()
285285

286286
net.add_edge(n1, n2), net.add_edge(n1, n3), net.add_edge(n1, n4)

0 commit comments

Comments
 (0)