Skip to content

QuNetSim Adaption to support the implementation of link layer protocol #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/benchmark_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def teleport(sender, receiver):
for i in range(10):
q1 = Qubit(sender)
sender.send_teleport(receiver.host_id, q1, await_ack=False, no_ack=True)
q2 = receiver.get_data_qubit(sender.host_id, q1.id, wait=-1)
q2 = receiver.get_qubit(sender.host_id, q1.id, wait=-1)
_ = q2.measure()


Expand Down
16 changes: 8 additions & 8 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Babel==2.9.1
backcall==0.1.0
bitstring==3.1.6
bleach==3.3.0
certifi==2019.6.16
certifi==2022.12.7
cffi==1.14.0
chardet==3.0.4
Click==7.0
Expand All @@ -23,35 +23,35 @@ docutils==0.15.2
entrypoints==0.3
eqsn==0.0.8
flake8==3.7.9
future==0.18.2
future==0.18.3
hyperlink==19.0.0
idna==2.8
imagesize==1.1.0
importlib-metadata==1.1.0
incremental==17.5.0
ipykernel==5.1.3
ipython==7.10.1
ipython==7.16.3
ipython-genutils==0.2.0
jedi==0.15.1
jeepney==0.4.3
Jinja2==2.11.3
json5==0.8.5
jsonschema==3.2.0
jupyter-client==6.1.3
jupyter-core==4.6.3
jupyter-core==4.11.2
keyring==21.2.1
kiwisolver==1.1.0
MarkupSafe==1.1.1
matplotlib==3.1.2
mccabe==0.6.1
mistune==0.8.4
mistune==2.0.3
more-itertools==8.0.0
nbconvert==5.6.1
nbformat==4.4.0
networkx==2.4
nose2==0.9.1
notebook==6.4.1
numpy==1.18.1
notebook==6.4.12
numpy==1.22.0
packaging==19.1
pandocfilters==1.4.2
parso==0.5.1
Expand Down Expand Up @@ -99,7 +99,7 @@ tornado==6.0.3
tqdm==4.46.1
traitlets==4.3.3
twine==3.1.1
Twisted==20.3.0
Twisted==22.10.0
urllib3==1.26.5
wcwidth==0.1.7
webencodings==0.5.1
Expand Down
4 changes: 2 additions & 2 deletions docs/_sources/components/host.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ The most commonly used methods for Hosts are:
* Add a classical and quantum connection to the host with id *host_id*
* :code:`get_classical(host_id, wait=N)`
* Get a classical message from sender with host_id *host_id* and wait *N* seconds for it
* :code:`get_data_qubit(host_id, wait=N)`:
* :code:`get_qubit(host_id, wait=N)`:
* Get a data qubit from sender with host_id *host_id* and wait *N* seconds for it
* :code:`get_data_qubits(host_id)`:
* :code:`get_qubits(host_id)`:
* Get all data qubits from sender with host_id *host_id*
* :code:`get_epr(host_id, q_id=q_id)`:
* Get EPR pair with qubit ID *q_id* from sender with host_id *host_id*. If *q_id=None* then get the first free EPR pair
Expand Down
4 changes: 2 additions & 2 deletions docs/_sources/examples/QKD_B92.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Bob sends Alice a classical message after the measurement and tells her whether
while received_counter < key_size:
base = randint(0,1)
# 0 means rectilinear basis and 1 means diagonal basis
qubit = bob.get_data_qubit(sender,wait = wait_time)
qubit = bob.get_qubit(sender,wait = wait_time)
if qubit is not None:
if base == 1:
qubit.H()
Expand Down Expand Up @@ -276,7 +276,7 @@ The full example is given below.
while received_counter < key_size:
base = randint(0, 1)
# 0 means rectilinear basis and 1 means diagonal basis
qubit = bob.get_data_qubit(sender, wait=wait_time)
qubit = bob.get_qubit(sender, wait=wait_time)
if qubit is not None:
if base == 1:
qubit.H()
Expand Down
6 changes: 3 additions & 3 deletions docs/_sources/examples/QKD_BB84.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ the same bit again, until the transmission works.
measurement_base = random.randint(0, 1)

# wait for the qubit
q_bit = eve.get_data_qubit(sender, wait=wait_time)
q_bit = eve.get_qubit(sender, wait=wait_time)
while q_bit is None:
q_bit = eve.get_data_qubit(sender, wait=wait_time)
q_bit = eve.get_qubit(sender, wait=wait_time)

# measure qubit in right measurement basis
if measurement_base == 1:
Expand Down Expand Up @@ -305,7 +305,7 @@ The full example is below:
# wait for the qubit
q_bit = eve.get_data_qubit(sender, wait=wait_time)
while q_bit is None:
q_bit = eve.get_data_qubit(sender, wait=wait_time)
q_bit = eve.get_qubit(sender, wait=wait_time)

# measure qubit in right measurement basis
if measurement_base == 1:
Expand Down
4 changes: 2 additions & 2 deletions docs/_sources/examples/anonymous_transfer.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Finally, we establish the behaviour of the receiver. The receiver here behaves a

print('established secret EPR')
host.add_epr(s, q, q_id=epr_id)
q = host.get_data_qubit(s, wait=10)
q = host.get_qubit(s, wait=10)
host.empty_classical()
print('Received qubit %s in the %d state' % (q.id, q.measure()))

Expand Down Expand Up @@ -142,7 +142,7 @@ Full example:

print('established secret EPR')
host.add_epr(s, q, q_id=epr_id)
q = host.get_data_qubit(s, wait=10)
q = host.get_qubit(s, wait=10)
host.empty_classical()
print('Received qubit %s in the %d state' % (q.id, q.measure()))

Expand Down
4 changes: 2 additions & 2 deletions docs/_sources/examples/packet_sniffing.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ her messages and measures her qubits.
print("Eve Received classical: %s." % alice_message.content)

for i in range(amount_to_transmit):
q = host.get_data_qubit('Alice', wait=10)
q = host.get_qubit('Alice', wait=10)
m = q.measure()
print("Eve measured: %d." % m)

Expand Down Expand Up @@ -166,7 +166,7 @@ The full example is below.
print("Eve Received classical: %s." % alice_message.content)

for i in range(amount_transmit):
q = host.get_data_qubit('Alice', wait=10)
q = host.get_qubit('Alice', wait=10)
m = q.measure()
print("Eve measured: %d." % m)

Expand Down
12 changes: 6 additions & 6 deletions docs/_sources/examples/quantum_coin_flipping.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ received and stored in *partner_qubits*.

# send and get q1 from our partner
host.send_qubit(partner_id, q1, await_ack=True)
partner_q1 = host.get_data_qubit(partner_id)
partner_q1 = host.get_qubit(partner_id)

# send and get q2 from our partner
host.send_qubit(partner_id, q2, await_ack=True)
partner_q2 = host.get_data_qubit(partner_id)
partner_q2 = host.get_qubit(partner_id)

partner_qubits[i, j, 0] = partner_q1
partner_qubits[i, j, 1] = partner_q2
Expand Down Expand Up @@ -124,7 +124,7 @@ and the host returns the quantum state :math:`\Psi_{\bar{a}_j}`.
psi_a[i, j] = partner_qubits[i, j, 1]

# The partner should send the qubit Ψ_b_j_bar back.
psi_b_bar[i, j] = host.get_data_qubit(partner_id, wait=10)
psi_b_bar[i, j] = host.get_qubit(partner_id, wait=10)

After this procedure, the host has m qubits of the state
:math:`\Psi_{\bar{b}_j}` and m qubits of :math:`\Psi_{a_j}`, for all j.
Expand Down Expand Up @@ -284,11 +284,11 @@ The full example is given below.

# send and get q1 from our partner
host.send_qubit(partner_id, q1, await_ack=True)
partner_q1 = host.get_data_qubit(partner_id)
partner_q1 = host.get_qubit(partner_id)

# send and get q2 from our partner
host.send_qubit(partner_id, q2, await_ack=True)
partner_q2 = host.get_data_qubit(partner_id)
partner_q2 = host.get_qubit(partner_id)

partner_qubits[i, j, 0] = partner_q1
partner_qubits[i, j, 1] = partner_q2
Expand Down Expand Up @@ -317,7 +317,7 @@ The full example is given below.
psi_a[i, j] = partner_qubits[i, j, 1]

# The partner should send the qubit Ψ_b_j_bar back.
psi_b_bar[i, j] = host.get_data_qubit(partner_id, wait=10)
psi_b_bar[i, j] = host.get_qubit(partner_id, wait=10)

for j in range(m):
# Send own random bits b_j to partner
Expand Down
8 changes: 4 additions & 4 deletions docs/_sources/examples/quantum_money.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ After the bank distributes the money, the customer possesses the money.
def receive_money():
for serial in range(NO_OF_SERIALS):
for bit_no in range(QUBITS_PER_MONEY):
q = host.get_data_qubit(banker, wait=10)
q = host.get_qubit(banker, wait=10)
money_qubits[serial].append(q)
print('Customer received money')

Expand Down Expand Up @@ -135,7 +135,7 @@ that there is a cheating attempt. If measurement results are correct, the bank v
print('Serial received by Bank')
serial_to_be_checked = message.content
for qubit_no in range(QUBITS_PER_MONEY):
q = host.get_data_qubit(customer, wait=10)
q = host.get_qubit(customer, wait=10)
if bank_basis[serial_to_be_checked][qubit_no] == 1:
q.H()

Expand Down Expand Up @@ -240,7 +240,7 @@ The full example is below:
print('Serial received by Bank')
serial_to_be_checked = message.content
for qubit_no in range(QUBITS_PER_MONEY):
q = host.get_data_qubit(customer, wait=10)
q = host.get_qubit(customer, wait=10)
if bank_basis[serial_to_be_checked][qubit_no] == 1:
q.H()

Expand Down Expand Up @@ -272,7 +272,7 @@ The full example is below:
def receive_money():
for serial in range(NO_OF_SERIALS):
for bit_no in range(QUBITS_PER_MONEY):
q = host.get_data_qubit(banker, wait=10)
q = host.get_qubit(banker, wait=10)
money_qubits[serial].append(q)
print('Customer received money')

Expand Down
4 changes: 2 additions & 2 deletions docs/_sources/examples/send_data.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Dean can safely access the qubit that Alice sent without having to wait.
q_id, ack_arrived = host_alice.send_qubit('Dean', q, await_ack=True)

# Get the qubit on Dean's side from Alice
q_rec = host_dean.get_data_qubit('Alice', q_id, wait=0)
q_rec = host_dean.get_qubit('Alice', q_id, wait=0)

# Ensure the qubit arrived and then measure and print the results.
if q_rec is not None:
Expand Down Expand Up @@ -133,7 +133,7 @@ The full example is below:
q_id, _ = host_alice.send_qubit('Dean', q, await_ack=True)

# Get the qubit on Dean's side from Alice
q_rec = host_dean.get_data_qubit('Alice', q_id)
q_rec = host_dean.get_qubit('Alice', q_id)

