1616from functools import cached_property
1717from typing import (
1818 Callable ,
19+ cast ,
1920 Dict ,
2021 FrozenSet ,
2122 Hashable ,
2223 Iterable ,
2324 Iterator ,
2425 List ,
26+ Mapping ,
2527 Optional ,
2628 overload ,
2729 Sequence ,
@@ -176,7 +178,9 @@ def from_cirq_circuit(cls, circuit: 'cirq.Circuit') -> 'CompositeBloq':
176178
177179 return cirq_optree_to_cbloq (circuit )
178180
179- def on_classical_vals (self , ** vals : 'ClassicalValT' ) -> Dict [str , 'ClassicalValT' ]:
181+ def on_classical_vals (
182+ self , ** vals : Union [sympy .Symbol , 'ClassicalValT' ]
183+ ) -> Dict [str , 'ClassicalValT' ]:
180184 """Support classical data by recursing into the composite bloq."""
181185 from qualtran .simulation .classical_sim import call_cbloq_classically
182186
@@ -606,7 +610,7 @@ def _reg_to_soq(
606610
607611def _process_soquets (
608612 registers : Iterable [Register ],
609- in_soqs : Dict [str , SoquetT ],
613+ in_soqs : Mapping [str , SoquetInT ],
610614 debug_str : str ,
611615 func : Callable [[Soquet , Register , Tuple [int , ...]], None ],
612616) -> None :
@@ -631,6 +635,7 @@ def _process_soquets(
631635 the incoming, indexed soquet as well as the register and (left-)index it
632636 has been mapped to.
633637 """
638+ unchecked_names : Set [str ] = set (in_soqs .keys ())
634639 for reg in registers :
635640 try :
636641 # if we want fancy indexing (which we do), we need numpy
@@ -639,7 +644,7 @@ def _process_soquets(
639644 except KeyError :
640645 raise BloqError (f"{ debug_str } requires a Soquet named `{ reg .name } `." ) from None
641646
642- del in_soqs [ reg .name ] # so we can check for surplus arguments.
647+ unchecked_names . remove ( reg .name ) # so we can check for surplus arguments.
643648
644649 for li in reg .all_idxs ():
645650 idxed_soq = in_soq [li ]
@@ -652,9 +657,8 @@ def _process_soquets(
652657 raise BloqError (
653658 f"{ debug_str } register dtypes are not consistent { extra_str } ."
654659 ) from None
655-
656- if in_soqs :
657- raise BloqError (f"{ debug_str } does not accept Soquets: { in_soqs .keys ()} ." ) from None
660+ if unchecked_names :
661+ raise BloqError (f"{ debug_str } does not accept Soquets: { unchecked_names } ." ) from None
658662
659663
660664def _map_soqs (
@@ -965,7 +969,7 @@ def add(self, bloq: Bloq, **in_soqs: SoquetInT):
965969 return outs
966970
967971 def _add_binst (
968- self , binst : BloqInstance , in_soqs : Dict [str , SoquetInT ]
972+ self , binst : BloqInstance , in_soqs : Mapping [str , SoquetInT ]
969973 ) -> Iterator [Tuple [str , SoquetT ]]:
970974 """Add a bloq instance.
971975
@@ -1010,7 +1014,8 @@ def add_from(self, bloq: Bloq, **in_soqs: SoquetInT) -> Tuple[SoquetT, ...]:
10101014
10111015 # Initial mapping of LeftDangle according to user-provided in_soqs.
10121016 soq_map : List [Tuple [SoquetT , SoquetT ]] = [
1013- (_reg_to_soq (LeftDangle , reg ), in_soqs [reg .name ]) for reg in cbloq .signature .lefts ()
1017+ (_reg_to_soq (LeftDangle , reg ), cast (SoquetT , in_soqs [reg .name ]))
1018+ for reg in cbloq .signature .lefts ()
10141019 ]
10151020
10161021 for binst , in_soqs , old_out_soqs in cbloq .iter_bloqsoqs ():
0 commit comments