|
1 | | -# Public Quantum Network |
| 1 | +# PQN Stack |
2 | 2 |
|
3 | | -Software for Public Quantum Network nodes. |
| 3 | +**Software stack for Public Quantum Network (PQN) nodes** |
4 | 4 |
|
5 | | -## Development Instructions |
| 5 | +[](https://opensource.org/licenses/MIT) |
| 6 | +[](https://www.python.org/downloads/) |
6 | 7 |
|
7 | | -1. Install [uv](https://docs.astral.sh/uv/), which will handle project management |
| 8 | +A distributed node based approach to quantum networks. This repository hosts all the code necessary to make nodes of the PQN function (except for the frontend located [here](https://github.com/PublicQuantumNetwork/pqn-gui)). |
8 | 9 |
|
9 | | -1. Clone and navigate into this repository |
10 | 10 |
|
11 | | -1. Install the dependencies and set up the virtual environment 🏗️ |
| 11 | +<p align="center"> |
| 12 | + <img src="docs/images/frontend_screenshot.png" alt="PQN Web Interface" width="800"/> |
| 13 | + <br> |
| 14 | + <em>PQN web interface for public interaction with a quantum network</em> |
| 15 | +</p> |
12 | 16 |
|
13 | | - ```sh |
14 | | - uv sync |
15 | | - ``` |
| 17 | +> [!WARNING] |
| 18 | +> **Early Development**: This package is in early stages of development. APIs, installation procedures, and distribution methods are subject to change. Use in production environments is not recommended at this time. |
16 | 19 |
|
17 | | -1. Run the code 🚀 |
| 20 | +## Node Architecture |
18 | 21 |
|
19 | | - ```sh |
20 | | - uv run pqn |
21 | | - ``` |
| 22 | +<p align="center"> |
| 23 | + <img src="docs/images/network_architecture.png" alt="PQN Node Architecture" width="800"/> |
| 24 | + <br> |
| 25 | + <em>PQN web interface for monitoring and controlling quantum network nodes</em> |
| 26 | +</p> |
22 | 27 |
|
23 | | -### Project Management |
| 28 | +Our Node is composed of multiple components. All components inside a node are part of an in internal intranet with no external world access except for quantum links to other hardware or the _Node API_. |
24 | 29 |
|
25 | | -A few of the most useful uv commands are shown below. |
26 | | -See the [uv project guide](https://docs.astral.sh/uv/guides/projects) for more information about working on projects with uv. |
| 30 | +* **Node API**: FastAPI based, handles communications with web-ui as well as Node to Node communication. Only component in a Node than can talk to other components and the outside world. Resides in [src/pqnstack/app/main.py](https://github.com/PublicQuantumNetwork/pqn-stack/blob/master/src/pqnstack/app/main.py). |
| 31 | +* **Lightweight Web UI**: Designed for the general public to be able to interact with quantum networks. Resides in its own repository [here](https://github.com/PublicQuantumNetwork/pqn-gui). |
| 32 | +* **Router**: Routes messages between _Hardware Providers_, PQN developers and _Node APIs_. Uses ZMQ sockets to communicate between machines. Resides in [src/pqnstack/network/router.py](https://github.com/PublicQuantumNetwork/pqn-stack/blob/master/src/pqnstack/network/router.py). |
| 33 | +* **Hardware Provider**: Hosts hardware resources that are provided to whoever needs them inside a Node through the use of ProxyInstruments. Resides in [src/pqnstack/network/instrument_provider.py](https://github.com/PublicQuantumNetwork/pqn-stack/blob/master/src/pqnstack/network/instrument_provider.py). |
27 | 34 |
|
28 | | -- `uv add` -- Add dependencies to the project |
29 | | -- `uv remove` -- Remove dependencies from the project |
30 | | -- `uv sync` -- Update the project's environment |
31 | | -- `uv run` -- Run a command or script |
| 35 | +## Quick Start |
32 | 36 |
|
33 | | -> [!IMPORTANT] |
34 | | -> Instead of `pip install <package>`, use `uv add <package>`. |
| 37 | +> [!NOTE] |
| 38 | +> **Hardware Requirements**: To do anything interesting with this software currently requires real quantum hardware components (TimeTagger, rotators, etc.). We are actively working on fully simulated hardware components to enable single-machine demos without physical devices, but this capability is not yet available. |
35 | 39 |
|
36 | | -### Scripts |
| 40 | +### Prerequisites |
37 | 41 |
|
38 | | -To run your code, or a command that is aware of your project environment, use the following command: |
| 42 | +- Python 3.12 or higher |
| 43 | +- [uv](https://docs.astral.sh/uv/) package manager |
| 44 | +- Quantum hardware components (TimeTagger, compatible instruments) |
39 | 45 |
|
40 | | -- `uv run` -- Run a command or script |
| 46 | +### Installation |
41 | 47 |
|
42 | | -See the [script documentation](https://docs.astral.sh/uv/guides/scripts/) for more information. |
| 48 | +1. **Clone the repository** |
43 | 49 |
|
44 | | -### Linting and Formatting |
| 50 | + ```bash |
| 51 | + git clone https://github.com/PublicQuantumNetwork/pqn-stack.git |
| 52 | + cd pqn-stack |
| 53 | + ``` |
45 | 54 |
|
46 | | -Use [Ruff](https://docs.astral.sh/ruff/) to lint and format your code. |
47 | | -It is already specified as a development dependency in this template's `pyproject.toml`, and is automatically installed when you run `uv sync`. |
| 55 | +2. **Install dependencies** |
48 | 56 |
|
49 | | -You can run the linter with `uv run ruff check` (use the `--fix` flag to apply fixes), and the formatter with `uv run ruff format`. |
50 | | -There are many options available to customize which linting rules are applied. |
51 | | -All rules are enabled by default, and I have disabled a few redundant ones as a starting point in the `pyproject.toml`. |
52 | | -Feel free to modify the list as needed for your project. |
53 | | -See the [documentation](https://docs.astral.sh/ruff/tutorial/) or command help output for additional information. |
| 57 | + ```bash |
| 58 | + uv sync |
| 59 | + |
| 60 | + # Or sync with the --extra flag to run the full node |
| 61 | + uv sync --extra webapp |
| 62 | + ``` |
54 | 63 |
|
55 | | -### Type Checking |
| 64 | +### Starting a Node |
56 | 65 |
|
57 | | -Use [mypy](https://www.mypy-lang.org/) for type checking: `uv run mypy`. |
| 66 | +To fully start a PQN Node, you need to initialize 4 different processes: |
58 | 67 |
|
59 | | -### Testing |
| 68 | +* **Node API** |
| 69 | +* **Router** |
| 70 | +* **Hardware provider** (optional) |
| 71 | +* **Web GUI** (optional) |
60 | 72 |
|
61 | | -Use [pytest](https://docs.pytest.org/en/stable/) to run tests: |
| 73 | +### Node API |
62 | 74 |
|
63 | | -- `uv run pytest` |
64 | | -- Use `uv run pytest --cov` to check code coverage. |
| 75 | +#### Config file |
65 | 76 |
|
66 | | -### Alternate Manual Setup |
| 77 | +Before starting a Node API, you need to set up a configuration file: |
| 78 | + |
| 79 | +1. **Copy the example configuration:** |
| 80 | + ```bash |
| 81 | + cp configs/config_app_example.toml config.toml |
| 82 | + ``` |
67 | 83 |
|
68 | | -If it is not possible to use uv for installation, there is a workaround using `virtualenv` and `pip`. |
| 84 | +2. **Edit the configuration:** |
| 85 | + Open `config.toml` in your editor and replace the placeholder values with your actual settings (router addresses, instrument names, etc.). |
69 | 86 |
|
70 | 87 | > [!IMPORTANT] |
71 | | -> This method is intended as a workaround **only** for situations where uv is not available, and **only for local installations** rather than for active project development. |
| 88 | +> The configuration file **must** be named `config.toml` and placed at the root of the repository. If you use a different name or location, the API will not be able to find it. |
72 | 89 |
|
73 | | -From the root directory of the repository: |
| 90 | +#### Run the FastAPI instance |
| 91 | +For a quick run you can simply run to get started: |
74 | 92 |
|
75 | | -1. Create the virtual environment |
| 93 | +```bash |
| 94 | + uv run fastapi run src/pqnstack/app/main.py |
| 95 | +``` |
76 | 96 |
|
77 | | - ```sh |
78 | | - virtualenv .venv |
79 | | - ``` |
| 97 | +Please take a look at the [FastAPI docs](https://fastapi.tiangolo.com/deployment/) for more options on how to run the API |
80 | 98 |
|
81 | | -1. Activate the virtual environment |
| 99 | +### Router and Hardware Provider |
82 | 100 |
|
83 | | - ```sh |
84 | | - source .venv/bin/activate |
85 | | - ``` |
| 101 | +Both the Router and Hardware Provider can be configured in two ways: |
86 | 102 |
|
87 | | -1. Install the project dependencies |
| 103 | +1. **Using CLI flags** - Pass configuration directly as command-line arguments |
| 104 | +2. **Using a config file** - Use the `--config` flag with a path to a TOML configuration file (see example in [configs/config_messaging_example.toml](https://github.com/PublicQuantumNetwork/pqn-stack/blob/master/configs/config_messaging_example.toml)) |
88 | 105 |
|
89 | | - ```sh |
90 | | - pip install -e . |
91 | | - ``` |
| 106 | +The config file can contain settings for both router and provider: |
| 107 | +- Router settings go under `[router]` |
| 108 | +- Provider settings go under `[provider]` with instruments defined as `[[provider.instruments]]` |
92 | 109 |
|
93 | | -1. Run the code |
| 110 | +Command-line arguments override config file settings. |
94 | 111 |
|
95 | | - ```sh |
96 | | - pqn |
97 | | - ``` |
| 112 | +#### Starting the Router |
| 113 | + |
| 114 | +```bash |
| 115 | +# Using CLI flags |
| 116 | +uv run pqn start-router --name router1 --host localhost --port 5555 |
| 117 | + |
| 118 | +# Using a config file |
| 119 | +uv run pqn start-router --config configs/config_messaging_example.toml |
| 120 | +``` |
| 121 | + |
| 122 | +#### Starting an Instrument Provider |
| 123 | + |
| 124 | +```bash |
| 125 | +# Using a config file (recommended for defining instruments) |
| 126 | +uv run pqn start-provider --config configs/config_messaging_example.toml |
98 | 127 |
|
99 | | -### Possible Problems |
| 128 | +# Using CLI flags with inline JSON for instruments |
| 129 | +uv run pqn start-provider \ |
| 130 | + --name provider1 \ |
| 131 | + --router-name router1 \ |
| 132 | + --instruments '{"dummy1": {"import": "pqnstack.pqn.drivers.dummies.DummyInstrument", "desc": "Test Instrument", "hw_address": "123456"}}' |
| 133 | +``` |
100 | 134 |
|
101 | | -What to try if things don't seem to be working: |
| 135 | +### Web GUI |
102 | 136 |
|
103 | | -- Remove the `.venv/` directory and try again ♻️ |
| 137 | +For instructions on how install and start the web GUI please see the repo where it lives at [https://github.com/PublicQuantumNetwork/pqn-gui](https://github.com/PublicQuantumNetwork/pqn-gui) |
0 commit comments