Skip to content

Commit 47f41aa

Browse files
committed
Update documentation of the simulaqron.general package
1 parent eea7cdf commit 47f41aa

3 files changed

Lines changed: 50 additions & 15 deletions

File tree

docs/simulaqron.general.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ simulaqron.general.host_config module
1313
:show-inheritance:
1414

1515

16+
simulaqron.general.errors module
17+
-------------------------------------
18+
19+
.. automodule:: simulaqron.general.errors
20+
:members:
21+
:undoc-members:
22+
:show-inheritance:
23+
24+
1625
Module contents
1726
---------------
1827

simulaqron/general/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
class SimUnsupportedError(RuntimeError):
2+
"""
3+
Raised when the SimulaQron does not support the configured simulation backend.
4+
Check :py:class:`NodeConfigType` enum for valid values of the simulation backend.
5+
"""
26
pass

simulaqron/general/host_config.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@
4040
class Host(pb.Referenceable):
4141
def __init__(self, name: str, hostname: str, port: int):
4242
"""
43-
Initialize the details of the host. For now, we just keep the following:
44-
45-
name informal name of the host (e.g. Alice)
46-
hostname name of the node on the network (e.g. localhost or yournode.qutech.nl)
47-
port port number on hostname
43+
Class representing a host that runs a SimulaQron Virtual Node. It holds the following information:
44+
45+
:param name: Informal name of the host (e.g. Alice)
46+
:type name: str
47+
:param hostname: Name of the node on the network (e.g. localhost or yournode.qutech.nl)
48+
:type hostname: str
49+
:param port: Port number on hostname
50+
:type port: int
4851
"""
4952

5053
self.name = name
@@ -57,7 +60,7 @@ def __init__(self, name: str, hostname: str, port: int):
5760
self.family = addr[0]
5861
self.addr = addr
5962

60-
self.ip = node_id_from_addrinfo(addr)
63+
self.ip = _node_id_from_addrinfo(addr)
6164

6265
# Connection identifiers used after connected
6366
self.factory = 0
@@ -67,14 +70,24 @@ def __init__(self, name: str, hostname: str, port: int):
6770

6871
class SocketsConfig(pb.Referenceable):
6972
def __init__(self, nets_config: NetworksConfiguration, network_name: str = "default",
70-
config_type: str | NodeConfigType = "vnode"):
73+
config_type: NodeConfigType | str = "vnode"):
7174
"""
72-
Initialize by reading in the configuration file.
75+
Structure used to hold the sockets configuration for a particular component.
7376
7477
With version 4.0.0, we use the already in-memory information to create the SocketsConfig object.
7578
This avoids reading the file multiple times, which might have been updated by other processes
7679
in between reads. Additionally, this also simplifies the code, and reduces the potential source
7780
of bugs in the configuration read/write code.
81+
82+
:param nets_config: :py:class:`NetworksConfiguration` object, containing the loaded ``simulaqron_network.json``
83+
file.
84+
:type nets_config: NetworksConfiguration
85+
:param network_name: The name of the network to use. This name must exist in the loaded network
86+
configuration object.
87+
:type network_name: str
88+
:param config_type: The type of configuration to use. Valid values are instances of the
89+
:py:class:`NodeConfigType` enum, or the string that represent each of those values.
90+
:type config_type: NodeConfigType | str
7891
"""
7992
# Dictionary where we will keep host details, indexed by node name (e.g. Alice)
8093
self.hostDict: Dict[str, Host] = {}
@@ -94,9 +107,9 @@ def filter(self, nodes_to_keep: List[str]):
94107
Filter the loaded sockets configurations to only contain the given names.
95108
If a given node name is not found in the loaded one, it will simply be ignored
96109
from the exclusion process (i.e. it will not break the process)
97-
Args:
98-
nodes_to_keep: List[str]
99-
The node names to keep after filtering.
110+
111+
:param nodes_to_keep: The node names to keep after filtering.
112+
:type nodes_to_keep: List[str]
100113
"""
101114
nodes_kept = {}
102115
for node_name in self.hostDict.keys():
@@ -105,25 +118,34 @@ def filter(self, nodes_to_keep: List[str]):
105118
self.hostDict = nodes_kept
106119

107120

108-
def node_id(fam: socket.AddressFamily, ip: str) -> int:
121+
def _node_id(fam: socket.AddressFamily, ip: str) -> int:
109122
if fam == socket.AF_INET:
110123
return struct.unpack("!L", IPv4Address(ip).packed)[0]
111124
else:
112125
raise ValueError("No IPv6 yet :(")
113126

114127

115-
def node_id_from_addrinfo(
128+
def _node_id_from_addrinfo(
116129
addr: tuple[socket.AddressFamily, socket.SocketKind, int, str, tuple[str, int]]
117130
) -> int:
118131
fam = addr[0]
119132
sockaddr = addr[4]
120133
ip = sockaddr[0]
121-
return node_id(fam, ip)
134+
return _node_id(fam, ip)
122135

123136

124137
def get_node_id_from_net_config(net_config: SocketsConfig, node_name: str) -> int:
125138
"""
126-
NOTE node ID is the index of the node name of a sorted list of all the node names in the network.
139+
Gets the node ID from the given sockets config and node name.
140+
141+
.. note:: node ID is the index of the node name of a sorted list of all the node names in the network.
142+
143+
:param net_config: SocketsConfig object.
144+
:type net_config: SocketsConfig
145+
:param node_name: The name of the node to get the node ID from.
146+
:type node_name: str
147+
:return: The node ID from the given sockets config and node name.
148+
:rtype: int
127149
"""
128150
if node_name not in net_config.hostDict:
129151
raise ValueError(f"node name {node_name} not in host_dict ({net_config.hostDict.keys()})")

0 commit comments

Comments
 (0)