Skip to content

Networking

QuNetSim

Maintained by tqsd

QuNetSim is a quantum-enabled network simulator that adds common quantum networking tasks like teleportation, superdense coding, sharing EPR pairs, etc.

PythonMIT
QuNetSim illustration

Resource snapshot

Category

Networking

Stars

144

Last pushed

Apr 2, 2024Updated 2y ago

Open issues

23

Quickstart

Get running in a few lines.

Quickstart
from qunetsim.components import Host, Network

network = Network.get_instance()
network.start()

alice = Host('Alice')
bob = Host('Bob')

alice.add_connection(bob.host_id)
bob.add_connection(alice.host_id)

alice.start()
bob.start()

network.add_hosts([alice, bob])

# Block Alice to wait for qubit arrive from Bob
alice.send_epr(bob.host_id, await_ack=True)
q_alice = alice.get_epr(bob.host_id)
q_bob = bob.get_epr(alice.host_id)

print("EPR is in state: %d, %d" % (q_alice.measure(), q_bob.measure()))
network.stop(True)

What it is

QuNetSim is maintained by tqsd and sits in the Networking lane of the open-source quantum map.

QuNetSim is a quantum-enabled network simulator that adds common quantum networking tasks like teleportation, superdense coding, sharing EPR pairs, etc. It commonly appears alongside projectq-framework-projectq in example workflows.

Last verified by Qtangl generator on May 27, 2026

Who it's for

Researchers and students exploring distributed quantum systems, communication protocols, and quantum internet concepts.

What you can build or learn

  • See how the project models nodes, links, and entanglement distribution.
  • Understand what a networking-oriented workflow looks like in software.
  • Compare education-focused versus research-focused networking tools.

Code samples

Examples from the repository.

Anonymous (examples/anonymous_transfer/anonymous.py)
import time
from qunetsim.components import Host
from qunetsim.components import Network
import random
from qunetsim.objects import Qubit
def distribute(host, nodes):
    # distribute=True => sender doesn't keep part of the GHZ
    host.send_ghz(nodes, distribute=True)
def sender(host, distributor, r, epr_id):
    q = host.get_ghz(distributor, wait=10)
    b = random.choice(['0', '1'])
    host.send_broadcast(b)
    if b == '1':
        q.Z()
    host.add_epr(r, q, q_id=epr_id)
    sending_qubit = Qubit(host)
    sending_qubit.X()
    print('Sending %s' % sending_qubit.id)
    # Generate EPR if none shouldn't change anything, but if there is
    # no shared entanglement between s and r, then there should
    # be a mistake in the protocol
    host.send_teleport(r, sending_qubit, generate_epr_if_none=False, await_ack=False)
    host.empty_classical()
def receiver(host, distributor, s, epr_id):
    q = host.get_ghz(distributor, wait=10)
    b = random.choice(['0', '1'])
    host.send_broadcast(b)
    messages = []
    # Await broadcast messages from all parties
    while len(messages) < 3:
        messages = host.classical
        messages = [x for x in messages if x.content != 'ACK']
        time.sleep(0.5)
    print([m.content for m in messages])
    parity = int(b)
    for m in messages:
        if m.sender != s:
            parity = parity ^ int(m.content)
    if parity == 1:
        q.Z()
Bb84 Protocol (examples/BB84/BB84_protocol.py)
# -*- coding: utf-8 -*-
import numpy as np
import binascii
from random import getrandbits
from qunetsim.components.host import Host
from qunetsim.components.network import Network
from qunetsim.objects import Qubit
from qunetsim.objects import Logger
Logger.DISABLED = True
class BB84:
    def __init__(self):
        print("Welcome to BB84 demo")
    def select_encoding(self, length):
        alice_bitstring = ""
        alice_bases = ""
        for i in range(length):
            alice_bitstring += (str(getrandbits(1)))
            alice_bases += (str(getrandbits(1)))
            # 0 means (0,1) basis and 1 means(+,-)basis
        return alice_bitstring, alice_bases
    def select_measurement(self, length):   # Bob bases
        bases = ""
        for i in range(length):
            bases += (str(getrandbits(1)))
        return bases
    def encode(self, host_sender, bitstring, bases):
        encoded_qubits = []
        for i in range(len(bitstring)):
            q = Qubit(host_sender)
            if bases[i] == "0":
                if bitstring[i] == "0":
                    pass  # initialized in 0
                elif bitstring[i] == "1":
                    q.X()
            elif bases[i] == "1":
                if bitstring[i] == "0":
                    q.H()
                elif bitstring[i] == "1":
                    q.X()
                    q.H()
