|
| 1 | +# SimulaQron native mode template |
| 2 | + |
| 3 | +You can use the files in this folder as a template for implementing new SimulaQron applications. |
| 4 | +Please check the comments inside the `nodeTest.py` file to learn how to modify it. |
| 5 | + |
| 6 | + |
| 7 | +# Update network configuration |
| 8 | + |
| 9 | +Additionally, this template also contains a file that you can use for defining the network: |
| 10 | +`network_config.json`. |
| 11 | + |
| 12 | +This file contains a single network, named "default". This network contains 4 nodes named |
| 13 | +"Alice", "Bob", "Charlie" and "David". |
| 14 | + |
| 15 | +Each one of those nodes defines 3 entries: |
| 16 | +* `app_socket`: The hostname and port used by other nodes to send classical messages to this node. |
| 17 | + SimulaQron applications will bind to this hostname and port to listen for classical messages coming |
| 18 | + from other nodes. |
| 19 | +* `qnodeos_socket`: The hostname and port to bind the QNodeOS server. This configuration is required |
| 20 | + when using SimulaQron's NetQASM interface. |
| 21 | +* `vnode_socket`: The hostname and port to bind SimulaQron's Virtual Node server. This server is in |
| 22 | + charge of executing the quantum simulation. Configuring this entry is required in all cases.s |
| 23 | + |
| 24 | + |
| 25 | +## Adding new nodes |
| 26 | + |
| 27 | +To add a new node named "Eva", follow these steps: |
| 28 | +1. Open the config.json file in a text editor. |
| 29 | +2. Locate the "nodes" array inside the "default" object. |
| 30 | +3. Add a new object to the "nodes" array for "Eva". The structure should match the existing nodes: |
| 31 | +```json |
| 32 | +{ |
| 33 | + "Eva": { |
| 34 | + "app_socket": ["localhost", PORT_NUMBER], |
| 35 | + "qnodeos_socket": ["localhost", PORT_NUMBER], |
| 36 | + "vnode_socket": ["localhost", PORT_NUMBER] |
| 37 | + } |
| 38 | +} |
| 39 | +``` |
| 40 | + Replace PORT_NUMBER with unique port numbers for each socket type (e.g., 8851, 8852, 8853). The result should |
| 41 | + look like: |
| 42 | +```json |
| 43 | +Copy |
| 44 | + |
| 45 | +{ |
| 46 | + "name": "default", |
| 47 | + "nodes": [ |
| 48 | + {"Alice": {...}}, |
| 49 | + {"Bob": {...}}, |
| 50 | + {"Charlie": {...}}, |
| 51 | + {"David": {...}}, |
| 52 | + { |
| 53 | + "Eva": { |
| 54 | + "app_socket": ["localhost", 8851], |
| 55 | + "qnodeos_socket": ["localhost", 8852], |
| 56 | + "vnode_socket": ["localhost", 8853] |
| 57 | + } |
| 58 | + } |
| 59 | + ], |
| 60 | + "topology": null |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +4. Save the file after making the changes. |
| 65 | + |
| 66 | + |
| 67 | +# Additional tools |
| 68 | + |
| 69 | +This folder also contains a few bash scripts you can use for executing you application. |
| 70 | + |
| 71 | + |
| 72 | +## `run.sh` |
| 73 | + |
| 74 | +This script is a helper to quickly start the SimulaQron backend for a list of specified nodes, and then |
| 75 | +start the application code for those same nodes. |
| 76 | + |
| 77 | +This script needs a small change depending on how many nodes you want to run *on the current machine*. |
| 78 | +If you open this file, you can see this content: |
| 79 | +```shell |
| 80 | +#!/usr/bin/env bash |
| 81 | + |
| 82 | +# Check if SimulaQron is already running |
| 83 | +if [ ! -f ~/.simulaqron_pids/simulaqron_network_default.pid ]; then |
| 84 | + if ! simulaqron start --nodes=Alice,Bob --network-config-file network_config.json |
| 85 | + then |
| 86 | + echo "SimulaQron could not start correctly" |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | +fi |
| 90 | + |
| 91 | + |
| 92 | +# Run the files for Alice, Bob or whatever nodes you construct |
| 93 | +python3 bobTest.py & |
| 94 | +python3 aliceTest.py |
| 95 | +``` |
| 96 | + |
| 97 | +Change the `--nodes` option of the `simulaqron start` command, with the list (separated with commas, no spaces) |
| 98 | +of nodes you want to start locally. Also, change the `python3` lines to also start all your python programs |
| 99 | +that implement the nodes. |
| 100 | + |
| 101 | +Finally, if you changed the name of the network configuration file, also reflect this change by changing |
| 102 | +the argument next to the `--network-config-file` option. |
| 103 | + |
| 104 | + |
| 105 | +## `terminate.sh` |
| 106 | + |
| 107 | +This script can be used to stop the SimulaQron backend and terminate all the applications processes |
| 108 | +that are still running. |
| 109 | + |
| 110 | + |
| 111 | +## `doNew.sh` |
| 112 | + |
| 113 | +This is ascript that you can use to start a new instance of your application from a clean state. |
| 114 | +This scrip simply invokes `terminate.sh` and `run.sh` sequentially. |
0 commit comments