|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +from collections import Counter |
15 | 16 | from functools import cached_property |
16 | | -from typing import Dict, List, Optional, Set, Tuple, TYPE_CHECKING |
| 17 | +from typing import Dict, List, Optional, Tuple, TYPE_CHECKING |
17 | 18 |
|
18 | 19 | import cirq |
19 | 20 | from attrs import frozen |
|
26 | 27 | if TYPE_CHECKING: |
27 | 28 | from qualtran import Bloq, CompositeBloq, Register, Signature, SoquetT |
28 | 29 | from qualtran.drawing import WireSymbol |
29 | | - from qualtran.resource_counting import BloqCountT, SympySymbolAllocator |
| 30 | + from qualtran.resource_counting import BloqCountDictT, SympySymbolAllocator |
30 | 31 |
|
31 | 32 |
|
32 | 33 | def _adjoint_final_soqs(cbloq: 'CompositeBloq', new_signature: Signature) -> Dict[str, 'SoquetT']: |
@@ -150,17 +151,21 @@ def _circuit_diagram_info_( |
150 | 151 | sub_info.exponent *= -1 |
151 | 152 | return sub_info |
152 | 153 |
|
153 | | - def supports_decompose_bloq(self) -> bool: |
154 | | - """Delegate to `subbloq.supports_decompose_bloq()`""" |
155 | | - return self.subbloq.supports_decompose_bloq() |
156 | | - |
157 | 154 | def adjoint(self) -> 'Bloq': |
158 | 155 | """The 'double adjoint' brings you back to the original bloq.""" |
159 | 156 | return self.subbloq |
160 | 157 |
|
161 | | - def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']: |
| 158 | + def build_call_graph(self, ssa: 'SympySymbolAllocator') -> 'BloqCountDictT': |
162 | 159 | """The call graph takes the adjoint of each of the bloqs in `subbloq`'s call graph.""" |
163 | | - return {(bloq.adjoint(), n) for bloq, n in self.subbloq.build_call_graph(ssa=ssa)} |
| 160 | + sub_cg = self.subbloq.build_call_graph(ssa=ssa) |
| 161 | + counts = Counter['Bloq']() |
| 162 | + if isinstance(sub_cg, set): |
| 163 | + for bloq, n in sub_cg: |
| 164 | + counts[bloq.adjoint()] += n |
| 165 | + else: |
| 166 | + for bloq, n in sub_cg.items(): |
| 167 | + counts[bloq.adjoint()] += n |
| 168 | + return counts |
164 | 169 |
|
165 | 170 | def pretty_name(self) -> str: |
166 | 171 | """The subbloq's pretty_name with a dagger.""" |
|
0 commit comments