def _formatted(self, format_type, fence=False):
     formatted_gate_operation = (self.gate_operation.formatted(format_type,
                                                               fence=False))
     if format_type == 'latex':
         return r'\gate{' + formatted_gate_operation + r'}'
     else:
         return Operation.formatted(self, format_type, fence)
 def formatted(self, format_type, fence=False):
     formatted_gate_operation = self.target_gate.formatted(format_type,
                                                           fence=False)
     if format_type == LATEX:
         return r'\gate{' + formatted_gate_operation + r'}'
     else:
         return Operation.formatted(self, format_type, fence)
Exemple #3
0
 def formatter(self, formatType, fence=False):
     from .common import CTRL_UP, CTRL_DN, CTRL_UPDN, WIRE_UP, WIRE_DN, WIRE_LINK
     if formatType == LATEX:
         if fence: yield r'\left[' + '\n'
         yield r'\begin{array}{cc}' + '\n'
         yield r'\Qcircuit @C=1em @R=.7em {' # + '\n'
         for nestedRowIdx in self.generateNestedRowIndices():
             #print "nestedRowIdx", nestedRowIdx
             if sum(nestedRowIdx) > 0: yield r' \\ ' # previous row has ended
             for level, circuitTensor, row, column in self.generateCircuitElementsAlongRow(nestedRowIdx):
                 if not (row, column) in circuitTensor:
                     yield r' & \qw' # identity gate is a quantum wire
                 else:
                     elem = circuitTensor[row, column]
                     if level < len(nestedRowIdx)-1:
                         # we have a multigate
                         if sum(nestedRowIdx[level:]) == 0:
                             # we are at the top of the multigate
                             numMultiGateRows = self.numberOfNestedRows(circuitTensor, row)
                             yield r' & \multigate{' + str(numMultiGateRows-1) + '}{' + elem.formatted(formatType, False) + '}'
                         else:
                             # below the top of the multigate, use ghost
                             yield r' & \ghost{' + elem.formatted(formatType, False) + '}'
                     elif elem == WIRE_LINK:
                         yield r' & \qw' # junction, but the instruction here just needs to continue the horizontal wire
                     elif elem == CTRL_UP:
                         yield r' & \ctrl{' + str(Circuit._NearestTarget(circuitTensor, row, column, -1)) + '}'
                     elif elem == CTRL_DN:
                         yield r' & \ctrl{' + str(Circuit._NearestTarget(circuitTensor, row, column, 1)) + '}'
                     elif elem == WIRE_UP:
                         yield r' & \qwx[' + str(Circuit._NearestTarget(circuitTensor, row, column, -1)) + '] \qw'
                     elif elem == WIRE_DN:
                         yield r' & \qwx[' + str(Circuit._NearestTarget(circuitTensor, row, column, 1)) + '] \qw'
                     elif elem == CTRL_UPDN:
                         yield r' & \ctrl{' + str(Circuit._NearestTarget(circuitTensor, row, column, -1)) + '}'
                         yield r' \qwx[' + str(Circuit._NearestTarget(circuitTensor, row, column, 1)) + ']'
                     elif elem == TARGET:
                         yield r' & ' + elem.formatted(formatType, False)
                     else:
                         yield r' & ' + elem.formatted(formatType, False)
         yield '} & ~ \n'
         yield r'\end{array}'
         if fence: yield '\n' + r'\right]'
     else:
         yield Operation.formatted(self, formatType, fence)
 def formatted(self, format_type, fence=False):
     formatted_state = self.state.formatted(format_type, fence=False)
     if format_type == LATEX:
         return r'\lstick{' + formatted_state + r'}'
     else:
         return Operation.formatted(self, format_type, fence)
 def formatted(self, format_type, fence=False):
     formatted_number = self.number.formatted(format_type, fence=False)
     if format_type == LATEX:
         return r'/^{' + formatted_number + r'} \qw'
     else:
         return Operation.formatted(self, format_type, fence)