예제 #1
0
    def from_clifford(cliff_in):
        """
        Tests an input Clifford ``cliff_in`` to determine if it is, in
        fact, a Pauli. If so, it outputs the Pauli. If not, it
        raises an error. 
        
        :arg cliff_in: Representation of Clifford operator to be converted, 
            if possible.
        :rtype: :class:`qecc.Pauli`
        
        Example:
        
        >>> import qecc as q
        >>> cliff = q.Clifford([q.Pauli('XI',2),q.Pauli('IX')], map(q.Pauli,['ZI','IZ']))
        >>> q.Pauli.from_clifford(cliff)
        i^0 ZI
        
        Converting a Pauli into a Clifford and back again will erase
        the phase:
        
        >>> import qecc as q
        >>> paul = q.Pauli('YZ',3)
        >>> cliff = paul.as_clifford()
        >>> q.Pauli.from_clifford(cliff)
        i^0 YZ
        
        """

        nq = len(cliff_in.xout)  #Determine number of qubits.
        test_ex, test_zed = elem_gens(nq)  #Get paulis to compare.
        """If the Paulis input to the Clifford are only altered in phase, then the Clifford is also a Pauli."""
        for ex_clif, zed_clif, ex_test, zed_test in zip(
                cliff_in.xout, cliff_in.zout, test_ex, test_zed):
            if ex_clif.op != ex_test.op or zed_clif.op != zed_test.op:
                raise ValueError("Clifford is not Pauli.")
            #If the Clifford is Pauli, determine which by examining operators with altered phases.
            exact = eye_p(nq)
            zedact = eye_p(nq)  #Initialize accumulators
            """If a negative sign appears on a given generator, assign a Pauli to that qubit that conjugates the generator to a minus sign, e.g. ZXZ = -X """
            for idx_x in range(nq):
                if cliff_in.xout[idx_x].ph == 2:
                    exact.op = cc.replace_one_character(exact.op, idx_x, 'Z')
            for idx_z in range(nq):
                if cliff_in.zout[idx_z].ph == 2:
                    zedact.op = cc.replace_one_character(zedact.op, idx_z, 'X')
            return Pauli((exact * zedact).op)
예제 #2
0
 def from_clifford(cliff_in):
     """
     Tests an input Clifford ``cliff_in`` to determine if it is, in
     fact, a Pauli. If so, it outputs the Pauli. If not, it
     raises an error. 
     
     :arg cliff_in: Representation of Clifford operator to be converted, 
         if possible.
     :rtype: :class:`qecc.Pauli`
     
     Example:
     
     >>> import qecc as q
     >>> cliff = q.Clifford([q.Pauli('XI',2),q.Pauli('IX')], map(q.Pauli,['ZI','IZ']))
     >>> q.Pauli.from_clifford(cliff)
     i^0 ZI
     
     Converting a Pauli into a Clifford and back again will erase
     the phase:
     
     >>> import qecc as q
     >>> paul = q.Pauli('YZ',3)
     >>> cliff = paul.as_clifford()
     >>> q.Pauli.from_clifford(cliff)
     i^0 YZ
     
     """
     
     nq=len(cliff_in.xout) #Determine number of qubits.
     test_ex,test_zed=elem_gens(nq) #Get paulis to compare.
     """If the Paulis input to the Clifford are only altered in phase, then the Clifford is also a Pauli."""
     for ex_clif,zed_clif,ex_test,zed_test in zip(cliff_in.xout, cliff_in.zout,test_ex,test_zed):
         if ex_clif.op != ex_test.op or zed_clif.op != zed_test.op:
             raise ValueError("Clifford is not Pauli.")
         #If the Clifford is Pauli, determine which by examining operators with altered phases.
         exact=eye_p(nq)
         zedact=eye_p(nq) #Initialize accumulators
         """If a negative sign appears on a given generator, assign a Pauli to that qubit that conjugates the generator to a minus sign, e.g. ZXZ = -X """
         for idx_x in range(nq):
             if cliff_in.xout[idx_x].ph==2:
                 exact.op = cc.replace_one_character(exact.op, idx_x, 'Z')
         for idx_z in range(nq):
             if cliff_in.zout[idx_z].ph==2:
                 zedact.op = cc.replace_one_character(zedact.op, idx_z, 'X')
         return Pauli((exact*zedact).op)
예제 #3
0
def embed(pauli,qubits_tpl,nq):
    """
    Takes a Pauli, defined on as many qubits as are in qubits_tpl, and acts it
    on the register specified by qubits_tpl, within a register nq long.  
    """
    new_pauli_op='I'*nq
    new_pauli_ph=pauli.ph
    for idx in range(len(qubits_tpl)):
        new_pauli_op = cc.replace_one_character(new_pauli_op, qubits_tpl[idx], pauli.op[idx])
    return Pauli(new_pauli_op,new_pauli_ph)
예제 #4
0
def embed(pauli,qubits_tpl,nq):
    """
    Takes a Pauli, defined on as many qubits as are in qubits_tpl, and acts it
    on the register specified by qubits_tpl, within a register nq long.  
    """
    new_pauli_op='I'*nq
    new_pauli_ph=pauli.ph
    for idx in range(len(qubits_tpl)):
        new_pauli_op = cc.replace_one_character(new_pauli_op, qubits_tpl[idx], pauli.op[idx])
    return Pauli(new_pauli_op,new_pauli_ph)