Skip to content

Commit

Permalink
Decompose Type Error
Browse files Browse the repository at this point in the history
  • Loading branch information
mpharrigan committed Sep 9, 2024
1 parent d2763ee commit 0852ab6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions qualtran/bloqs/arithmetic/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,8 @@ def build_composite_bloq(
a = bb.add(SignExtend(self.dtype, QInt(self.dtype.bitsize + 1)), x=a)
b = bb.add(SignExtend(self.dtype, QInt(self.dtype.bitsize + 1)), x=b)
else:
if self.dtype.is_symbolic():
raise DecomposeTypeError(f"Cannot decompose symbolic {self}")
a = bb.join(np.concatenate([[bb.allocate(1)], bb.split(a)]))
b = bb.join(np.concatenate([[bb.allocate(1)], bb.split(b)]))

Expand Down
4 changes: 4 additions & 0 deletions qualtran/bloqs/arithmetic/controlled_addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
bloq_example,
BloqBuilder,
BloqDocSpec,
DecomposeTypeError,
QBit,
QInt,
QUInt,
Expand Down Expand Up @@ -134,6 +135,9 @@ def wire_symbol(self, soq: 'Soquet') -> 'WireSymbol':
def build_composite_bloq(
self, bb: 'BloqBuilder', ctrl: 'Soquet', a: 'Soquet', b: 'Soquet'
) -> Dict[str, 'SoquetT']:
if self.a_dtype.is_symbolic() or self.b_dtype.is_symbolic():
raise DecomposeTypeError(f"Cannot support symbolic {self}")

a_arr = bb.split(a)
ctrl_q = bb.split(ctrl)[0]
ancilla_arr = []
Expand Down
12 changes: 10 additions & 2 deletions qualtran/bloqs/data_loading/select_swap_qrom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
import sympy
from numpy.typing import ArrayLike

from qualtran import bloq_example, BloqDocSpec, BQUInt, GateWithRegisters, Register, Signature
from qualtran import (
bloq_example,
BloqDocSpec,
BQUInt,
DecomposeTypeError,
GateWithRegisters,
Register,
Signature,
)
from qualtran.bloqs.arithmetic.bitwise import Xor
from qualtran.bloqs.bookkeeping import Partition
from qualtran.bloqs.data_loading.qrom import QROM
Expand Down Expand Up @@ -394,7 +402,7 @@ def build_composite_bloq(self, bb: 'BloqBuilder', **soqs: 'SoquetT') -> Dict[str
target = [soqs.pop(reg.name) for reg in self.target_registers]
# Allocate intermediate clean/dirty ancilla for the underlying QROM call.
if is_symbolic(*self.block_sizes):
raise ValueError(
raise DecomposeTypeError(
f"Cannot decompose SelectSwapQROM bloq with symbolic block sizes. Found {self.block_sizes=}"
)
block_sizes = cast(Tuple[int, ...], self.block_sizes)
Expand Down
2 changes: 2 additions & 0 deletions qualtran/bloqs/mcmt/and_bloq.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ def decompose_from_registers(
yield self._decompose_via_tree(control, self.concrete_cvs, ancilla, *target)

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

def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -> 'WireSymbol':
Expand Down
6 changes: 5 additions & 1 deletion qualtran/bloqs/mod_arithmetic/mod_addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Bloq,
bloq_example,
BloqDocSpec,
DecomposeTypeError,
GateWithRegisters,
QBit,
QMontgomeryUInt,
Expand Down Expand Up @@ -89,7 +90,7 @@ def on_classical_vals(

def build_composite_bloq(self, bb: 'BloqBuilder', x: Soquet, y: Soquet) -> Dict[str, 'SoquetT']:
if is_symbolic(self.bitsize):
raise NotImplementedError(f'symbolic decomposition is not supported for {self}')
raise DecomposeTypeError(f'Symbolic decomposition is not supported for {self}')
# Allocate ancilla bits for use in addition.
junk_bit = bb.allocate(n=1)
sign = bb.allocate(n=1)
Expand Down Expand Up @@ -390,6 +391,9 @@ def on_classical_vals(
def build_composite_bloq(
self, bb: 'BloqBuilder', ctrl, x: Soquet, y: Soquet
) -> Dict[str, 'SoquetT']:
if self.dtype.is_symbolic():
raise DecomposeTypeError(f"Cannot decompose symbolic {self}")

y_arr = bb.split(y)
ancilla = bb.allocate(1)
x = bb.add(Cast(self.dtype, QUInt(self.dtype.bitsize)), reg=x)
Expand Down

0 comments on commit 0852ab6

Please sign in to comment.