Skip to content

Commit 0852ab6

Browse files
committed
Decompose Type Error
1 parent d2763ee commit 0852ab6

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

qualtran/bloqs/arithmetic/comparison.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,8 @@ def build_composite_bloq(
10801080
a = bb.add(SignExtend(self.dtype, QInt(self.dtype.bitsize + 1)), x=a)
10811081
b = bb.add(SignExtend(self.dtype, QInt(self.dtype.bitsize + 1)), x=b)
10821082
else:
1083+
if self.dtype.is_symbolic():
1084+
raise DecomposeTypeError(f"Cannot decompose symbolic {self}")
10831085
a = bb.join(np.concatenate([[bb.allocate(1)], bb.split(a)]))
10841086
b = bb.join(np.concatenate([[bb.allocate(1)], bb.split(b)]))
10851087

qualtran/bloqs/arithmetic/controlled_addition.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
bloq_example,
2424
BloqBuilder,
2525
BloqDocSpec,
26+
DecomposeTypeError,
2627
QBit,
2728
QInt,
2829
QUInt,
@@ -134,6 +135,9 @@ def wire_symbol(self, soq: 'Soquet') -> 'WireSymbol':
134135
def build_composite_bloq(
135136
self, bb: 'BloqBuilder', ctrl: 'Soquet', a: 'Soquet', b: 'Soquet'
136137
) -> Dict[str, 'SoquetT']:
138+
if self.a_dtype.is_symbolic() or self.b_dtype.is_symbolic():
139+
raise DecomposeTypeError(f"Cannot support symbolic {self}")
140+
137141
a_arr = bb.split(a)
138142
ctrl_q = bb.split(ctrl)[0]
139143
ancilla_arr = []

qualtran/bloqs/data_loading/select_swap_qrom.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@
2222
import sympy
2323
from numpy.typing import ArrayLike
2424

25-
from qualtran import bloq_example, BloqDocSpec, BQUInt, GateWithRegisters, Register, Signature
25+
from qualtran import (
26+
bloq_example,
27+
BloqDocSpec,
28+
BQUInt,
29+
DecomposeTypeError,
30+
GateWithRegisters,
31+
Register,
32+
Signature,
33+
)
2634
from qualtran.bloqs.arithmetic.bitwise import Xor
2735
from qualtran.bloqs.bookkeeping import Partition
2836
from qualtran.bloqs.data_loading.qrom import QROM
@@ -394,7 +402,7 @@ def build_composite_bloq(self, bb: 'BloqBuilder', **soqs: 'SoquetT') -> Dict[str
394402
target = [soqs.pop(reg.name) for reg in self.target_registers]
395403
# Allocate intermediate clean/dirty ancilla for the underlying QROM call.
396404
if is_symbolic(*self.block_sizes):
397-
raise ValueError(
405+
raise DecomposeTypeError(
398406
f"Cannot decompose SelectSwapQROM bloq with symbolic block sizes. Found {self.block_sizes=}"
399407
)
400408
block_sizes = cast(Tuple[int, ...], self.block_sizes)

qualtran/bloqs/mcmt/and_bloq.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ def decompose_from_registers(
386386
yield self._decompose_via_tree(control, self.concrete_cvs, ancilla, *target)
387387

388388
def decompose_bloq(self) -> 'CompositeBloq':
389+
if is_symbolic(self.cvs):
390+
raise DecomposeTypeError(f"Cannot decompose symbolic {self}.")
389391
return decompose_from_cirq_style_method(self)
390392

391393
def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -> 'WireSymbol':

qualtran/bloqs/mod_arithmetic/mod_addition.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Bloq,
2424
bloq_example,
2525
BloqDocSpec,
26+
DecomposeTypeError,
2627
GateWithRegisters,
2728
QBit,
2829
QMontgomeryUInt,
@@ -89,7 +90,7 @@ def on_classical_vals(
8990

9091
def build_composite_bloq(self, bb: 'BloqBuilder', x: Soquet, y: Soquet) -> Dict[str, 'SoquetT']:
9192
if is_symbolic(self.bitsize):
92-
raise NotImplementedError(f'symbolic decomposition is not supported for {self}')
93+
raise DecomposeTypeError(f'Symbolic decomposition is not supported for {self}')
9394
# Allocate ancilla bits for use in addition.
9495
junk_bit = bb.allocate(n=1)
9596
sign = bb.allocate(n=1)
@@ -390,6 +391,9 @@ def on_classical_vals(
390391
def build_composite_bloq(
391392
self, bb: 'BloqBuilder', ctrl, x: Soquet, y: Soquet
392393
) -> Dict[str, 'SoquetT']:
394+
if self.dtype.is_symbolic():
395+
raise DecomposeTypeError(f"Cannot decompose symbolic {self}")
396+
393397
y_arr = bb.split(y)
394398
ancilla = bb.allocate(1)
395399
x = bb.add(Cast(self.dtype, QUInt(self.dtype.bitsize)), reg=x)

0 commit comments

Comments
 (0)