Simulating distributed Quantum teleportation with SimulaQron and CQC
I was looking for a framework to simulate quantum communications for some time ago in order to be able to execute, simulate and test the protocols I am working on. One of the requirements was to be able to simulate quantum communication using several hosts (be that in the form of separate servers, virtual machines or containers). After some attempts to use a well known quantum computing framework with the (bad) trick of sending the information of the whole state of the system from one host to a second one over the network, I reached SimulaQron + CQC. And it looked very promising from the very beginning!
SimulaQron and CQC
Just a few words on the framework components, just borrowing the descriptions from the corresponding documentation pages. As you can see we are talking about two main components, SimulaQron (http://www.simulaqron.org and https://softwarequtech.github.io/SimulaQron/html/index.html) and CQC, that stands for Classical-Quantum Combiner, (https://softwarequtech.github.io/CQC-Python/index.html), both created at QUTech that is highly active in the field of quantum technologies.
SimulaQron is an application level simulator for a quantum internet that allows you to program your own quantum internet applications. Explore how to realize software for a quantum internet connecting local quantum processors by quantum communication, and develop your own libraries and software engineering concepts suitable for a quantum internet.
This Python library provides a way to program a protocol on a network where the nodes listen to instructions through the classical-quantum combiner (CQC) interface. For more information on how to use this library with SimulaQron, see https://softwarequtech.github.io/SimulaQron/html/GettingStarted.html.
As it can be seen there is a clear relation between these two components. This relation is depicted in the following figure, taken from the previously named documentation pages
This image reflects the possibilities you have to use SimulaQron from a application program: by using the native interface directly with Twisted or by using the Python or C library that make use of the CQC Interface. As recommended in the documentation we will use the last method with the Python library for the purpose of this entry.
I will not go here over the procedure to install (quite easy) the components or any other detail that can be found in the documentation pages.
Teleportation: the local case
The first thing I tried to learn how this framework works was to run the classical teleportation algorithm that is included in the framework examples in github (see below). Of course previous to execute the algorithm, you have to setup the SimulaQron virtual network. Therefore the path is clear: create and start the virtual network using SimulaQron and then execute the teleportation algorithm leveraging CQC. In this local case it is easy to find the instructions in the documentation sites, even though the network creation and algorithm execution are not presented together. Let us do it here.
For the network creation we can follow the instructions in https://softwarequtech.github.io/SimulaQron/html/ConfNodes.html#starting-the-simulaqron-backend with some trivial modification
$ simulaqron start --nodes Alice,Bob
This will start the ‘default’ virtual network replacing the original network in the configuration file, provided that you answer yes to the question
Do you want to add/replace the network 'default' in the file /usr/local/lib/python3.8/site-packages/simulaqron/config/network.json with a new network? (yes/no)
If you respond no, the process is aborted.
Note: I found some confusing behavior when using the options of the
simulaqron command which are not very well described in the documentation from my point of view.
The next step is to execute the algorithm, that you can find in https://github.com/SoftwareQuTech/CQC-Python/tree/master/examples/pythonLib/teleport, by running the run.sh script or by running the Alice and Bob python files separately (for example in separate terminals)
$ python3 aliceTest.py
$ python3 bobTest.py
What you get from Alice is
| App Alice: Measurement outcomes are: a=0, b=0 |
and for Bob
| App Bob: Measurement outcome is: 0 |
The relevant point here is that this is happening in two separate processes, and the algorithm is sending (simulated) quantum information (one of the qubits of the EPR pair) over the virtual network from one process (Alice) the the other (Bob), in addition to classical information.
Just to clarify that the algorithm is teleporting a
|+>| state, therefore the measurement in Bob will give us 0 or 1 with equal probability.
We can now stop the network
$ simulaqron stop
Teleportation: the distributed case
Let us go for the real objective of this entry. It was clear for me that the distributed case was possible as well, but the instructions for creating the distributed virtual network are not clear at all in the documentation IMHO, therefore I think it was worth to explain it here.
I will use containers in order to create the distributed environment in my laptop, but of course you can run these containers y separate systems. In order to have all the required components I created a folder and inside it I copied the Dockerfile and the same python files as before, aliceTest.py and bobTest.py with a small modification.
In order to use a SimulaQron virtual network different than the default we need to adapt the python files to include the reference to the new virtual network (that we can call newnet) and modify in the python files the line
with CQCConnection("Alice") as Alice:
to include the reference to the virtual network
with CQCConnection("Alice", network_name="newnet") as Alice:
and same for bobTest.py.
The use of a different virtual network is not required, but I think it helps to keep things clear.
The Dockerfile to create the image contains the installation of SimulaQron (that includes CQC) and the copy to the image of the python files:
$ cat Dockerfile
FROM python:3WORKDIR /usr/src/appRUN pip install --no-cache-dir simulaqronCOPY . .
For the creation and management of the images and containers I am using
podman because it is the preferred solution for my Fedora 31.
$ sudo podman build -t teleport .
STEP 1: FROM python:3
STEP 2: WORKDIR /usr/src/app
--> Using cache 9338ecb398d0faf388ce89b09f167a40828835812e3e0f88a9a6e4b2138307f5
STEP 3: RUN pip install --no-cache-dir simulaqron
Downloading simulaqron-3.0.15-py3-none-any.whl (113 kB)
|████████████████████████████████| 113 kB 10.2 MB/s
...STEP 4: COPY . .
STEP 5: COMMIT teleport
2930a892a326e89e848e4917f42016412595d239d400ea5aab32a4cf0494c7ff$ sudo podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/teleport latest 2930a892a326 4 minutes ago 1.1 GB
We can now run two containers in interactive mode from this image in separate terminals to realize our distributed teleportation algorithm. First let us create a new network for the containers that will make use of the embedded DNS and therefore we do not need to worry about IPs and we can use just hostnames (do not confuse the container networks with the SimulaQron networks).
$ sudo podman network create teleport
/etc/cni/net.d/teleport.conflist$ sudo podman network ls
NAME VERSION PLUGINS
podman 0.4.0 bridge,portmap,firewall,tuning
teleport 0.4.0 bridge,portmap,firewall,dnsname
And now we can run the containers to be able to start the SimulaQron network as well as to launch the python programs that implement the teleportation algorithm.
$ sudo podman run -it --rm --network teleport --name Alice localhost/teleport bash
Dockerfile aliceTest.py bobTest.py
and in a separate terminal
$ sudo podman run -it --rm --network teleport --name Bob localhost/teleport bash
Once the containers are running we have to create the SimulaQron network configuration in both nodes taking into account that we need to be consistent with the node names and ports.
root@cccb86e7f91f:/usr/src/app# simulaqron nodes add Alice --hostname Alice.dns.podman --app-port 8000 --cqc-port 8001 --vnode-port 8002 --network-name=”newnet” -froot@cccb86e7f91f:/usr/src/app# simulaqron nodes add Bob --hostname Bob.dns.podman --app-port 9000 --cqc-port 9001 --vnode-port 9002 --network-name="newnet" -f
We execute the same network configuration commands in both containers. Before moving on, let us examine the previous commands.
With them we create two SimulaQron nodes (Alice and Bob) in a new SimulaQron virtual network named newnet. For each of these nodes we identify the host where the node will run (hostname, taking advantage of the embedded containers DNS in the teleport container network, that use the domain dns.podman) and the ports to run the virtual network and cqc processes that must be different for each node. Finally we use the -f flag to force the writing of the config file without asking for that. Something that is not configured in the previous commands is the topology of the virtual network, that means that it will be full mesh by default. You can find more information on creating topologies in the documentation page.
We can see the configurations created in the config file, that include the default network:
root@cccb86e7f91f:/usr/src/app# cat /usr/local/lib/python3.8/site-packages/simulaqron/config/network.json
We can now start the SimulaQron virtual network in both containers (same command in both containers):
root@cccb86e7f91f:/usr/src/app# simulaqron start --nodes=Alice,Bob --name="newnet" --keep
--keepoption forces the use of the configuration created previously.
And now we can run our distributed teleportation algorithm. In Alice
root@cccb86e7f91f:/usr/src/app# python aliceTest.py
root@71b0916b25de:/usr/src/app# python bobTest.py
Once the processes are running in both containers they can communicate and execute the algorithm in a distributed form.
Alice will show something like
| App Alice: Measurement outcomes are: a=0, b=1 |
and Bob something like
| App Bob: Measurement outcome is: 1 |
Starting from here we can figure out how to simulate and test new distributed quantum network applications with the help of SimulaQron and CQC.