Skip to content

Commit 4eec441

Browse files
committed
Update "configure nodes" documentation and fix bugs in CLI client to match the documentation
1 parent 096c084 commit 4eec441

4 files changed

Lines changed: 34 additions & 17 deletions

File tree

docs/ConfNodes.rst

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
Configuring the simulated network
2-
=================================
1+
SimulaQron Configuration
2+
========================
33

44
SimulaQron uses two configuration files:
55

66
* ``simulaqron_network.json`` — defines nodes, their socket ports, and network topology (described on this page)
77
* ``simulaqron_settings.json`` — configures the simulation backend, timeouts, and other settings
88
(see the Settings section in `Getting Started <GettingStarted.rst>`_)
99

10-
-------------------------------------------
10+
-------------------------------------
1111
Running all nodes on a single machine
12-
-------------------------------------------
12+
-------------------------------------
1313

1414
When developing and testing, you typically run all simulated nodes on one computer.
1515
In this case, all sockets use ``localhost`` and you just need distinct port numbers for each node.
1616

17-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
^^^^^^^^^^^^^^^^^^^^^^^^
1818
Using the SimulaQron CLI
19-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
^^^^^^^^^^^^^^^^^^^^^^^^
2020

2121
The ``simulaqron`` command manages the backend for you. To start a network with nodes Alice and Bob::
2222

@@ -36,8 +36,9 @@ If something went wrong (e.g. the process was killed) and SimulaQron thinks the
3636

3737
The ``simulaqron start`` command accepts these arguments:
3838

39-
* ``--nodes <nodes_list>`` (**required**): Comma-separated list of node names to start. These must exist in
40-
the network configuration file.
39+
* ``--nodes <nodes_list>`` (optional): Comma-separated list of node names to start. These must exist in
40+
the network configuration file. If not given, SimulaQron will start all the defined nodes in
41+
``simulaqron_network.json``.
4142
* ``--simulaqron-config-file=PATH`` (optional): Path to a SimulaQron settings file. Defaults to
4243
``simulaqron_settings.json`` in the current folder.
4344
* ``--network-config-file=PATH`` (optional): Path to a network configuration file. Defaults to
@@ -48,9 +49,9 @@ The ``simulaqron start`` command accepts these arguments:
4849
.. warning:: ``simulaqron start`` will fail if any of the ports specified in the config files are already in
4950
use by a running SimulaQron network or another program.
5051

51-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5253
Using per-example run scripts
53-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5455

5556
Each example in ``examples/new-sdk/`` and ``examples/nativeMode/`` includes a ``run.sh`` script that starts
5657
the SimulaQron backend and launches the node programs. This is the easiest way to try an example::
@@ -61,9 +62,9 @@ the SimulaQron backend and launches the node programs. This is the easiest way t
6162
The ``run.sh`` script reads the ``simulaqron_network.json`` and ``simulaqron_settings.json`` in the example
6263
directory, so each example is self-contained.
6364

64-
-------------------------------------------
65+
----------------------------------
6566
Running nodes on separate machines
66-
-------------------------------------------
67+
----------------------------------
6768

6869
To simulate a real distributed quantum network, you can run each node on a different physical computer.
6970
In this case, you need to:
@@ -120,9 +121,16 @@ For each node, you specify IP and port for three sockets:
120121
* ``qnodeos_socket`` — connection to the QNodeOS server that interprets NetQASM subroutines
121122
* ``vnode_socket`` — connection to the SimulaQron VirtualNode that runs the quantum simulation
122123

123-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124+
You can easily copy the default network configuration by using the simulaqron CLI command::
125+
126+
simulaqron nodes default
127+
128+
This will create a ``simulaqron_network.json`` file in the current folder with 5 nodes: `Alice`,
129+
`Bob`, `Charlie`, `David` and `Eve`.
130+
131+
^^^^^^^^^^^^^^^^^^^^^^^^^^
124132
Using the CLI to add nodes
125-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
133+
^^^^^^^^^^^^^^^^^^^^^^^^^^
126134

127135
You can build up a network incrementally using the CLI::
128136

@@ -140,9 +148,9 @@ You can also specify explicit hostnames and ports:
140148
* ``--vnode-port``
141149
* ``--neighbors``
142150

143-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144152
Writing the JSON config manually
145-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
153+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146154

147155
For more complex setups, write the ``simulaqron_network.json`` file directly.
148156
Here is an example with two networks ("default" and "small_network")::

docs/GettingStarted.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ implement using simulaqron.
246246
.. note:: Settings needs to be set before starting the SimulaQron backend. If the backend is already running, stop
247247
it, set the settings and start it again.
248248

249+
It is also possible to create the default SimulaQron network configuration in the current folder. Check the
250+
`Configuring the Network <ConfNodes.rst>`_ document to check how to achieve this.
251+
249252
^^^^^^^^^^^^^^^^^^^
250253
Settings precedence
251254
^^^^^^^^^^^^^^^^^^^

simulaqron/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def add(name: str, network_name: str, hostname: str, app_port: int, qnodeos_port
721721
app_port=app_port, qnodeos_port=qnodeos_port, vnode_port=vnode_port,
722722
neighbors=neighbors)
723723
network_config.write_to_file(LOCAL_NETWORK_SETTINGS)
724-
added_node: NodeConfig = network_config.get_nodes(network_name=network_name)[name]
724+
added_node: NodeConfig = network_config[network_name][name]
725725
click.echo(f"Node with name '{added_node.name}' was added to the network with name '{network_name}'.\n"
726726
"Socket addresses are: \n"
727727
f"* App/Classical: '({added_node.app_hostname}, {added_node.app_port})\n"

simulaqron/settings/network_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ def __eq__(self, other) -> bool:
170170
nodes_are_equal = [this_node == other_node for this_node, other_node in zip(self.nodes, other.nodes)]
171171
return self.name == other.name and self.topology == other.topology and all(nodes_are_equal)
172172

173+
def __getitem__(self, item: str) -> NodeConfig | None:
174+
for node_name, node_cfg in self.nodes.items():
175+
if node_name == item:
176+
return node_cfg
177+
return None
178+
173179

174180
@dataclass
175181
class NetworksConfiguration(JSONSerializerMixin):

0 commit comments

Comments
 (0)