Ejemplo n.º 1
0
 def __init__(self, *paulis):
     if len(paulis) == 1:
         single_arg = paulis[0]
         if isinstance(single_arg, str):
             paulis = [pc.Pauli(single_arg)]
         elif isinstance(single_arg, Sequence) or hasattr(single_arg, '__iter__'):
             paulis = list(map(pc.ensure_pauli, single_arg))
         else:
             paulis = list(map(pc.ensure_pauli, paulis))
     else:
         paulis = list(map(pc.ensure_pauli, paulis))
         
     # FIXME: figure out why super(list, self).__init__ doesn't work.
     list.__init__(self, paulis)
Ejemplo n.º 2
0
    def pad(self, extra_bits=0, lower_right=None):
        r"""
        Takes a PauliList, and returns a new PauliList, 
        appending ``extra_bits`` qubits, with stabilizer operators specified by
        ``lower_right``.
        
        :arg pauli_list_in: list of Pauli operators to be padded. 
        :param int extra_bits: Number of extra bits to be appended to the system.
        :param lower_right: list of `qecc.Pauli` operators, acting on `extra_bits` qubits.
        :rtype: list of :class:`qecc.Pauli` objects.
        
        Example:
        
        >>> import qecc as q
        >>> pauli_list = q.PauliList('XXX', 'YIY', 'ZZI')
        >>> pauli_list.pad(extra_bits=2, lower_right=q.PauliList('IX','ZI'))
        PauliList(i^0 XXXII, i^0 YIYII, i^0 ZZIII, i^0 IIIIX, i^0 IIIZI)

        """

        len_P = len(self)
        nq_P = len(self[0]) if len_P > 0 else 0

        if extra_bits == 0 and lower_right is None or len(lower_right) == 0:
            return PauliList(self)
        elif len(lower_right) != 0:
            extra_bits = len(lower_right[0])

        setout = PauliList(
            [pc.Pauli(pauli.op + 'I' * extra_bits) for pauli in self])

        if lower_right is None:
            setout += [pc.eye_p(nq_P + extra_bits)] * extra_bits
        else:
            setout += [pc.eye_p(nq_P) & P for P in lower_right]

        return setout
Ejemplo n.º 3
0
 def __call__(self, P):
     if self.ignore_phase:
         P = pc.Pauli(P.op)
     return P in self.S
Ejemplo n.º 4
0
 def __init__(self, S, ignore_phase=True):
     super(PauliMembershipPredicate,
           self).__init__([pc.Pauli(P.op)
                           for P in S] if ignore_phase else S)
     self.ignore_phase = ignore_phase
Ejemplo n.º 5
0
 def __init__(self, S, ignore_phase=True):
     super(PauliMembershipPredicate, self).__init__(
         map(lambda P: pc.Pauli(P.op), S) if ignore_phase else S)
     self.ignore_phase = ignore_phase