diff --git a/examples/pythonLib/coinflipLeader/README.txt b/examples/pythonLib/coinflipLeader/README.txt index 77795dd..6b17bec 100644 --- a/examples/pythonLib/coinflipLeader/README.txt +++ b/examples/pythonLib/coinflipLeader/README.txt @@ -2,13 +2,28 @@ ## How to run +First make sure that simulaqron is started with the nodes you'd want to include. +This can be done with for example `simulaqron start` which by default starts a network +with the nodes Alice, Bob, Charlie, David and Eve. +Note that you need to be using either the qutip or projectq backend, since single-qubit +rotations are used which are not supported in stabilizer formalism. +To change the backend do `simulaqron set backend projectq`, which of course requires projectq +to be installed (`pip install projectq`). + +In this folder there is both an example with the four nodes Alice, Bob, Charlie and David +and one where you can dynamically choose the nodes that the example uses. + +To start either of the examples do +``` +python3 fourPartyCoinFlip.py +``` +or ``` -sh $NETSIM/run/startAll.sh -./run.sh +python3 nPartyCoinFlip.py ``` -Note that you need to give the nodes a few seconds to start up after running -the first command. +When running `nPartyCoinFlip.py` fill in the names you want to use (note that these needs to +be in the current running network) and press enter when you're finished. ## Explanation diff --git a/examples/pythonLib/coinflipLeader/nPartyCoinFlip.py b/examples/pythonLib/coinflipLeader/nPartyCoinFlip.py new file mode 100644 index 0000000..b01041f --- /dev/null +++ b/examples/pythonLib/coinflipLeader/nPartyCoinFlip.py @@ -0,0 +1,33 @@ +from cqc.pythonLib_protocols.coinflip_leader import CoinflipConsensus + + +def main(): + + leaderChooser = CoinflipConsensus(arr) # Elects a leader from array that you declared + return leaderChooser.leader() + +# For 12-13-14-15 lines: After seeing "Add person" sentence, you can add person that how many person you want to add. +# After adding one person you should press "enter" and then you can continue to add person with press enter +# If you want to cancel from adding person you should press enter again +# After enter the all name that you wanted to add you should press "enter" +# 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 ... +arr = [] # Here an empty array was defined +veri = input("Add person") +while veri: + arr.append(veri) + veri = input("Add person") + + +# giving a value for each leader +d = dict() +for veri in arr: + d[veri] = 0 + +# Runs 20 rounds of leader election and prints the results. +for i in range(0, 20): + if i % 10 == 0: + print(i) + d[main()] += 1 + + +print(d)