3
3
from beartype .vale import Is
4
4
from typing import Annotated
5
5
from beartype import beartype
6
+ from plum import dispatch
6
7
import numpy as np
7
8
from bloqade .ir .scalar import cast
8
9
@@ -46,7 +47,7 @@ def scale(self, scale: ScalarType):
46
47
47
48
return ListOfLocations (location_list )
48
49
49
- @beartype
50
+ @dispatch
50
51
def _add_position (
51
52
self , position : Tuple [ScalarType , ScalarType ], filling : Optional [bool ] = None
52
53
):
@@ -61,8 +62,8 @@ def _add_position(
61
62
62
63
return ListOfLocations (location_list )
63
64
64
- @beartype
65
- def _add_position_list (
65
+ @dispatch
66
+ def _add_position ( # noqa: F811
66
67
self ,
67
68
position : List [Tuple [ScalarType , ScalarType ]],
68
69
filling : Optional [List [bool ]] = None ,
@@ -86,23 +87,23 @@ def _add_position_list(
86
87
87
88
return ListOfLocations (location_list )
88
89
89
- @beartype
90
- def _add_numpy_position (
90
+ @dispatch
91
+ def _add_position ( # noqa: F811
91
92
self , position : PositionArray , filling : Optional [BoolArray ] = None
92
93
):
93
- return self ._add_position_list (
94
+ return self .add_position (
94
95
list (map (tuple , position .tolist ())),
95
96
filling .tolist () if filling is not None else None ,
96
97
)
97
98
98
99
def add_position (
99
100
self ,
100
101
position : Union [
102
+ PositionArray ,
101
103
Tuple [ScalarType , ScalarType ],
102
104
List [Tuple [ScalarType , ScalarType ]],
103
- PositionArray ,
104
105
],
105
- filling : Optional [Union [bool , list [bool ], BoolArray ]] = None ,
106
+ filling : Optional [Union [BoolArray , List [bool ], bool ]] = None ,
106
107
) -> "ListOfLocations" :
107
108
"""add a position or list of positions to existing atom arrangement.
108
109
@@ -113,25 +114,15 @@ def add_position(
113
114
position to add
114
115
filling (bool | list[bool]
115
116
| numpy.array with shape (n, ) | None, optional):
116
- filling of the added position(s). Defaults to None.
117
+ filling of the added position(s). Defaults to None. if None, all
118
+ positions are filled.
119
+
117
120
118
121
Returns:
119
122
ListOfLocations: new atom arrangement with added positions
120
123
121
124
"""
122
- if isinstance (position , tuple ) and isinstance (filling , (bool , type (None ))):
123
- return self ._add_position (position , filling )
124
- elif isinstance (position , list ) and isinstance (filling , (list , type (None ))):
125
- return self ._add_position_list (position , filling )
126
- elif isinstance (position , np .ndarray ) and isinstance (
127
- filling , (np .ndarray , type (None ))
128
- ):
129
- return self ._add_numpy_position (position , filling )
130
- else :
131
- raise TypeError (
132
- f"cannot interpret arguments, got { type (position )} "
133
- f"for position and { type (filling )} for filling"
134
- )
125
+ return self ._add_position (position , filling )
135
126
136
127
@beartype
137
128
def apply_defect_count (
0 commit comments