Skip to content

Commit b2d9300

Browse files
committed
Linter changes
1 parent 89972b3 commit b2d9300

File tree

14 files changed

+75
-65
lines changed

14 files changed

+75
-65
lines changed

examples/nativeMode/teleport/bobTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def remote_recover_teleport(self, a, b, virtualNum):
125125
else:
126126
ValueError(f"Unknown backend {simulaqron_settings.sim_backend}")
127127

128-
print(f"Qubit is:\n{state}")
128+
print(f"Qubit is: \n{state}")
129129

130130

131131
#####################################################################################################

simulaqron/general/host_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import socket
3131
import struct
3232
from ipaddress import IPv4Address
33-
from typing import Dict, List
33+
from typing import Dict
3434

3535
from twisted.spread import pb
3636

simulaqron/local/setup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def setup_local(myName: str, virtualNet: SocketsConfig, classicalNet: SocketsCon
8181
if myName in classicalNet.hostDict:
8282
try:
8383
nb = classicalNet.hostDict[myName]
84-
_logger.debug("LOCAL %s: Starting local classical communication server (%s: %s, %d).", myName, nb.name, nb.hostname, nb.port)
84+
_logger.debug("LOCAL %s: Starting local classical communication server (%s: %s, %d).",
85+
myName, nb.name, nb.hostname, nb.port
86+
)
8587
nb.root = lNode
8688
nb.factory = pb.PBServerFactory(nb.root)
8789
reactor.listenTCP(nb.port, nb.factory)
@@ -94,7 +96,8 @@ def setup_local(myName: str, virtualNet: SocketsConfig, classicalNet: SocketsCon
9496

9597
# Connect to the local virtual node simulating the "local" qubits
9698
node = virtualNet.hostDict[myName]
97-
_logger.debug("LOCAL %s: Connecting to local virtual node (%s: %s, %d).", myName, node.name, node.hostname, node.port)
99+
_logger.debug("LOCAL %s: Connecting to local virtual node (%s: %s, %d).", myName, node.name, node.hostname,
100+
node.port)
98101
factory = pb.PBClientFactory()
99102
reactor.connectTCP(node.hostname, node.port, factory)
100103
deferVirtual = factory.getRootObject()
@@ -104,7 +107,8 @@ def setup_local(myName: str, virtualNet: SocketsConfig, classicalNet: SocketsCon
104107
for node in classicalNet.hostDict:
105108
nb = classicalNet.hostDict[node]
106109
if nb.name != myName:
107-
_logger.debug("LOCAL %s: Making classical connection to %s (%s: %s, %d).", myName, nb.name, nb.name, nb.hostname, nb.port)
110+
_logger.debug("LOCAL %s: Making classical connection to %s (%s: %s, %d).", myName, nb.name, nb.name,
111+
nb.hostname, nb.port)
108112
nb.factory = pb.PBClientFactory()
109113
reactor.connectTCP(nb.hostname, nb.port, nb.factory)
110114
dList.append(nb.factory.getRootObject())

simulaqron/sdk/socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(
3333
self._use_callbacks = use_callbacks
3434
self._network_name = network_name
3535

36-
self._logger = get_netqasm_logger(f"{self.__class__.__name__}(L:{app_name} <-> R:{remote_app_name})")
36+
self._logger = get_netqasm_logger(f"{self.__class__.__name__}(L: {app_name} <-> R: {remote_app_name})")
3737
self._timeout = timeout
3838
# We define _app_socket as None as a default value, so the __del__ method
3939
# does not fail when the socket could not be connected correctly.

simulaqron/settings/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from .network_config import NetworkConfigBuilder, DEFAULT_SIMULAQRON_NETWORK_FILENAME, LOCAL_NETWORK_SETTINGS, HOME_NETWORK_SETTINGS
2-
from .simulaqron_config import SimulaqronConfig, DEFAULT_SIMULAQRON_SETTINGS_FILENAME, LOCAL_SIMULAQRON_SETTINGS, HOME_SIMULAQRON_SETTINGS
1+
from .network_config import (NetworkConfigBuilder, DEFAULT_SIMULAQRON_NETWORK_FILENAME,
2+
LOCAL_NETWORK_SETTINGS, HOME_NETWORK_SETTINGS)
3+
from .simulaqron_config import (SimulaqronConfig, DEFAULT_SIMULAQRON_SETTINGS_FILENAME,
4+
LOCAL_SIMULAQRON_SETTINGS, HOME_SIMULAQRON_SETTINGS)
35
from ._serialization import init_serialization
46

57
init_serialization()
@@ -12,4 +14,4 @@
1214
# Centralized way to store the config of the network. It reads the local
1315
# configuration if exists, otherwise, it simply populates the in-memory
1416
# configs object with the default values
15-
network_config = NetworkConfigBuilder.load_from_known_sources()
17+
network_config = NetworkConfigBuilder.load_from_known_sources()

simulaqron/settings/_serialization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,14 @@ def network_config_serializer(obj: NetworkConfig) -> Dict[str, Any]:
107107
nodes_dict = {
108108
"name" : obj.name,
109109
"nodes": [
110-
{ node_cfg.name: JSONSerializer.serialize(node_cfg) }
110+
{node_cfg.name: JSONSerializer.serialize(node_cfg)}
111111
for node_cfg in obj.nodes.values()
112112
],
113113
"topology": JSONSerializer.serialize(obj.topology)
114114
}
115115
return JSONSerializer.serialize(nodes_dict)
116116

117+
117118
@JSONSerializer.register_deserializer(NetworkConfig)
118119
def network_config_deserializer(cls: Type[NetworkConfig], obj: Dict[str, Any]) -> NetworkConfig:
119120
net_cfg = cls(obj["name"])

simulaqron/settings/network_config.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from os import PathLike
99
from pathlib import Path
1010
from typing import Optional, Self, Dict, List, Tuple, Any
11+
1112
from dataclasses_serialization.json import JSONSerializer, JSONSerializerMixin
1213

1314
import simulaqron._default_config
@@ -60,10 +61,12 @@ def get_config(self, config_type: str | NodeConfigType) -> Tuple[str, int]:
6061
def __eq__(self, other) -> bool:
6162
if not isinstance(other, NodeConfig):
6263
return False
63-
return (self.name == other.name and self.app_port == other.app_port and
64-
self.qnodeos_port == other.qnodeos_port and self.vnode_port == other.vnode_port and
65-
self.app_hostname == other.app_hostname and self.qnodeos_hostname == other.qnodeos_hostname and
66-
self.vnode_hostname == other.vnode_hostname)
64+
names_equal = self.name == other.name
65+
app_sockets_equal = self.app_hostname == other.app_hostname and self.app_port == other.app_port
66+
qnos_sockets_equal = self.qnodeos_hostname == other.qnodeos_hostname and self.qnodeos_port == other.qnodeos_port
67+
vnode_sockets_equal = self.vnode_hostname == other.vnode_hostname and self.vnode_port == other.vnode_port
68+
69+
return names_equal and app_sockets_equal and qnos_sockets_equal and vnode_sockets_equal
6770

6871

6972
@dataclass
@@ -156,6 +159,7 @@ def __eq__(self, other) -> bool:
156159
nodes_are_equal = [this_node == other_node for this_node, other_node in zip(self.nodes, other.nodes)]
157160
return self.name == other.name and self.topology == other.topology and all(nodes_are_equal)
158161

162+
159163
@dataclass
160164
class NetworkConfigBuilder(JSONSerializerMixin):
161165
"""

simulaqron/simulaqron.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from daemons.prefab import run
1010

1111
from simulaqron.network import Network
12-
from simulaqron.settings import simulaqron_settings, network_config
1312
from simulaqron.settings import LOCAL_SIMULAQRON_SETTINGS, LOCAL_NETWORK_SETTINGS, HOME_NETWORK_SETTINGS
13+
from simulaqron.settings import simulaqron_settings, network_config
1414
from simulaqron.settings.network_config import NodeConfig, DEFAULT_SIMULAQRON_NETWORK_FILENAME
1515
from simulaqron.settings.simulaqron_config import SimBackend
1616

@@ -29,6 +29,7 @@ class RunningSimulaQronDaemon(run.RunDaemon):
2929
This class is useful to stop the already-running daemons without needed to read all
3030
the required configurations.
3131
"""
32+
3233
def __init__(self, pidfile: Path):
3334
assert pidfile is not None
3435
super().__init__(pidfile=pidfile)
@@ -74,8 +75,8 @@ def version():
7475
@cli.command()
7576
@click.option(
7677
"--network-config-file",
77-
help=f"Use the given network config file. Defaults to the file named '{DEFAULT_SIMULAQRON_NETWORK_FILENAME}' "
78-
f"on the current directory.",
78+
help=f"Use the given network config file. Defaults to the file named " # noqa: E131
79+
f"'{DEFAULT_SIMULAQRON_NETWORK_FILENAME}' on the current directory.", # noqa: E131
7980
type=click.Path(exists=True, dir_okay=False, resolve_path=True, path_type=Path),
8081
default=LOCAL_NETWORK_SETTINGS
8182
)
@@ -109,9 +110,9 @@ def start(name: str, nrnodes: int, nodes: str, network_config_file: Path):
109110
logging.warning("The pidfile for this network is located at %s", pidfile)
110111
return
111112
nodes = nodes.split(",")
112-
if len(nodes) <=0:
113-
print(f"WARNING - The list of nodes to start is empty. If you specified the --nrnodes option "
114-
f"this can be normal. Please check your invocation line if needed.")
113+
if len(nodes) <= 0:
114+
print("WARNING - The list of nodes to start is empty. If you specified the --nrnodes option "
115+
"this can be normal. Please check your invocation line if needed.")
115116
if nrnodes > 0 and len(nodes) < nrnodes:
116117
nodes += [f"Node{i}" for i in range(nrnodes - len(nodes))]
117118
d = SimulaQronDaemon(pidfile=pidfile, name=name, nodes=nodes)
@@ -381,9 +382,9 @@ def get():
381382
def sim_backend():
382383
if LOCAL_SIMULAQRON_SETTINGS.exists() and LOCAL_SIMULAQRON_SETTINGS.is_file():
383384
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
384-
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}':")
385+
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}'")
385386
else:
386-
print(f"Configuration from default configuration:")
387+
print("Configuration from default configuration")
387388
simulaqron_settings.default_settings()
388389
print(simulaqron_settings.sim_backend)
389390

@@ -394,9 +395,9 @@ def sim_backend():
394395
def max_qubits():
395396
if LOCAL_SIMULAQRON_SETTINGS.exists() and LOCAL_SIMULAQRON_SETTINGS.is_file():
396397
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
397-
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}':")
398+
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}'")
398399
else:
399-
print(f"Configuration from default configuration:")
400+
print("Configuration from default configuration")
400401
simulaqron_settings.default_settings()
401402
print(simulaqron_settings.max_qubits)
402403

