3
3
from bloqade .ir .scalar import Scalar , Literal , cast
4
4
from bloqade .ir .tree_print import Printer
5
5
6
- from pydantic .dataclasses import dataclass
6
+ from pydantic .v1 . dataclasses import dataclass
7
7
from beartype .typing import List , Tuple , Generator , Union , Optional
8
+ from beartype .door import is_bearable
8
9
from beartype import beartype
9
10
from enum import Enum
10
11
from numpy .typing import NDArray
14
15
15
16
from beartype .vale import Is
16
17
from typing import Annotated
17
- from plum import dispatch
18
18
import plotext as pltxt
19
19
import sys
20
20
import numpy as np
@@ -234,8 +234,8 @@ def scale(self, scale: ScalarType):
234
234
235
235
return ListOfLocations (location_list )
236
236
237
- @ dispatch
238
- def _add_position (
237
+ ## enforce input is single tuple and filling is single boolean
238
+ def add_position_single_tupe (
239
239
self , position : Tuple [ScalarType , ScalarType ], filling : Optional [bool ] = None
240
240
):
241
241
if filling is None :
@@ -246,8 +246,8 @@ def _add_position(
246
246
247
247
return ListOfLocations (location_list )
248
248
249
- @ dispatch
250
- def _add_position ( # noqa: F811
249
+ ## enforce input is list of tuples and filling is list of booleans or none
250
+ def add_position_list_tuples ( # noqa: F811
251
251
self ,
252
252
position : List [Tuple [ScalarType , ScalarType ]],
253
253
filling : Optional [List [bool ]] = None ,
@@ -268,8 +268,8 @@ def _add_position( # noqa: F811
268
268
269
269
return ListOfLocations (location_list )
270
270
271
- @ dispatch
272
- def _add_position ( # noqa: F811
271
+ ## enforce input is numpy array and filling is numpy array or none
272
+ def add_position_ndarray ( # noqa: F811
273
273
self , position : PositionArray , filling : Optional [BoolArray ] = None
274
274
):
275
275
return self .add_position (
@@ -333,7 +333,21 @@ def add_position(
333
333
shows your geometry in your web browser
334
334
335
335
"""
336
- return self ._add_position (position , filling )
336
+
337
+ if is_bearable (position , PositionArray ) and is_bearable (
338
+ filling , Optional [BoolArray ]
339
+ ):
340
+ return self .add_position_ndarray (position , filling )
341
+ elif is_bearable (position , List [Tuple [ScalarType , ScalarType ]]) and is_bearable (
342
+ filling , Optional [List [bool ]]
343
+ ):
344
+ return self .add_position_list_tuples (position , filling )
345
+ elif is_bearable (position , Tuple [ScalarType , ScalarType ]) and is_bearable (
346
+ filling , Optional [bool ]
347
+ ):
348
+ return self .add_position_single_tupe (position , filling )
349
+ else :
350
+ raise TypeError ("Invalid input types for add_position provided!" )
337
351
338
352
@beartype
339
353
def apply_defect_count (
0 commit comments