Skip to content

Commit

Permalink
debug decomposition errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mpharrigan committed Aug 29, 2024
1 parent d250938 commit a4af542
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions qualtran/_infra/bloq.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,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):
Expand Down
6 changes: 5 additions & 1 deletion qualtran/cirq_interop/_cirq_to_bloq.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,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

0 comments on commit a4af542

Please sign in to comment.