diff --git a/qualtran/_infra/bloq.py b/qualtran/_infra/bloq.py index 5fda9d70c..e9d48121f 100644 --- a/qualtran/_infra/bloq.py +++ b/qualtran/_infra/bloq.py @@ -52,9 +52,14 @@ def _decompose_from_build_composite_bloq(bloq: 'Bloq') -> 'CompositeBloq': from qualtran import BloqBuilder - bb, initial_soqs = BloqBuilder.from_signature(bloq.signature, add_registers_allowed=False) - out_soqs = bloq.build_composite_bloq(bb=bb, **initial_soqs) - return bb.finalize(**out_soqs) + try: + bb, initial_soqs = BloqBuilder.from_signature(bloq.signature, add_registers_allowed=False) + out_soqs = bloq.build_composite_bloq(bb=bb, **initial_soqs) + return bb.finalize(**out_soqs) + except (DecomposeTypeError, DecomposeNotImplementedError) as ex: + raise ex + except Exception as ex: + raise RuntimeError(f"Unexpected error when decomposing {bloq}: {ex}") from ex class DecomposeNotImplementedError(NotImplementedError): diff --git a/qualtran/cirq_interop/_cirq_to_bloq.py b/qualtran/cirq_interop/_cirq_to_bloq.py index 447227a6b..3ffc18773 100644 --- a/qualtran/cirq_interop/_cirq_to_bloq.py +++ b/qualtran/cirq_interop/_cirq_to_bloq.py @@ -602,8 +602,12 @@ def decompose_from_registers( return cirq_optree_to_cbloq( decomposed_optree, signature=bloq.signature, in_quregs=in_quregs, out_quregs=out_quregs ) + except (DecomposeNotImplementedError, DecomposeTypeError) as exc: + raise exc except ValueError as exc: if "Only gate operations are supported" in str(exc): raise DecomposeNotImplementedError(str(exc)) from exc else: - raise exc + raise RuntimeError(f"Unexpected error when decomposing {bloq}: {exc}") from exc + except Exception as exc: + raise RuntimeError(f"Unexpected error when decomposing {bloq}: {exc}") from exc