Skip to content

Commit 6ce16d1

Browse files
author
Axel Dahlberg
authored
Merge pull request #11 from SoftwareQuTech/npartcoinflip
Npartcoinflip
2 parents 5255895 + 5fcdac9 commit 6ce16d1

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

examples/pythonLib/coinflipLeader/README.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22

33
## How to run
44

5+
First make sure that simulaqron is started with the nodes you'd want to include.
6+
This can be done with for example `simulaqron start` which by default starts a network
7+
with the nodes Alice, Bob, Charlie, David and Eve.
8+
Note that you need to be using either the qutip or projectq backend, since single-qubit
9+
rotations are used which are not supported in stabilizer formalism.
10+
To change the backend do `simulaqron set backend projectq`, which of course requires projectq
11+
to be installed (`pip install projectq`).
12+
13+
In this folder there is both an example with the four nodes Alice, Bob, Charlie and David
14+
and one where you can dynamically choose the nodes that the example uses.
15+
16+
To start either of the examples do
17+
```
18+
python3 fourPartyCoinFlip.py
19+
```
20+
or
521
```
6-
sh $NETSIM/run/startAll.sh
7-
./run.sh
22+
python3 nPartyCoinFlip.py
823
```
924

10-
Note that you need to give the nodes a few seconds to start up after running
11-
the first command.
25+
When running `nPartyCoinFlip.py` fill in the names you want to use (note that these needs to
26+
be in the current running network) and press enter when you're finished.
1227

1328
## Explanation
1429

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from cqc.pythonLib_protocols.coinflip_leader import CoinflipConsensus
2+
3+
4+
def main():
5+
6+
leaderChooser = CoinflipConsensus(arr) # Elects a leader from array that you declared
7+
return leaderChooser.leader()
8+
9+
# For 12-13-14-15 lines: After seeing "Add person" sentence, you can add person that how many person you want to add.
10+
# After adding one person you should press "enter" and then you can continue to add person with press enter
11+
# If you want to cancel from adding person you should press enter again
12+
# After enter the all name that you wanted to add you should press "enter"
13+
# Note that: you should use name from cqc's names space such as Alice, Bob, David, Eve Charlie.., you cant't use name randomly such as Gozde, Axel ...
14+
arr = [] # Here an empty array was defined
15+
veri = input("Add person")
16+
while veri:
17+
arr.append(veri)
18+
veri = input("Add person")
19+
20+
21+
# giving a value for each leader
22+
d = dict()
23+
for veri in arr:
24+
d[veri] = 0
25+
26+
# Runs 20 rounds of leader election and prints the results.
27+
for i in range(0, 20):
28+
if i % 10 == 0:
29+
print(i)
30+
d[main()] += 1
31+
32+
33+
print(d)

0 commit comments

Comments
 (0)