# Ensure the qubit arrived and then measure and print the results.
if q_rec is not None:
Expand Down
2 changes: 1 addition & 1 deletion docs/_sources/quick_start.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ of commands that are built into hosts, see the [Design Overview section](https:/
# Here we write the protocol code for another host.
for _ in range(5):
# Wait for a qubit from Alice for 10 seconds.
q = host.get_data_qubit(sender, wait=10)
q = host.get_qubit(sender, wait=10)
# Measure the qubit and print the result.
print('%s received a qubit in the %d state.' % (host.host_id, q.measure()))

Expand Down
14 changes: 7 additions & 7 deletions docs/components/host.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ <h1>Host<a class="headerlink" href="#host" title="Permalink to this headline">¶
</dl>
</li>
<li><dl class="simple">
<dt><code class="code docutils literal notranslate"><span class="pre">get_data_qubit(host_id,</span> <span class="pre">wait=N)</span></code>:</dt><dd><ul>
<dt><code class="code docutils literal notranslate"><span class="pre">get_qubit(host_id,</span> <span class="pre">wait=N)</span></code>:</dt><dd><ul>
<li><p>Get a data qubit from sender with host_id <em>host_id</em> and wait <em>N</em> seconds for it</p></li>
</ul>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt><code class="code docutils literal notranslate"><span class="pre">get_data_qubits(host_id)</span></code>:</dt><dd><ul>
<dt><code class="code docutils literal notranslate"><span class="pre">get_qubits(host_id)</span></code>:</dt><dd><ul>
<li><p>Get all data qubits from sender with host_id <em>host_id</em></p></li>
</ul>
</dd>
Expand Down Expand Up @@ -763,8 +763,8 @@ <h1>Host<a class="headerlink" href="#host" title="Permalink to this headline">¶
</dd></dl>

<dl class="method">
<dt id="qunetsim.components.host.Host.get_data_qubit">
<code class="sig-name descname">get_data_qubit</code><span class="sig-paren">(</span><em class="sig-param">host_id</em>, <em class="sig-param">q_id=None</em>, <em class="sig-param">wait=0</em><span class="sig-paren">)</span><a class="headerlink" href="#qunetsim.components.host.Host.get_data_qubit" title="Permalink to this definition">¶</a></dt>
<dt id="qunetsim.components.host.Host.get_qubit">
<code class="sig-name descname">get_qubit</code><span class="sig-paren">(</span><em class="sig-param">host_id</em>, <em class="sig-param">q_id=None</em>, <em class="sig-param">wait=0</em><span class="sig-paren">)</span><a class="headerlink" href="#qunetsim.components.host.Host.get_qubit" title="Permalink to this definition">¶</a></dt>
<dd><p>Gets the data qubit received from another host in the network. If qubit ID is specified,
qubit with that ID is returned, else, the last qubit received is returned.</p>
<dl class="field-list simple">
Expand All @@ -785,10 +785,10 @@ <h1>Host<a class="headerlink" href="#host" title="Permalink to this headline">¶
</dd></dl>

<dl class="method">
<dt id="qunetsim.components.host.Host.get_data_qubits">
<code class="sig-name descname">get_data_qubits</code><span class="sig-paren">(</span><em class="sig-param">host_id</em>, <em class="sig-param">remove_from_storage=False</em><span class="sig-paren">)</span><a class="headerlink" href="#qunetsim.components.host.Host.get_data_qubits" title="Permalink to this definition">¶</a></dt>
<dt id="qunetsim.components.host.Host.get_qubits">
<code class="sig-name descname">get_qubits</code><span class="sig-paren">(</span><em class="sig-param">host_id</em>, <em class="sig-param">remove_from_storage=False</em><span class="sig-paren">)</span><a class="headerlink" href="#qunetsim.components.host.Host.get_qubits" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the dictionary of data qubits stored, just for the information regarding which qubits are stored.
Optional to remove the qubits from storage like <em>get_data_qubit</em> does with <em>remove_from_storage</em> field.</p>
Optional to remove the qubits from storage like <em>get_qubit</em> does with <em>remove_from_storage</em> field.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/QKD_B92.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ <h1>Quantum Key Distribution - B92<a class="headerlink" href="#quantum-key-distr
<span class="k">while</span> <span class="n">received_counter</span> <span class="o">&lt;</span> <span class="n">key_size</span><span class="p">:</span>
<span class="n">base</span> <span class="o">=</span> <span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="c1"># 0 means rectilinear basis and 1 means diagonal basis</span>
<span class="n">qubit</span> <span class="o">=</span> <span class="n">bob</span><span class="o">.</span><span class="n">get_data_qubit</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span><span class="n">wait</span> <span class="o">=</span> <span class="n">wait_time</span><span class="p">)</span>
<span class="n">qubit</span> <span class="o">=</span> <span class="n">bob</span><span class="o">.</span><span class="n">get_qubit</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span><span class="n">wait</span> <span class="o">=</span> <span class="n">wait_time</span><span class="p">)</span>
<span class="k">if</span> <span class="n">qubit</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">if</span> <span class="n">base</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">qubit</span><span class="o">.</span><span class="n">H</span><span class="p">()</span>
Expand Down Expand Up @@ -748,7 +748,7 @@ <h1>Quantum Key Distribution - B92<a class="headerlink" href="#quantum-key-distr
<span class="k">while</span> <span class="n">received_counter</span> <span class="o">&lt;</span> <span class="n">key_size</span><span class="p">:</span>
<span class="n">base</span> <span class="o">=</span> <span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="c1"># 0 means rectilinear basis and 1 means diagonal basis</span>
<span class="n">qubit</span> <span class="o">=</span> <span class="n">bob</span><span class="o">.</span><span class="n">get_data_qubit</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="n">wait</span><span class="o">=</span><span class="n">wait_time</span><span class="p">)</span>
<span class="n">qubit</span> <span class="o">=</span> <span class="n">bob</span><span class="o">.</span><span class="n">get_qubit</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="n">wait</span><span class="o">=</span><span class="n">wait_time</span><span class="p">)</span>
<span class="k">if</span> <span class="n">qubit</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">if</span> <span class="n">base</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">qubit</span><span class="o">.</span><span class="n">H</span><span class="p">()</span>
Expand Down
Loading