예제 #1
0
    def as_qcircuit(self, C=None, R=None):
        r"""
        Typesets this circuit using the `Qcircuit`_ package for
        :math:`\text{\LaTeX}`.
        
        :param float C: Width (in ems) of each column.
        :param float R: Height (in ems) of each column.
        :rtype: :obj:`str`
        :returns: A string containing :math:`\text{\LaTeX}` source code for use
            with `Qcircuit`_.
        
        .. _Qcircuit: http://www.cquic.org/Qcircuit/
        """

        trans_cells = []
        for timestep in self.group_by_time():
            col = [r'\qw'] * self.nq  # If nothing else, place a \qw.
            hidden_qubits = set()

            for loc in timestep:
                if any(qubit in hidden_qubits
                       for qubit in range(min(loc.qubits),
                                          max(loc.qubits) + 1)):
                    # A qubit is hidden, so append and reset.
                    trans_cells.append(col)
                    col = [r'\qw'] * self.nq  # If nothing else, place a \qw.
                    hidden_qubits = set()

                if loc.wt == 1:
                    col[loc.qubits[0]] = r"\gate{{{0}}}".format(
                        loc.kind if loc.kind != "I" else r"\id")
                elif loc.kind == 'CNOT':
                    col[loc.qubits[0]] = r'\ctrl{{{0}}}'.format(loc.qubits[1] -
                                                                loc.qubits[0])
                    col[loc.qubits[1]] = r'\targ'
                else:
                    raise NotImplementedError(
                        "Location kind {0.kind} not supported by this method.".
                        format(loc))

                hidden_qubits.update(
                    range(min(loc.qubits),
                          max(loc.qubits) + 1))

            trans_cells.append(col)

        cells = u.transpose([[''] * self.nq] + trans_cells +
                            [[r'\qw'] * self.nq])

        return r"""
        \Qcircuit {C} {R} {{
            {0}
        }}
        """.format(u.latex_array_contents(cells),
                   C="@C{}em".format(C) if C is not None else "",
                   R="@R{}em".format(R) if R is not None else "")
예제 #2
0
    def as_qcircuit(self, C=None, R=None):
        r"""
        Typesets this circuit using the `Qcircuit`_ package for
        :math:`\text{\LaTeX}`.
        
        :param float C: Width (in ems) of each column.
        :param float R: Height (in ems) of each column.
        :rtype: :obj:`str`
        :returns: A string containing :math:`\text{\LaTeX}` source code for use
            with `Qcircuit`_.
        
        .. _Qcircuit: http://www.cquic.org/Qcircuit/
        """
             
        trans_cells = []
        for timestep in self.group_by_time():
            col = [r'\qw'] * self.nq # If nothing else, place a \qw.
            hidden_qubits = set()
            
            for loc in timestep:
                if any(qubit in hidden_qubits for qubit in range(min(loc.qubits), max(loc.qubits)+1)):
                    # A qubit is hidden, so append and reset.
                    trans_cells.append(col)
                    col = [r'\qw'] * self.nq # If nothing else, place a \qw.
                    hidden_qubits = set()
                    
                if loc.wt == 1:
                    col[loc.qubits[0]] = r"\gate{{{0}}}".format(loc.kind if loc.kind != "I" else r"\id")
                elif loc.kind == 'CNOT':
                    col[loc.qubits[0]] = r'\ctrl{{{0}}}'.format(loc.qubits[1] - loc.qubits[0])
                    col[loc.qubits[1]] = r'\targ'
                else:
                    raise NotImplementedError("Location kind {0.kind} not supported by this method.".format(loc))

                hidden_qubits.update(range(min(loc.qubits), max(loc.qubits)+1))
                
            trans_cells.append(col)
            
        cells = u.transpose([[''] * self.nq] + trans_cells + [[r'\qw'] * self.nq])
        
        return r"""
        \Qcircuit {C} {R} {{
            {0}
        }}
        """.format(u.latex_array_contents(cells),
            C="@C{}em".format(C) if C is not None else "",
            R="@R{}em".format(R) if R is not None else ""
        )
예제 #3
0
    def recovery_circuit_as_qcircuit(self, C=None, R=None):
        """
        Returns the recovery operator (as specified by
        :meth:`syndromes_and_recovery_operators`), expressed as a `Qcircuit`_
        array.
        
        :param float C: Width (in ems) of each column.
        :param float R: Height (in ems) of each column.
        
        .. _Qcircuit: http://www.cquic.org/Qcircuit/
        """
        nq_data = self.nq
        nq_anc = nq_data - self.nq_logical
        nq = nq_data + nq_anc

        # Put a blank line of array cells coming into the circuit.
        trans_cells = [[""] * nq]

        for bitstring, recovery_gate in self.syndromes_and_recovery_operators(
        ):
            trans_cells.append(
                # Data register
                [
                    r"\gate{{{}}} {}".format(P if P != "I" else r"\id",
                                             "\qwx" if idx != 0 else "")
                    for idx, P in enumerate(recovery_gate.op)
                ] +
                # Ancilla register
                [(r"\controlo" if bit == 0 else r"\control") + r" \cw \cwx"
                 for bit in bitstring])

        trans_cells.append([r"\qw"] * nq_data + [r"\cw"] * nq_anc)

        # FIXME: consolidate this with Circuit.as_qcircuit().
        return r"""
        \Qcircuit  {C} {R} {{
            {0}
        }}
        """.format(u.latex_array_contents(u.transpose(trans_cells)),
                   C="@C{}em".format(C) if C is not None else "",
                   R="@R{}em".format(R) if R is not None else "")
예제 #4
0
 def recovery_circuit_as_qcircuit(self, C=None, R=None):
     """
     Returns the recovery operator (as specified by
     :meth:`syndromes_and_recovery_operators`), expressed as a `Qcircuit`_
     array.
     
     :param float C: Width (in ems) of each column.
     :param float R: Height (in ems) of each column.
     
     .. _Qcircuit: http://www.cquic.org/Qcircuit/
     """
     nq_data = self.nq
     nq_anc = nq_data - self.nq_logical
     nq = nq_data + nq_anc
     
     # Put a blank line of array cells coming into the circuit.
     trans_cells = [[""] * nq]
     
     for bitstring, recovery_gate in self.syndromes_and_recovery_operators():
         trans_cells.append(
             # Data register
             [r"\gate{{{}}} {}".format(P if P != "I" else r"\id", "\qwx" if idx != 0 else "") for idx, P in enumerate(recovery_gate.op)] +
             # Ancilla register
             [(r"\controlo" if bit == 0 else r"\control") + r" \cw \cwx" for bit in bitstring]
         )
      
     trans_cells.append([r"\qw"] * nq_data + [r"\cw"] * nq_anc)
      
     # FIXME: consolidate this with Circuit.as_qcircuit().   
     return r"""
     \Qcircuit  {C} {R} {{
         {0}
     }}
     """.format(
         u.latex_array_contents(u.transpose(trans_cells)),
         C="@C{}em".format(C) if C is not None else "",
         R="@R{}em".format(R) if R is not None else ""
         )