Skip to content

Commit

Permalink
#5 Delete: print statements for debugging broadcasting messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mapa21 committed May 14, 2024
1 parent e68c605 commit d650edd
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions fail_stop_agreement.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"source": [
"n = 4\n",
"t = 0\n",
"round_messages = {} # contains the count for every value received {value: count} \n",
"broadcasted_messages = []\n",
"\n",
"QUESTION_MARK = \"?\"\n",
Expand All @@ -42,6 +41,7 @@
" self.input_val = input_val\n",
" self.round_messages = {}\n",
" self.output = None\n",
" self.decision_epoch = None\n",
" def __str__(self):\n",
" return f\"id: {self.id} | round_messages: {self.round_messages}\"\n",
" \n",
Expand Down Expand Up @@ -73,12 +73,6 @@
" global broadcasted_messages\n",
" broadcasting_lock.acquire()\n",
" broadcasted_messages.append(new_msg)\n",
"\n",
" print(\"id: \", process_id)\n",
" for msg in broadcasted_messages:\n",
" print(msg) \n",
" print(\"-----------------------------------\")\n",
"\n",
" broadcasting_lock.release()\n",
"\n",
"def receive(process, epoch, round, required_val=None):\n",
Expand All @@ -97,9 +91,6 @@
" num_received_messages += 1\n",
" msg.read[process.id] = True\n",
" broadcasting_lock.release()\n",
" #print(\"process(\", process.id, \") within receive round \", round, \":\", process, \" | num_received msgs: \", num_received_messages)\n",
" #if round != 3:\n",
" # break # no waiting condition on the number of received messages for round 1 and 2\n",
"\n",
"def get_majority_value(process):\n",
" for value, count in process.round_messages.items():\n",
Expand All @@ -120,7 +111,7 @@
" most_frequent_val = max(process.round_messages, key=process.round_messages.get)\n",
" \n",
" answer = most_frequent_val\n",
" number = process.round_messages.get(most_frequent_val,0)\n",
" number = process.round_messages.get(most_frequent_val, 0)\n",
" return answer, number"
]
},
Expand All @@ -136,46 +127,38 @@
" epoch = 0\n",
" while True:\n",
" epoch += 1\n",
" \n",
" broadcast(process.id, epoch, 1, current)\n",
" if not next:\n",
" receive(process, epoch, 1)\n",
" print(\"process(\", process.id, \") after receive round 1:\", process)\n",
" \n",
" receive(process, epoch, 1) \n",
" current = get_majority_value(process)\n",
" print(\"majority_value: \", current, \"after round 1, epoch: \", epoch, )\n",
"\n",
" process.round_messages.clear() # needed so that round_messages can be reused for the counts of the next round\n",
"\n",
" broadcast(process.id, epoch, 2, current)\n",
" if not next:\n",
" receive(process, epoch, 2)\n",
"\n",
" print(\"process(\", process.id, \") after round 2:\", process)\n",
"\n",
" answer, number = get_most_frequent_val(process)\n",
" print(\"most_frequent_val: \", answer)\n",
"\n",
" process.round_messages.clear()\n",
"\n",
" broadcast(process.id, epoch, 3, WAITING_MESSAGE)\n",
" if not next:\n",
" receive(process, epoch, 3, WAITING_MESSAGE)\n",
" print(\"after round 3\")\n",
" process.round_messages.clear()\n",
"\n",
" coin = quantum_coin_flip()\n",
" print(\"coin for process(\", process.id, \"): \", coin)\n",
"\n",
" if next: \n",
" break\n",
" \n",
" if number >= HALF_PLUS_ONE:\n",
" current = answer\n",
" next = True\n",
" process.decision_epoch = epoch\n",
" elif number >= 1:\n",
" current = answer\n",
" else:\n",
" current = coin\n",
" process.output = current\n",
" print(\"Decision for \", process.id, \" = \", process.output, \" | \", current)\n",
" return current"
]
},
Expand All @@ -190,7 +173,6 @@
"\n",
"for i in range(0, n):\n",
" pr = Process(i, str(i%2))\n",
" #pr = Process(i, 0)\n",
" processes.append(pr)\n",
"\n",
" thr = threading.Thread(target=agreement, args=((pr,)))\n",
Expand All @@ -202,9 +184,9 @@
"for thr in threads:\n",
" thr.join()\n",
"\n",
"print(\"****************** SOLUTION: ******************\")\n",
"print(\"******* SOLUTION: *******\")\n",
"for pr in processes:\n",
" print(\"process(\", pr.id, \") = \", pr.output)"
" print(\"process(\", pr.id, \") = \", pr.output, \" @epoch: \", pr.decision_epoch)"
]
}
],
Expand Down

0 comments on commit d650edd

Please sign in to comment.