Skip to content

Commit

Permalink
add comment on controlled unitary failure
Browse files Browse the repository at this point in the history
  • Loading branch information
anurudhp committed Nov 7, 2024
1 parent 9cb2e5e commit 88d650d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion qualtran/_infra/controlled.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,19 @@ def _unitary_(self):
# subbloq is a cirq gate, use the cirq-style API to derive a unitary.
import cirq

# TODO It would be ideal to use `tensor_contract` always,
# but at the moment it's about 5-10x slower than `cirq.unitary`.
# So we default to `cirq.unitary`, and only use `tensor_contract` if it fails.
# https://github.com/quantumlib/Qualtran/issues/1336
# TODO `cirq.ControlledGate` fails to correctly verify `subbloq` using
# a compute-uncompute `And` pair is unitary.
# https://github.com/quantumlib/Qualtran/issues/1488
try:
return cirq.unitary(
cirq.ControlledGate(self.subbloq, control_values=self.ctrl_spec.to_cirq_cv())
)
except ValueError:
pass
pass # use the tensor contraction instead
if all(reg.side == Side.THRU for reg in self.subbloq.signature):
# subbloq has only THRU registers, so the tensor contraction corresponds
# to a unitary matrix.
Expand Down

0 comments on commit 88d650d

Please sign in to comment.