def __repr__(self): args = [ 'kraus_ops=[' + ', '.join(proper_repr(op) for op in self._kraus_ops) + ']' ] if self._key is not None: args.append(f'key=\'{self._key}\'') return f'cirq.KrausChannel({", ".join(args)})'
def _circuit_diagram_info_( self, args: 'cirq.CircuitDiagramInfoArgs' ) -> 'cirq.CircuitDiagramInfo': rounded_angles = np.array(self._diag_angles_radians) if args.precision is not None: rounded_angles = rounded_angles.round(args.precision) diag_str = 'diag({})'.format(', '.join(proper_repr(angle) for angle in rounded_angles)) return protocols.CircuitDiagramInfo((diag_str, '#2'))
def __repr__(self): unitary_tuples = [ '(' + repr(op[0]) + ', ' + proper_repr(op[1]) + ')' for op in self._mixture ] args = [f'mixture=[{", ".join(unitary_tuples)}]'] if self._key is not None: args.append(f'key=\'{self._key}\'') return f'cirq.MixedUnitaryChannel({", ".join(args)})'
def __repr__(self) -> str: before0 = proper_repr(self.single_qubit_operations_before[0]) before1 = proper_repr(self.single_qubit_operations_before[1]) after0 = proper_repr(self.single_qubit_operations_after[0]) after1 = proper_repr(self.single_qubit_operations_after[1]) return ( 'cirq.KakDecomposition(\n' f' interaction_coefficients={self.interaction_coefficients!r},\n' ' single_qubit_operations_before=(\n' f' {before0},\n' f' {before1},\n' ' ),\n' ' single_qubit_operations_after=(\n' f' {after0},\n' f' {after1},\n' ' ),\n' f' global_phase={self.global_phase!r})')
def __repr__(self) -> str: if self._global_shift == 0: if self._exponent == 1: return 'cirq.Y' return f'(cirq.Y**{proper_repr(self._exponent)})' return 'cirq.YPowGate(exponent={}, global_shift={!r})'.format( proper_repr(self._exponent), self._global_shift )
def __repr__(self) -> str: e = proper_repr(self._exponent) if self._global_shift == 0: if self._exponent == 1: return 'cirq.ISWAP' return f'(cirq.ISWAP**{e})' return (f'cirq.ISwapPowGate(exponent={e}, ' f'global_shift={self._global_shift!r})')
def _circuit_diagram_info_( self, args: 'cirq.CircuitDiagramInfoArgs' ) -> 'cirq.CircuitDiagramInfo': rounded_angles = np.array(self._diag_angles_radians) if args.precision is not None: rounded_angles = rounded_angles.round(args.precision) if len(rounded_angles) <= 4: rounded_angles_str = ', '.join(proper_repr(angle) for angle in rounded_angles) diag_str = f'diag({rounded_angles_str})' else: diag_str = ', '.join(proper_repr(angle) for angle in rounded_angles[:2]) diag_str += ', ..., ' diag_str += ', '.join(proper_repr(angle) for angle in rounded_angles[-2:]) diag_str = f'diag({diag_str})' return protocols.CircuitDiagramInfo( [diag_str] + ['#' + str(i) for i in range(2, self._num_qubits_() + 1)] )
def _write_test_data(key: str, *test_instances: Any): """Helper method for creating initial test data.""" # coverage: ignore cirq.to_json(test_instances, TEST_DATA_PATH / f'{key}.json') with open(TEST_DATA_PATH / f'{key}.repr', 'w') as f: f.write('[\n') for e in test_instances: f.write(proper_repr(e)) f.write(',\n') f.write(']')
def __repr__(self): return ('cirq.KakDecomposition(\n' ' interaction_coefficients={!r},\n' ' single_qubit_operations_before=(\n' ' {},\n' ' {},\n' ' ),\n' ' single_qubit_operations_after=(\n' ' {},\n' ' {},\n' ' ),\n' ' global_phase={!r})').format( self.interaction_coefficients, proper_repr(self.single_qubit_operations_before[0]), proper_repr(self.single_qubit_operations_before[1]), proper_repr(self.single_qubit_operations_after[0]), proper_repr(self.single_qubit_operations_after[1]), self.global_phase, )
def test_proper_repr_data_frame(): df = pd.DataFrame(index=[1, 2, 3], data=[[11, 21.0], [12, 22.0], [13, 23.0]], columns=['a', 'b']) df2 = eval(proper_repr(df)) assert df2['a'].dtype == np.int64 assert df2['b'].dtype == np.float pd.testing.assert_frame_equal(df2, df) df = pd.DataFrame(index=pd.Index([1, 2, 3], name='test'), data=[[11, 21.0], [12, 22.0], [13, 23.0]], columns=['a', 'b']) df2 = eval(proper_repr(df)) pd.testing.assert_frame_equal(df2, df) df = pd.DataFrame(index=pd.MultiIndex.from_tuples([(1, 2), (2, 3), (3, 4)], names=['x', 'y']), data=[[11, 21.0], [12, 22.0], [13, 23.0]], columns=pd.Index(['a', 'b'], name='c')) df2 = eval(proper_repr(df)) pd.testing.assert_frame_equal(df2, df)
def __repr__(self) -> str: if self._global_shift == -0.5: if protocols.is_parameterized(self._exponent): return 'cirq.Rz({})'.format( proper_repr(sympy.pi * self._exponent)) return 'cirq.Rz(np.pi*{!r})'.format(self._exponent) if self._global_shift == 0: if self._exponent == 0.25: return 'cirq.T' if self._exponent == -0.25: return '(cirq.T**-1)' if self._exponent == 0.5: return 'cirq.S' if self._exponent == -0.5: return '(cirq.S**-1)' if self._exponent == 1: return 'cirq.Z' return '(cirq.Z**{})'.format(proper_repr(self._exponent)) return ('cirq.ZPowGate(exponent={}, ' 'global_shift={!r})').format(proper_repr(self._exponent), self._global_shift)
def __repr__(self) -> str: if self._global_shift == -0.5: if isinstance(self._exponent, sympy.Basic): return 'cirq.Rz({})'.format(proper_repr( sympy.pi * self._exponent)) else: return 'cirq.Rz(np.pi*{!r})'.format(self._exponent) if self._global_shift == 0: if self._exponent == 0.25: return 'cirq.T' if self._exponent == -0.25: return '(cirq.T**-1)' if self._exponent == 0.5: return 'cirq.S' if self._exponent == -0.5: return '(cirq.S**-1)' if self._exponent == 1: return 'cirq.Z' return '(cirq.Z**{})'.format(proper_repr(self._exponent)) return ( 'cirq.ZPowGate(exponent={}, ' 'global_shift={!r})' ).format(proper_repr(self._exponent), self._global_shift)
def __repr__(self) -> str: if self._global_shift == 0: if self._exponent == 0.25: return 'cirq.T' if self._exponent == -0.25: return '(cirq.T**-1)' if self._exponent == 0.5: return 'cirq.S' if self._exponent == -0.5: return '(cirq.S**-1)' if self._exponent == 1: return 'cirq.Z' return f'(cirq.Z**{proper_repr(self._exponent)})' return 'cirq.ZPowGate(exponent={}, global_shift={!r})'.format( proper_repr(self._exponent), self._global_shift )
def __repr__(self) -> str: return 'cirq.ThreeQubitDiagonalGate([{}])'.format( ','.join(proper_repr(angle) for angle in self._diag_angles_radians) )
def __repr__(self) -> str: v = proper_repr(self.value) p = proper_repr(self.period) return f'cirq.PeriodicValue({v}, {p})'
def __repr__(self) -> str: t = proper_repr(self.theta) p = proper_repr(self.phi) return f'cirq.FSimGate(theta={t}, phi={p})'
def __repr__(self): return 'cirq.PhaseGradientGate(num_qubits={!r}, exponent={})'.format( self._num_qubits, _compat.proper_repr(self.exponent))
def __repr__(self): return ('BadEigenGate' '(exponent={}, global_shift={!r})'.format( proper_repr(self._exponent), self._global_shift))
def __repr__(self): return 'RandomMatrixGate({})'.format(proper_repr(self._matrix))
def __repr__(self): return ('cirq.PauliStringPhasor({!r}, ' 'exponent_neg={}, ' 'exponent_pos={})'.format(self.pauli_string, proper_repr(self.exponent_neg), proper_repr(self.exponent_pos)))
def __repr__(self): return 'cirq.PeriodicValue({}, {})'.format(proper_repr(self.value), proper_repr(self.period))
def __repr__(self): return 'cirq.SingleQubitMatrixGate({})'.format( proper_repr(self._matrix))
def item_repr(entry): key, val = entry return '{!r}: {}'.format(key, proper_repr(val))
def __repr__(self) -> str: if self._global_shift == 0: return 'cirq_iqm.IsingGate({})'.format(proper_repr(self._exponent)) return ('cirq_iqm.IsingGate(exponent={}, ' 'global_shift={!r})').format(proper_repr(self._exponent), self._global_shift)
def __repr__(self): args = ['phase_exponent={!r}'.format(2 * self.phase_exponent)] if self.exponent != 1: # coverage: ignore args.append('exponent={}'.format(proper_repr(self.exponent))) return 'BadGateRepr({})'.format(', '.join(args))
def __repr__(self): if self.exponent == 1: return 'ofc.DoubleExcitation' return '(ofc.DoubleExcitation**{})'.format(proper_repr(self.exponent))
def __repr__(self): args = ['phase_exponent={}'.format(proper_repr(self.phase_exponent))] if self.exponent != 1: args.append('exponent={}'.format(proper_repr(self.exponent))) return 'GoodGate({})'.format(', '.join(args))
def __repr__(self): return 'cirq.FSimGate(theta={}, phi={})'.format( proper_repr(self.theta), proper_repr(self.phi))