Checksum (examples/checksum/checksum.py)
import time
import numpy as np
from qunetsim.components import Host
from qunetsim.components import Network
from qunetsim.objects import Logger
from qunetsim.objects import Qubit
WAIT_TIME = 10
def checksum_sender(host, q_size, receiver_id, checksum_size_per_qubit):
    bit_arr = np.random.randint(2, size=q_size)
    Logger.get_instance().log('Bit array to be sent: ' + str(bit_arr))
    qubits = []
    for i in range(q_size):
        q_tmp = Qubit(host)
        if bit_arr[i] == 1:
            q_tmp.X()
        qubits.append(q_tmp)
    check_qubits = host.add_checksum(qubits, checksum_size_per_qubit)
    checksum_size = int(q_size / checksum_size_per_qubit)
    qubits.append(check_qubits)
    checksum_cnt = 0
    for i in range(q_size + checksum_size):
        if i < q_size:
            q = qubits[i]
        else:
            q = qubits[q_size][checksum_cnt]
            checksum_cnt = checksum_cnt + 1
        host.send_qubit(receiver_id, q, await_ack=True)
def checksum_receiver(host, q_size, sender_id, checksum_size_per_qubit):
    qubits = []
    checksum_size = int(q_size / checksum_size_per_qubit)
    while len(qubits) < (q_size + checksum_size):
        q = host.get_qubit(sender_id, wait=WAIT_TIME)
        qubits.append(q)
        Logger.get_instance().log(str(host.host_id) + ': received qubit')
    checksum_qubits = []
    checksum_cnt = 0
    for i in range(len(qubits)):
        if checksum_cnt < checksum_size:
            checksum_qubits.append(qubits[q_size + i]['q'])
            checksum_cnt = checksum_cnt + 1

Plays well with

License

MIT

SPDX identifier detected from the repository metadata or license files.

Repository README

Preview from the project README.

Rendered as Markdown inside a scrollable preview. Long READMEs stay contained; expand or open on GitHub for the full document.

~206 words · about 1 min readOpen on GitHub

QuNetSim

QuNetSim Tests

QuNetSim is a quantum-enabled network simulator that adds common quantum networking tasks like teleportation, superdense coding, sharing EPR pairs, etc. With QuNetSim, one can design and test robust quantum network protocols under various network conditions.

Installation and Documentation

See https://tqsd.github.io/QuNetSim/ for documentation. To install the latest release via pip:

pip install qunetsim

Quick Start Guide

Templater

The QuNetSim pip package comes with a templater. After installing the library, simply type template and follow the instructions. A template QuNetSim example will be generated.

Quick Example

from qunetsim.components import Host, Network

network = Network.get_instance()
network.start()

alice = Host('Alice')
bob = Host('Bob')

alice.add_connection(bob.host_id)
bob.add_connection(alice.host_id)

alice.start()
bob.start()

network.add_hosts([alice, bob])

# Block Alice to wait for qubit arrive from Bob
alice.send_epr(bob.host_id, await_ack=True)
q_alice = alice.get_epr(bob.host_id)
q_bob = bob.get_epr(alice.host_id)

print("EPR is in state: %d, %d" % (q_alice.measure(), q_bob.measure()))
network.stop(True)

Contributing

Feel free to contribute by adding Github issues and pull requests. Adding test cases for any contributions is a requirement for any pull request to be merged.

Citation

@article{diadamo2020qunetsim,
  title={QuNetSim: A Software Framework for Quantum Networks},
  author={DiAdamo, Stephen and N{\"o}tzel, Janis and Zanger, Benjamin and Be{\c{s}}e, Mehmet Mert},
  journal={IEEE Transactions on Quantum Engineering},
  year={2021},
  doi={10.1109/TQE.2021.3092395}
}
Read on GitHub

Activity

Latest release

—

Watchers

9

Python support

—

Learn digest

Get monthly updates when library entries change.

Monthly digest: new library entries, updated flagships, and one editorial pick.

Related resources

Keep exploring nearby tools.

quantumlib

Cirq

Python framework for creating, editing, and running Noisy Intermediate-Scale Quantum (NISQ) circuits.

PythonApache-2.0Flagship

4,971 stars · Updated 3mo ago

open-quantum-safe

liboqs

C library for prototyping and experimenting with quantum-resistant cryptography

CMITFlagship

2,946 stars · Updated 3mo ago

XanaduAI

pennylane

PennyLane is an open-source quantum software platform for quantum computing, quantum machine learning, and quantum chemistry.

PythonApache-2.0FlagshipQtangl relevant

3,229 stars · Updated 3mo ago

QISKit

qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

PythonApache-2.0FlagshipQtangl relevant

7,412 stars · Updated 3mo ago

Microsoft

QuantumKatas

Tutorials and programming exercises for learning Q# and quantum computing

Jupyter NotebookMITFlagshipArchive

4,862 stars · Updated 2y ago

StephanieWehner

SimulaQron

Quantum Network Simulator for Application Programming

PythonBSD-3-Clause

131 stars · Updated 3mo ago