@@ -45,13 +45,13 @@ def col(self) -> int:
45
45
return self ._col
46
46
47
47
def with_dimension (self , dimension : int ) -> 'GridQid' :
48
- return GridQid (self .row , self .col , dimension = dimension )
48
+ return GridQid (self ._row , self ._col , dimension = dimension )
49
49
50
50
def is_adjacent (self , other : 'cirq.Qid' ) -> bool :
51
51
"""Determines if two qubits are adjacent qubits."""
52
52
return (
53
53
isinstance (other , GridQubit )
54
- and abs (self .row - other .row ) + abs (self .col - other .col ) == 1
54
+ and abs (self ._row - other ._row ) + abs (self ._col - other ._col ) == 1
55
55
)
56
56
57
57
def neighbors (self , qids : Optional [Iterable [ops .Qid ]] = None ) -> Set ['_BaseGridQid' ]:
@@ -71,7 +71,7 @@ def _with_row_col(self, row: int, col: int) -> Self:
71
71
"""Returns a qid with the same type but a different coordinate."""
72
72
73
73
def __complex__ (self ) -> complex :
74
- return self .col + 1j * self .row
74
+ return self ._col + 1j * self ._row
75
75
76
76
def __add__ (self , other : Union [Tuple [int , int ], Self ]) -> Self :
77
77
if isinstance (other , _BaseGridQid ):
@@ -80,7 +80,7 @@ def __add__(self, other: Union[Tuple[int, int], Self]) -> Self:
80
80
"Can only add GridQids with identical dimension. "
81
81
f"Got { self .dimension } and { other .dimension } "
82
82
)
83
- return self ._with_row_col (row = self .row + other .row , col = self .col + other .col )
83
+ return self ._with_row_col (row = self ._row + other ._row , col = self ._col + other ._col )
84
84
if not (
85
85
isinstance (other , (tuple , np .ndarray ))
86
86
and len (other ) == 2
@@ -90,7 +90,7 @@ def __add__(self, other: Union[Tuple[int, int], Self]) -> Self:
90
90
'Can only add integer tuples of length 2 to '
91
91
f'{ type (self ).__name__ } . Instead was { other } '
92
92
)
93
- return self ._with_row_col (row = self .row + other [0 ], col = self .col + other [1 ])
93
+ return self ._with_row_col (row = self ._row + other [0 ], col = self ._col + other [1 ])
94
94
95
95
def __sub__ (self , other : Union [Tuple [int , int ], Self ]) -> Self :
96
96
if isinstance (other , _BaseGridQid ):
@@ -99,7 +99,7 @@ def __sub__(self, other: Union[Tuple[int, int], Self]) -> Self:
99
99
"Can only subtract GridQids with identical dimension. "
100
100
f"Got { self .dimension } and { other .dimension } "
101
101
)
102
- return self ._with_row_col (row = self .row - other .row , col = self .col - other .col )
102
+ return self ._with_row_col (row = self ._row - other ._row , col = self ._col - other ._col )
103
103
if not (
104
104
isinstance (other , (tuple , np .ndarray ))
105
105
and len (other ) == 2
@@ -109,7 +109,7 @@ def __sub__(self, other: Union[Tuple[int, int], Self]) -> Self:
109
109
"Can only subtract integer tuples of length 2 to "
110
110
f"{ type (self ).__name__ } . Instead was { other } "
111
111
)
112
- return self ._with_row_col (row = self .row - other [0 ], col = self .col - other [1 ])
112
+ return self ._with_row_col (row = self ._row - other [0 ], col = self ._col - other [1 ])
113
113
114
114
def __radd__ (self , other : Tuple [int , int ]) -> Self :
115
115
return self + other
@@ -118,7 +118,7 @@ def __rsub__(self, other: Tuple[int, int]) -> Self:
118
118
return - self + other
119
119
120
120
def __neg__ (self ) -> Self :
121
- return self ._with_row_col (row = - self .row , col = - self .col )
121
+ return self ._with_row_col (row = - self ._row , col = - self ._col )
122
122
123
123
124
124
class GridQid (_BaseGridQid ):
@@ -255,16 +255,16 @@ def from_diagram(diagram: str, dimension: int) -> List['GridQid']:
255
255
return [GridQid (* c , dimension = dimension ) for c in coords ]
256
256
257
257
def __repr__ (self ) -> str :
258
- return f"cirq.GridQid({ self .row } , { self .col } , dimension={ self .dimension } )"
258
+ return f"cirq.GridQid({ self ._row } , { self ._col } , dimension={ self .dimension } )"
259
259
260
260
def __str__ (self ) -> str :
261
- return f"q({ self .row } , { self .col } ) (d={ self .dimension } )"
261
+ return f"q({ self ._row } , { self ._col } ) (d={ self .dimension } )"
262
262
263
263
def _circuit_diagram_info_ (
264
264
self , args : 'cirq.CircuitDiagramInfoArgs'
265
265
) -> 'cirq.CircuitDiagramInfo' :
266
266
return protocols .CircuitDiagramInfo (
267
- wire_symbols = (f"({ self .row } , { self .col } ) (d={ self .dimension } )" ,)
267
+ wire_symbols = (f"({ self ._row } , { self ._col } ) (d={ self .dimension } )" ,)
268
268
)
269
269
270
270
def _json_dict_ (self ) -> Dict [str , Any ]:
@@ -305,13 +305,13 @@ def __hash__(self) -> int:
305
305
def __eq__ (self , other ):
306
306
# Explicitly implemented for performance (vs delegating to Qid).
307
307
if isinstance (other , GridQubit ):
308
- return self .row == other .row and self .col == other .col
308
+ return self ._row == other ._row and self ._col == other ._col
309
309
return NotImplemented
310
310
311
311
def __ne__ (self , other ):
312
312
# Explicitly implemented for performance (vs delegating to Qid).
313
313
if isinstance (other , GridQubit ):
314
- return self .row != other .row or self .col != other .col
314
+ return self ._row != other ._row or self ._col != other ._col
315
315
return NotImplemented
316
316
317
317
@property
@@ -412,15 +412,15 @@ def from_diagram(diagram: str) -> List['GridQubit']:
412
412
return [GridQubit (* c ) for c in coords ]
413
413
414
414
def __repr__ (self ) -> str :
415
- return f"cirq.GridQubit({ self .row } , { self .col } )"
415
+ return f"cirq.GridQubit({ self ._row } , { self ._col } )"
416
416
417
417
def __str__ (self ) -> str :
418
- return f"q({ self .row } , { self .col } )"
418
+ return f"q({ self ._row } , { self ._col } )"
419
419
420
420
def _circuit_diagram_info_ (
421
421
self , args : 'cirq.CircuitDiagramInfoArgs'
422
422
) -> 'cirq.CircuitDiagramInfo' :
423
- return protocols .CircuitDiagramInfo (wire_symbols = (f"({ self .row } , { self .col } )" ,))
423
+ return protocols .CircuitDiagramInfo (wire_symbols = (f"({ self ._row } , { self ._col } )" ,))
424
424
425
425
def _json_dict_ (self ) -> Dict [str , Any ]:
426
426
return protocols .obj_to_dict_helper (self , ['row' , 'col' ])
0 commit comments