@@ -407,9 +408,9 @@ def max_qubits():
407408
def max_registers():
408409
if LOCAL_SIMULAQRON_SETTINGS.exists() and LOCAL_SIMULAQRON_SETTINGS.is_file():
409410
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
410-
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}':")
411+
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}'")
411412
else:
412-
print(f"Configuration from default configuration:")
413+
print("Configuration from default configuration")
413414
simulaqron_settings.default_settings()
414415
print(simulaqron_settings.max_registers)
415416

@@ -420,9 +421,9 @@ def max_registers():
420421
def conn_retry_time():
421422
if LOCAL_SIMULAQRON_SETTINGS.exists() and LOCAL_SIMULAQRON_SETTINGS.is_file():
422423
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
423-
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}':")
424+
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}'")
424425
else:
425-
print(f"Configuration from default configuration:")
426+
print("Configuration from default configuration")
426427
simulaqron_settings.default_settings()
427428
print(simulaqron_settings.conn_retry_time)
428429

@@ -433,9 +434,9 @@ def conn_retry_time():
433434
def recv_timeout():
434435
if LOCAL_SIMULAQRON_SETTINGS.exists() and LOCAL_SIMULAQRON_SETTINGS.is_file():
435436
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
436-
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}':")
437+
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}'")
437438
else:
438-
print(f"Configuration from default configuration:")
439+
print("Configuration from default configuration")
439440
simulaqron_settings.default_settings()
440441
print(simulaqron_settings.recv_timeout)
441442

