1818
1919from attrs import frozen
2020
21- from .composite_bloq import _binst_to_cxns , _cxns_to_soq_dict , _map_soqs , _reg_to_soq , BloqBuilder
21+ from .composite_bloq import (
22+ _binst_to_cxns ,
23+ _cxns_to_soq_dict ,
24+ _map_soqs ,
25+ _reg_to_soq ,
26+ _SoquetT ,
27+ BloqBuilder ,
28+ QVarT ,
29+ )
2230from .gate_with_registers import GateWithRegisters
2331from .quantum_graph import LeftDangle , RightDangle
2432from .registers import Signature
2533
2634if TYPE_CHECKING :
2735 import cirq
2836
29- from qualtran import Bloq , CompositeBloq , Register , Signature , SoquetT
37+ from qualtran import Bloq , CompositeBloq , Register , Signature
3038 from qualtran .drawing import WireSymbol
3139 from qualtran .resource_counting import BloqCountDictT , SympySymbolAllocator
3240
3341
34- def _adjoint_final_soqs (cbloq : 'CompositeBloq' , new_signature : Signature ) -> Dict [str , 'SoquetT ' ]:
42+ def _adjoint_final_soqs (cbloq : 'CompositeBloq' , new_signature : Signature ) -> Dict [str , '_SoquetT ' ]:
3543 """`CompositeBloq.final_soqs()` but backwards."""
3644 if LeftDangle not in cbloq ._binst_graph :
3745 return {}
@@ -57,15 +65,15 @@ def _adjoint_cbloq(cbloq: 'CompositeBloq') -> 'CompositeBloq':
5765 # First, we reverse the registers to initialize the BloqBuilder.
5866 old_signature = cbloq .signature
5967 new_signature = cbloq .signature .adjoint ()
60- old_i_soqs = [_reg_to_soq (RightDangle , reg ) for reg in old_signature .rights ()]
61- new_i_soqs = [_reg_to_soq (LeftDangle , reg ) for reg in new_signature .lefts ()]
62- soq_map : List [Tuple [SoquetT , SoquetT ]] = list (zip (old_i_soqs , new_i_soqs ))
6368
6469 # Then we reverse the order of subbloqs
6570 bloqnections = reversed (list (cbloq .iter_bloqnections ()))
6671
6772 # And add subbloq.adjoint() back in for each subbloq.
6873 bb , _ = BloqBuilder .from_signature (new_signature )
74+ old_i_soqs = [_reg_to_soq (RightDangle , reg ) for reg in old_signature .rights ()]
75+ new_i_soqs = [bb ._reg_to_qvar (LeftDangle , reg ) for reg in new_signature .lefts ()]
76+ soq_map : List [Tuple [_SoquetT , QVarT ]] = list (zip (old_i_soqs , new_i_soqs ))
6977 for binst , preds , succs in bloqnections :
7078 # Instead of get_me returning the right element of a predecessor connection,
7179 # it's the left element of a successor connection.
0 commit comments