Skip to content

Commit d697397

Browse files
committed
Update corrRNG example code and documentation after comments
1 parent 54489a2 commit d697397

3 files changed

Lines changed: 32 additions & 25 deletions

File tree

docs/new-sdk/CorrRNG.rst

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ quantum entanglement. Found in ``examples/new-sdk/corrRNG/``.
77
The protocol
88
------------
99

10-
1. Alice creates an EPR pair (two maximally entangled qubits) with Bob.
11-
2. Both Alice and Bob measure their respective qubits.
12-
3. Because the qubits are entangled, both measurements yield the same random bit.
10+
1. Alice creates an EPR pair (two maximally entangled qubits ``A`` and ``B``) with Bob:
1311

14-
The state before measurement is:
12+
.. math:: |\Phi^{+}\rangle = = \frac{1}{\sqrt{2}} \left(|0\rangle_A |0\rangle_B + |1\rangle_A |1\rangle_B\right)
1513

16-
.. math:: |\Psi\rangle_{AB} = \frac{1}{\sqrt{2}} \left(|0\rangle_A |0\rangle_B + |1\rangle_A |1\rangle_B\right)
14+
2. Both Alice and Bob measure their respective qubits.
15+
3. Because the qubits are entangled, both measurements yield the same random bit.
1716

1817
Alice's code
1918
------------
@@ -28,19 +27,19 @@ From ``aliceTest.py``::
2827
sim_conn = NetQASMConnection(this_node_name, epr_sockets=[epr_socket])
2928

3029
# Create an entangled qubit
31-
epr = epr_socket.create_keep()[0]
30+
A = epr_socket.create_keep()[0]
3231

3332
# And simply measure it
34-
m1 = epr.measure()
33+
a = A.measure()
3534

3635
# flush() executes all queued quantum operations and makes measurement
37-
# results available. Before flush(), m1 is just a future/promise.
36+
# results available. Before flush(), a is just a future/promise.
3837
sim_conn.flush()
3938

4039
# int(m) extracts the measurement outcome — only valid after flush().
41-
m1_val = int(m1)
40+
a_val = int(a)
4241
sim_conn.close()
43-
return m1_val
42+
return a_val
4443

4544
Bob's code
4645
----------
@@ -50,17 +49,25 @@ the rest of the code is analogous to Alice's::
5049

5150
def run_bob(this_node_name: str, remote_node_name: str) -> int:
5251
epr_socket = EPRSocket(remote_node_name)
52+
53+
# sim_conn is our connection to the quantum backend (SimulaQron), not to Alice.
54+
# Alice is reached via EPRSocket for quantum and reader/writer for classical.
5355
sim_conn = NetQASMConnection(this_node_name, epr_sockets=[epr_socket])
5456

55-
# Receive an entangled qubit (Alice created the pair)
56-
epr = epr_socket.recv_keep()[0]
57+
# Receive an entangled qubit
58+
B = epr_socket.recv_keep()[0]
5759

58-
m1 = epr.measure()
60+
# And simply measure it
61+
b = B.measure()
62+
63+
# flush() executes all queued quantum operations and makes measurement
64+
# results available. Before flush(), b is just a future/promise.
5965
sim_conn.flush()
6066

61-
m1_val = int(m1)
67+
# int(m) extracts the measurement outcome — only valid after flush().
68+
b_val = int(b)
6269
sim_conn.close()
63-
return m1_val
70+
return b_val
6471

6572
Key concepts
6673
------------

examples/new-sdk/corrRNG/aliceTest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ def run_alice(this_node_name: str, remote_node_name: str) -> int:
2323
sim_conn = NetQASMConnection(this_node_name, epr_sockets=[epr_socket])
2424

2525
# Create an entangled qubit
26-
epr = epr_socket.create_keep()[0]
26+
A = epr_socket.create_keep()[0]
2727

2828
# And simply measure it
29-
m1 = epr.measure()
29+
a = A.measure()
3030

3131
# flush() executes all queued quantum operations and makes measurement
32-
# results available. Before flush(), m1 is just a future/promise.
32+
# results available. Before flush(), a is just a future/promise.
3333
sim_conn.flush()
3434

3535
# int(m) extracts the measurement outcome — only valid after flush().
36-
m1_val = int(m1)
36+
a_val = int(a)
3737
sim_conn.close()
38-
return m1_val
38+
return a_val
3939

4040

4141
if __name__ == "__main__":

examples/new-sdk/corrRNG/bobTest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ def run_bob(this_node_name: str, remote_node_name: str) -> int:
2323
sim_conn = NetQASMConnection(this_node_name, epr_sockets=[epr_socket])
2424

2525
# Receive an entangled qubit
26-
epr = epr_socket.recv_keep()[0]
26+
B = epr_socket.recv_keep()[0]
2727

2828
# And simply measure it
29-
m1 = epr.measure()
29+
b = B.measure()
3030

3131
# flush() executes all queued quantum operations and makes measurement
32-
# results available. Before flush(), m1 is just a future/promise.
32+
# results available. Before flush(), b is just a future/promise.
3333
sim_conn.flush()
3434

3535
# int(m) extracts the measurement outcome — only valid after flush().
36-
m1_val = int(m1)
36+
b_val = int(b)
3737
sim_conn.close()
38-
return m1_val
38+
return b_val
3939

4040

4141
if __name__ == "__main__":

0 commit comments

Comments
 (0)