@@ -446,9 +447,9 @@ def recv_timeout():
446447
def recv_retry_time():
447448
if LOCAL_SIMULAQRON_SETTINGS.exists() and LOCAL_SIMULAQRON_SETTINGS.is_file():
448449
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
449-
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}':")
450+
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}'")
450451
else:
451-
print(f"Configuration from default configuration:")
452+
print("Configuration from default configuration")
452453
simulaqron_settings.default_settings()
453454
print(simulaqron_settings.recv_retry_time)
454455

@@ -459,9 +460,9 @@ def recv_retry_time():
459460
def log_level():
460461
if LOCAL_SIMULAQRON_SETTINGS.exists() and LOCAL_SIMULAQRON_SETTINGS.is_file():
461462
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
462-
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}':")
463+
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}'")
463464
else:
464-
print(f"Configuration from default configuration:")
465+
print("Configuration from default configuration")
465466
simulaqron_settings.default_settings()
466467
print(simulaqron_settings.log_level)
467468

@@ -472,9 +473,9 @@ def log_level():
472473
def noisy_qubits():
473474
if LOCAL_SIMULAQRON_SETTINGS.exists() and LOCAL_SIMULAQRON_SETTINGS.is_file():
474475
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
475-
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}':")
476+
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}'")
476477
else:
477-
print(f"Configuration from default configuration:")
478+
print("Configuration from default configuration")
478479
simulaqron_settings.default_settings()
479480
if simulaqron_settings.noisy_qubits:
480481
print("on")
@@ -488,9 +489,9 @@ def noisy_qubits():
488489
def t1():
489490
if LOCAL_SIMULAQRON_SETTINGS.exists() and LOCAL_SIMULAQRON_SETTINGS.is_file():
490491
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
491-
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}':")
492+
print(f"Configuration loaded from file: '{LOCAL_SIMULAQRON_SETTINGS}'")
492493
else:
493-
print(f"Configuration from default configuration:")
494+
print("Configuration from default configuration")
494495
simulaqron_settings.default_settings()
495496
print(simulaqron_settings.t1)
496497

