Example #1
0
def SwapTest(qB,qC):
    qA=create_qubits(1)
    qA=qA[0]
    H | qA
    Cswap(qA,qB,qC)
    H | qA
    return ns.qubits.qubitapi.measure(qA,observable=Z)
Example #2
0
def OneWayFunction(identity=None,symkey=[],randomSerialNumber=0,Money=0):
    owf_key=''
    
    # covert inputs to binary
    for i in symkey:
        owf_key+=str(bin(i)[2:])
    owf_key+=str(bin(randomSerialNumber)[2:])
    owf_key+=str(bin(Money)[2:]) 
    owf_key=int(owf_key)
    
    # make it qubit
    # apply three big prime numbers
    p1 = 33179
    p2 = 32537
    p3 = 31259
    
    MyRx=create_rotation_op(np.pi/180*(owf_key%p1), (1, 0, 0))
    MyRy=create_rotation_op(np.pi/180*(owf_key%p2), (0, 1, 0))
    MyRz=create_rotation_op(np.pi/180*(owf_key%p3), (0, 0, 1))
    
    tempQubit=create_qubits(1)
    tempQubit=tempQubit[0]
    MyRx | tempQubit
    MyRy | tempQubit
    MyRz | tempQubit
    
    #print(tempQubit.qstate.dm)
    return tempQubit
 def start(self):
     super().start()
     self.qList = create_qubits(self.num_bits,system_name="Q")
     self.my_memory.put(self.qList) 
     
     
     My_waitENVtype = EventType("WAIT_EVENT", "Wait for N nanoseconds")
     self._schedule_after(self.delay, My_waitENVtype) # self.delay
     self._wait_once(ns.EventHandler(self.popMem),entity=self
         ,event_type=My_waitENVtype) # can't add event_type
def Creat_EPR():
    # creat qubits
    q0, q1 = create_qubits(2) #qubit 00
    # entangle the two
    # do Hadmard transform
    ns.qubits.operate(q0, ns.H)
    # do cnot operation
    ns.qubits.operate([q0,q1], ns.CNOT) 
   
    return q0,q1 
Example #5
0
def Create_multiEPR(num_bits):
    qListA = []
    qListB = []
    for i in range(num_bits):
        qA, qB = create_qubits(2)  # qubit 00
        ns.qubits.operate(qA, ns.H)
        ns.qubits.operate([qA, qB], ns.CNOT)
        qListA.append(qA)
        qListB.append(qB)
    return qListA, qListB
Example #6
0
def Create_GHZ_set_list(num_qubits,num_sets):
    qList_2D=[]
    
    for i in range(num_qubits):
        qList = create_qubits(num_sets) #qubit 000
        H | qList[0]
        tmp=[qList[0]]
        for j in range(1, num_sets):
            ns.qubits.operate([qList[0],qList[j]], ns.CNOT)
            tmp.append(qList[j])

        qList_2D.append(tmp)

    return qList_2D
Example #7
0
def QBitCorrection(Qlist1,Qlist2,Qlist3):
    ret=[]
    for q1,q2,q3 in zip(Qlist1,Qlist2,Qlist3):
        Qlist=[q1,q2,q3]
    
    
        # Qlist
        # get Error Syndrome
        ErrorSyndromeLen=len(Qlist)-1
        ES_Qlist=create_qubits(ErrorSyndromeLen)
        #print(ES_Qlist)
        mes=[]
        for i in range(ErrorSyndromeLen):
            ns.qubits.operate([Qlist[i],ES_Qlist[i]], ns.CNOT) 
            ns.qubits.operate([Qlist[i+1],ES_Qlist[i]], ns.CNOT) 
            mes.append(ns.qubits.qubitapi.measure(ES_Qlist[i],observable=Z)[0])#
        #print(mes)


        # get Qlist idea from Error Syndrome
        res=[True]*len(Qlist)
        ind=True
        for i in range(len(mes)):
            if mes[i]==1:
                ind= not ind
                res[i+1]=ind
            else:
                res[i+1]=ind

        # count false cases
        F_count=0
        for i in res:
            if i ==False:
                F_count+=1

        # correct qubits
        if 2*F_count>len(mes): # case that false is more than true, than false might be the correct ones.
            for i in range(len(res)):
                if res[i] == True:
                    X|Qlist[i]
        else:
            for i in range(len(res)):
                if res[i] == False:
                    X|Qlist[i]
        
        ret.append(Qlist[0])
    
    return ret
Example #8
0
def Create_random_qubits(num_bits):
    res_state=[]
    qlist=[]
    qlist=create_qubits(num_bits) 
    for i in range(0,num_bits):
        res_state.append(randint(0,3)) # in four states
    for a,b in zip(res_state, qlist):
        if   a == 0: # 0 state
            pass
        elif a == 1: # 1 state    #X
            X | b
        elif a == 2: # + state    #H
            H | b
        elif a == 3: # - state    #XH
            X | b
            H | b
        else :
            print("Create random bits ERROR!!")
    return res_state, qlist
Example #9
0
def Create_random_qubits(num_bits):
    res_state = []
    qlist = []
    qlist = create_qubits(num_bits, system_name="Q")
    for i in range(0, num_bits):
        res_state.append(randint(0, 3))
    for a, b in zip(res_state, qlist):
        if a == 0:  # 0 state
            #print("0",b.qstate.dm)
            pass
        elif a == 1:  # 1 state    #X
            X | b
            #print("1",b.qstate.dm)
        elif a == 2:  # + state    #H
            H | b
            #print("+",b.qstate.dm)
        elif a == 3:  # - state    #XH
            X | b
            H | b
            #print("-",b.qstate.dm)
        else:
            print("Create random bits ERROR!!")
    return res_state, qlist
Example #10
0
            for i in range(len(res)):
                if res[i] == False:
                    X|Qlist[i]
        
        ret.append(Qlist[0])
    
    return ret
    


# In[ ]:


#Verify

qlist1=create_qubits(7)
qlist2=create_qubits(7)
qlist3=create_qubits(7)


#X|qlist1[5]
X|qlist2[5]
X|qlist3[5]
#X|qlist[0]
#X|qlist[2]
#X|qlist[1]

for i in qlist1:
    print(ns.qubits.qubitapi.measure(i,observable=Z))

print("--------")
        
        
        # Alice starts======================================================
        self.QT_Alice_EPRGen_sendQubits()






# In[16]:


# Test
ns.sim_reset()
q=create_qubits(1)
q=q[0]
H|q
Z|q

print("origin: \n",q.qstate.dm)
myQT=QuantumTeleportation(q,10**-6)
ns.sim_run()
    





# In[ ]: