Пример #1
0
    def text_diagram_info(
            self, args: ops.TextDiagramInfoArgs) -> ops.TextDiagramInfo:
        if self.half_turns in [-0.25, 0.25]:
            return ops.TextDiagramInfo(wire_symbols=('T', ),
                                       exponent=cast(float, self.half_turns) *
                                       4)

        if self.half_turns in [-0.5, 0.5]:
            return ops.TextDiagramInfo(wire_symbols=('S', ),
                                       exponent=cast(float, self.half_turns) *
                                       2)

        return ops.TextDiagramInfo(wire_symbols=('Z', ),
                                   exponent=self.half_turns)
 def text_diagram_info(self, args):
     # puts a [+1 : index] in inputs ordered by their bit order. I.e. low bit = 0
     syms = []
     for i in range(args.known_qubit_count - 1):
         syms.append('[+1 : ' + str(i) + ']')
     syms = tuple(syms)
     return ops.TextDiagramInfo(syms + ('BB', ), connected=True)
Пример #3
0
 def text_diagram_info(
         self, args: ops.TextDiagramInfoArgs) -> ops.TextDiagramInfo:
     well_known_map = {
         CliffordGate.I: 'I',
         CliffordGate.H: 'H',
         CliffordGate.X: 'X',
         CliffordGate.Y: 'Y',
         CliffordGate.Z: 'Z',
         CliffordGate.X_sqrt: 'X',
         CliffordGate.Y_sqrt: 'Y',
         CliffordGate.Z_sqrt: 'Z',
         CliffordGate.X_nsqrt: 'X',
         CliffordGate.Y_nsqrt: 'Y',
         CliffordGate.Z_nsqrt: 'Z',
     }
     if self in well_known_map:
         symbol = well_known_map[self]
     else:
         rotations = self.decompose_rotation()
         symbol = '-'.join(
             str(r) + ('^' + str(qt / 2)) * (qt % 4 != 2)
             for r, qt in rotations)
     return ops.TextDiagramInfo(wire_symbols=(symbol, ),
                                exponent={
                                    CliffordGate.X_sqrt: 0.5,
                                    CliffordGate.Y_sqrt: 0.5,
                                    CliffordGate.Z_sqrt: 0.5,
                                    CliffordGate.X_nsqrt: -0.5,
                                    CliffordGate.Y_nsqrt: -0.5,
                                    CliffordGate.Z_nsqrt: -0.5,
                                }.get(self, 1))
Пример #4
0
 def text_diagram_info(
         self, args: ops.TextDiagramInfoArgs) -> ops.TextDiagramInfo:
     labels = {Pauli.X: 'X', Pauli.Y: 'Y', Pauli.Z: '@'}
     l0 = labels[self.pauli0]
     l1 = labels[self.pauli1]
     # Add brackets around letter if inverted
     l0, l1 = ('(-{})'.format(l) if inv else l
               for l, inv in ((l0, self.invert0), (l1, self.invert1)))
     return ops.TextDiagramInfo(wire_symbols=(l0, l1),
                                exponent=self._exponent)
Пример #5
0
 def qcircuit_diagram_info(self, args: ops.TextDiagramInfoArgs
                           ) -> ops.TextDiagramInfo:
     name = str(self.sub)
     qubit_count = ((len(args.known_qubits) if
                    (args.known_qubits is not None) else 1)
                    if args.known_qubit_count is None
                    else args.known_qubit_count)
     symbols = tuple(_escape_text_for_latex('{}:{}'.format(name, i))
                     for i in range(qubit_count))
     return ops.TextDiagramInfo(symbols)
Пример #6
0
 def qcircuit_diagram_info(self, args: ops.TextDiagramInfoArgs
                           ) -> ops.TextDiagramInfo:
     info = self.sub.text_diagram_info(args)
     multigate_parameters = _get_multigate_parameters(self.sub, args)
     if multigate_parameters is not None:
         min_index, n_qubits = multigate_parameters
         name = _escape_text_for_latex(str(self.sub).rsplit('**', 1)[0])
         if info.exponent != 1:
             name += '^{' + str(info.exponent) + '}'
         box = '\multigate{' + str(n_qubits - 1) + '}{' + name + '}'
         ghost = '\ghost{' + name + '}'
         assert args.qubit_map is not None
         assert args.known_qubits is not None
         symbols = tuple(box if (args.qubit_map[q] == min_index) else
                         ghost for q in args.known_qubits)
         return ops.TextDiagramInfo(symbols, exponent=info.exponent,
                 connected=False)
     s = [_escape_text_for_latex(e) for e in info.wire_symbols]
     if info.exponent != 1:
         s[0] += '^{' + str(info.exponent) + '}'
     return ops.TextDiagramInfo(tuple('\\gate{' + e + '}' for e in s))
Пример #7
0
 def _pauli_string_diagram_info(
     self,
     args: ops.TextDiagramInfoArgs,
     exponent: Any = 1,
     exponent_absorbs_sign: bool = False,
 ) -> ops.TextDiagramInfo:
     qubits = self.qubits if args.known_qubits is None else args.known_qubits
     syms = tuple('[{}]'.format(self.pauli_string[qubit])
                  for qubit in qubits)
     if exponent_absorbs_sign and self.pauli_string.negated:
         if isinstance(exponent, float):
             exponent = -exponent
         else:
             exponent = '-{!s}'.format(exponent)
     return ops.TextDiagramInfo(wire_symbols=syms, exponent=exponent)
Пример #8
0
 def text_diagram_info(
         self, args: ops.TextDiagramInfoArgs) -> ops.TextDiagramInfo:
     e = 0 if args.precision is None else 10**-args.precision
     half_turns = self.half_turns
     if isinstance(self.axis_half_turns, value.Symbol):
         s = 'W({})'.format(self.axis_half_turns)
     elif abs(self.axis_half_turns) <= e:
         s = 'X'
     elif (abs(self.axis_half_turns - 1) <= e
           and isinstance(half_turns, float)):
         s = 'X'
         half_turns = -half_turns
     elif abs(self.axis_half_turns - 0.5) <= e:
         s = 'Y'
     elif args.precision is not None:
         s = 'W({{:.{}}})'.format(args.precision).format(
             self.axis_half_turns)
     else:
         s = 'W({})'.format(self.axis_half_turns)
     return ops.TextDiagramInfo((s, ), half_turns)
Пример #9
0
 def qcircuit_diagram_info(self, args: ops.TextDiagramInfoArgs
                           ) -> ops.TextDiagramInfo:
     return ops.TextDiagramInfo(self.symbols)
Пример #10
0
	def text_diagram_info(self):
		syms = ('@',) * (int(args.known_qubit_count) - 1)
		return ops.TextDiagramInfo(syms+('X',), connected=True)
Пример #11
0
 def text_diagram_info(self, args: ops.TextDiagramInfoArgs
                       ) -> ops.TextDiagramInfo:
     return ops.TextDiagramInfo(
         self.diagrammable.qcircuit_diagram_info(args))
Пример #12
0
 def text_diagram_info(self, args):
     base_info = self.u_gate.text_diagram_info(args)
     c_syms = ('@', ) * (int(args.known_qubit_count) - 1)
     return ops.TextDiagramInfo(c_syms + base_info.wire_symbols,
                                exponent=base_info.exponent,
                                connected=True)
Пример #13
0
 def text_diagram_info(self, args):
     return ops.TextDiagramInfo(('[Swap 01]', '[Swap 01]'))
Пример #14
0
 def text_diagram_info(self, args):
     return ops.TextDiagramInfo(('[F12]', ))
Пример #15
0
 def text_diagram_info(self, args):
     syms = []
     for i in range(args.known_qubit_count):
         syms.append('[+1 : ' + str(i) + ']')
     syms = tuple(syms)
     return ops.TextDiagramInfo(syms, connected=True)
Пример #16
0
 def qcircuit_diagram_info(self, args: ops.TextDiagramInfoArgs
                           ) -> Tuple[str, ...]:
     return ops.TextDiagramInfo(self.symbols).wire_symbols
Пример #17
0
 def text_diagram_info(
         self, args: ops.TextDiagramInfoArgs) -> ops.TextDiagramInfo:
     return ops.TextDiagramInfo(('@', '@'), self.half_turns)
Пример #18
0
 def text_diagram_info(self, args):
     base_info = self.base_gate.text_diagram_info(args)
     c_syms = self._control_symbols()
     return ops.TextDiagramInfo(c_syms + base_info.wire_symbols,
                                exponent=base_info.exponent,
                                connected=True)