|
15 | 15 | """Quantum read-only memory.""" |
16 | 16 |
|
17 | 17 | from functools import cached_property |
18 | | -from typing import Callable, Dict, Iterable, Sequence, Set, Tuple |
| 18 | +from typing import Any, Callable, Dict, Iterable, Sequence, Set, Tuple, Union |
19 | 19 |
|
20 | 20 | import attrs |
21 | 21 | import cirq |
|
28 | 28 | from qualtran.bloqs.mcmt.and_bloq import And, MultiAnd |
29 | 29 | from qualtran.bloqs.multiplexers.unary_iteration_bloq import UnaryIterationGate |
30 | 30 | from qualtran.drawing import Circle, TextBox, WireSymbol |
31 | | -from qualtran.resource_counting import BloqCountT |
| 31 | +from qualtran.resource_counting import BloqCountT, CostKey, QubitCount |
32 | 32 | from qualtran.simulation.classical_sim import ClassicalValT |
33 | 33 |
|
34 | 34 |
|
@@ -203,6 +203,11 @@ def on_classical_vals(self, **vals: 'ClassicalValT') -> Dict[str, 'ClassicalValT |
203 | 203 | targets = {k: v ^ vals[k] for k, v in targets.items()} |
204 | 204 | return controls | selections | targets |
205 | 205 |
|
| 206 | + def my_static_costs(self, cost_key: 'CostKey') -> Union[Any, NotImplemented]: |
| 207 | + if cost_key == QubitCount(): |
| 208 | + return self.num_controls + 2 * sum(self.selection_bitsizes) + sum(self.target_bitsizes) |
| 209 | + return super().my_static_costs(cost_key) |
| 210 | + |
206 | 211 | def _circuit_diagram_info_(self, _) -> cirq.CircuitDiagramInfo: |
207 | 212 | wire_symbols = ["@"] * self.num_controls |
208 | 213 | wire_symbols += ["In"] * total_bits(self.selection_registers) |
@@ -240,6 +245,9 @@ def nth_operation_callgraph(self, **kwargs: int) -> Set['BloqCountT']: |
240 | 245 | selection_idx = tuple(kwargs[reg.name] for reg in self.selection_registers) |
241 | 246 | return {(CNOT(), sum(int(d[selection_idx]).bit_count() for d in self.data))} |
242 | 247 |
|
| 248 | + def __str__(self): |
| 249 | + return 'QROM' |
| 250 | + |
243 | 251 |
|
244 | 252 | @bloq_example |
245 | 253 | def _qrom_small() -> QROM: |
|
0 commit comments