@@ -531,8 +532,8 @@ def nodes():
531532
help="The neighbors of the node in the network separated by ',' (no space).\n \
532533
For example '--neighbors Bob,Charlie,David'.\n \
533534
If not specified all current nodes in the network will be neighbors.")
534-
def add(name: str, network_name: str, hostname: str , app_port: int, qnodeos_port: int,
535-
vnode_port: int, neighbors: Optional[str]=None):
535+
def add(name: str, network_name: str, hostname: str, app_port: int, qnodeos_port: int,
536+
vnode_port: int, neighbors: Optional[str] = None):
536537
"""
537538
Add a node to the network.
538539
@@ -545,13 +546,13 @@ def add(name: str, network_name: str, hostname: str , app_port: int, qnodeos_por
545546
neighbors = [neighbor.strip() for neighbor in neighbors]
546547
network_config.read_from_file(LOCAL_NETWORK_SETTINGS)
547548
network_config.add_node(node_name=name, network_name=network_name,
548-
app_hostname=hostname, qnodeos_hostname=hostname, vnode_hostname=hostname,
549-
app_port=app_port, qnodeos_port=qnodeos_port, vnode_port=vnode_port,
550-
neighbors=neighbors)
549+
app_hostname=hostname, qnodeos_hostname=hostname, vnode_hostname=hostname,
550+
app_port=app_port, qnodeos_port=qnodeos_port, vnode_port=vnode_port,
551+
neighbors=neighbors)
551552
network_config.write_to_file(LOCAL_NETWORK_SETTINGS)
552553
added_node: NodeConfig = network_config.get_nodes(network_name=network_name)[name]
553554
print(f"Node with name '{added_node.name}' was added to the network with name '{network_name}'.\n"
554-
f"Socket addresses are:\n"
555+
"Socket addresses are: \n"
555556
f"* App/Classical: '({added_node.app_hostname}, {added_node.app_port})\n"
556557
f"* QNodeOS: '({added_node.qnodeos_hostname}, {added_node.qnodeos_port})\n"
557558
f"* Virtual Node: '({added_node.vnode_hostname}, {added_node.vnode_port})\n")

tests/quick/engine/test_project_q_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TestProjectQEnginInit:
2020
def test_init(self):
2121
eng = ProjectQEngine("Alice", 0)
2222
assert eng.maxQubits == 10
23-
assert eng.activeQubits== 0
23+
assert eng.activeQubits == 0
2424
assert len(eng.qubitReg) == 0
2525

2626
eng = ProjectQEngine("Alice", 0, 5)

tests/quick/general/test_host_config.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def _assert_results(app_conf: SocketsConfig, qnodeos_conf: SocketsConfig, vnode_
3131
@pytest.mark.skip(reason="Reading network config from legacy format files is not implemented yet")
3232
def test_load_legacy_net_config_file(self):
3333
this_file_folder = Path(__file__).parent
34-
sockets_config_path = this_file_folder / "resources" / "sockets.cfg"
35-
qnodeos_config_path = this_file_folder / "resources" / "qnodeos.cfg"
36-
virtual_config_path = this_file_folder / "resources" / "virtual.cfg"
34+
sockets_config_path = this_file_folder / "resources" / "sockets.cfg"
35+
qnodeos_config_path = this_file_folder / "resources" / "qnodeos.cfg"
36+
virtual_config_path = this_file_folder / "resources" / "virtual.cfg"
3737
network_config.read_from_legacy_files(app_file_path=sockets_config_path,
3838
qnodeos_config_path=qnodeos_config_path,
3939
virtual_config_path=virtual_config_path)
@@ -44,7 +44,6 @@ def test_load_legacy_net_config_file(self):
4444

4545
TestSocketsConfig._assert_results(app_conf, qnodeos_conf, vnode_conf)
4646

47-
4847
def test_load_new_net_config_file(self):
4948
this_file_folder = Path(__file__).parent
5049
network_config_path = this_file_folder / "resources" / "network.json"

0 commit comments

Comments
 (0)