Skip to content

Commit 3a4cc97

Browse files
committed
debug decomposition errors
1 parent 0852ab6 commit 3a4cc97

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

qualtran/_infra/bloq.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@
5252
def _decompose_from_build_composite_bloq(bloq: 'Bloq') -> 'CompositeBloq':
5353
from qualtran import BloqBuilder
5454

55-
bb, initial_soqs = BloqBuilder.from_signature(bloq.signature, add_registers_allowed=False)
56-
out_soqs = bloq.build_composite_bloq(bb=bb, **initial_soqs)
57-
return bb.finalize(**out_soqs)
55+
try:
56+
bb, initial_soqs = BloqBuilder.from_signature(bloq.signature, add_registers_allowed=False)
57+
out_soqs = bloq.build_composite_bloq(bb=bb, **initial_soqs)
58+
return bb.finalize(**out_soqs)
59+
except (DecomposeTypeError, DecomposeNotImplementedError) as ex:
60+
raise ex
61+
except Exception as ex:
62+
raise RuntimeError(f"Unexpected error when decomposing {bloq}: {ex}") from ex
5863

5964

6065
class DecomposeNotImplementedError(NotImplementedError):

qualtran/cirq_interop/_cirq_to_bloq.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,12 @@ def decompose_from_registers(
602602
return cirq_optree_to_cbloq(
603603
decomposed_optree, signature=bloq.signature, in_quregs=in_quregs, out_quregs=out_quregs
604604
)
605+
except (DecomposeNotImplementedError, DecomposeTypeError) as exc:
606+
raise exc
605607
except ValueError as exc:
606608
if "Only gate operations are supported" in str(exc):
607609
raise DecomposeNotImplementedError(str(exc)) from exc
608610
else:
609-
raise exc
611+
raise RuntimeError(f"Unexpected error when decomposing {bloq}: {exc}") from exc
612+
except Exception as exc:
613+
raise RuntimeError(f"Unexpected error when decomposing {bloq}: {exc}") from exc

0 commit comments

Comments
 (0)