SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from projectq.ops import All, CNOT, H, Measure, Rz, X, Z
  2.     from projectq import MainEngine
  3.     from projectq.meta import Dagger, Control
  4.     from cqc.pythonLib import CQCConnection, qubit
  5.     import simulaqron
  6.  
  7. def main():
  8.  
  9.     with CQCConnection("Alice") as Alice:
  10.         eng = MainEngine()
  11.         c1, c2 = create_bell_pair(eng)
  12.         tel1 = eng.allocate_qubit()
  13.         Alice.sendQubit((c1, "Bob"))
  14.         H | tel1
  15.         CNOT | (tel1, c2)
  16.         H | tel1
  17.         Measure | tel1
  18.         Measure | c2
  19.         to_print = "App {}: Measurement outcomes are: a={}, b={}".format(Alice.name, int(tel1), int(c2))
  20.         print("|" + "-" * (len(to_print) + 2) + "|")
  21.         print("| " + to_print + " |")
  22.         print("|" + "-" * (len(to_print) + 2) + "|")
  23.  
  24.         # Send corrections to Bob
  25.         Alice.sendClassical("Bob", int(tel1), int(c2))
  26.  
  27.  
  28. def create_bell_pair(eng):
  29.     b1 = eng.allocate_qubit()
  30.     b2 = eng.allocate_qubit()
  31.  
  32.     H | b1
  33.     CNOT | (b1, b2)
  34.  
  35.     return b1, b2
  36.  
  37. main()    
  38.  
  39. // new file for bob
  40. from projectq.ops import All, CNOT, H, Measure, Rz, X, Z
  41. from projectq import MainEngine
  42. from projectq.meta import Dagger, Control
  43. from cqc.pythonLib import CQCConnection, qubit
  44. import simulaqron
  45.  
  46. #####################################################################################################
  47. #
  48. # main
  49. #
  50. def main():
  51.  
  52.         # Initialize the connection
  53.         with CQCConnection("Bob") as Bob:
  54.  
  55.             # Make an EPR pair with Alice
  56.             qB=Bob.recvQubit(c1, "Alice")
  57.  
  58.             # Receive info about corrections
  59.             data=Bob.recvClassical()
  60.             message=list(data)
  61.             a=message[0]
  62.             b=message[1]
  63.  
  64.             # Apply corrections
  65.             if b==1:
  66.                     X | qB
  67.             if a==1:
  68.                     Z | qB
  69.  
  70.             # Measure qubit
  71.             Measure | qB
  72.             to_print="App {}: Measurement outcome is:  {}".format(Bob.name,int(qB))
  73.             print("|"+"-"*(len(to_print)+2)+"|")
  74.             print("| "+to_print+" |")
  75.             print("|"+"-"*(len(to_print)+2)+"|")
  76.  
  77. ##################################################################################################
  78. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top