Skip to content

Commit f5d764b

Browse files
committed
debug decomposition errors
1 parent 4a63851 commit f5d764b

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
@@ -46,9 +46,14 @@
4646
def _decompose_from_build_composite_bloq(bloq: 'Bloq') -> 'CompositeBloq':
4747
from qualtran import BloqBuilder
4848

49-
bb, initial_soqs = BloqBuilder.from_signature(bloq.signature, add_registers_allowed=False)
50-
out_soqs = bloq.build_composite_bloq(bb=bb, **initial_soqs)
51-
return bb.finalize(**out_soqs)
49+
try:
50+
bb, initial_soqs = BloqBuilder.from_signature(bloq.signature, add_registers_allowed=False)
51+
out_soqs = bloq.build_composite_bloq(bb=bb, **initial_soqs)
52+
return bb.finalize(**out_soqs)
53+
except (DecomposeTypeError, DecomposeNotImplementedError) as ex:
54+
raise ex
55+
except Exception as ex:
56+
raise RuntimeError(f"Unexpected error when decomposing {bloq}: {ex}") from ex
5257

5358

5459
class DecomposeNotImplementedError(NotImplementedError):

qualtran/cirq_interop/_cirq_to_bloq.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,12 @@ def decompose_from_registers(
594594
return cirq_optree_to_cbloq(
595595
decomposed_optree, signature=bloq.signature, in_quregs=in_quregs, out_quregs=out_quregs
596596
)
597+
except (DecomposeNotImplementedError, DecomposeTypeError) as exc:
598+
raise exc
597599
except ValueError as exc:
598600
if "Only gate operations are supported" in str(exc):
599601
raise DecomposeNotImplementedError(str(exc)) from exc
600602
else:
601-
raise exc
603+
raise RuntimeError(f"Unexpected error when decomposing {bloq}: {exc}") from exc
604+
except Exception as exc:
605+
raise RuntimeError(f"Unexpected error when decomposing {bloq}: {exc}") from exc

0 commit comments

Comments
 (0)