-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
32 lines (28 loc) · 1.13 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# main.py
import os
import sys
import argparse
from cirq import Circuit, Simulator
from paxos_cirq import PaxosCirq
from raft_cirq import RaftCirq
from pbft_cirq import PBFTCirq
def main():
parser = argparse.ArgumentParser(description='Universal Consensus')
parser.add_argument('--algorithm', type=str, required=True, help='Consensus algorithm (paxos, raft, pbft)')
parser.add_argument('--num_nodes', type=int, required=True, help='Number of nodes')
parser.add_argument('--num_requests', type=int, required=True, help='Number of requests')
parser.add_argument('--num_replicas', type=int, required=True, help='Number of replicas')
args = parser.parse_args()
if args.algorithm == 'paxos':
consensus = PaxosCirq(args.num_nodes, args.num_requests)
elif args.algorithm == 'raft':
consensus = RaftCirq(args.num_nodes, args.num_requests)
elif args.algorithm == 'pbft':
consensus = PBFTCirq(args.num_nodes, args.num_requests, args.num_replicas)
else:
print('Invalid algorithm')
sys.exit(1)
result = consensus.consensus()
print(result)
if __name__ == '__main__':
main()