Skip to content

Commit

Permalink
Fix BloqAsCirqGate.__pow__ (#1566)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpharrigan authored Feb 26, 2025
1 parent 60037bc commit 7be77d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 1 addition & 4 deletions qualtran/cirq_interop/_bloq_to_cirq.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ def __pow__(self, power, modulo=None):

bloq = self.bloq if power > 0 else self.bloq.adjoint()

try:
return BloqAsCirqGate(Power(bloq, abs(power)))
except ValueError as e:
raise ValueError(f"Bad power {power}") from e
return Power(bloq, abs(power))

def __eq__(self, other):
if not isinstance(other, BloqAsCirqGate):
Expand Down
9 changes: 9 additions & 0 deletions qualtran/cirq_interop/_bloq_to_cirq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ def test_swap():
assert swap_decomp_circuit == should_be


def test_cirq_pow():
circ = cirq.Circuit()
q0, q1 = cirq.LineQubit.range(2)
with pytest.raises(ValueError, match=r'.*positive integer.*'):
circ += (BloqAsCirqGate(SwapTwoBitsTest()) ** 0.5).on(q0, q1)

circ += (BloqAsCirqGate(SwapTwoBitsTest()) ** 2).on(q0, q1)


def test_multi_and_allocates():
multi_and = MultiAnd(cvs=(1, 1, 1, 1))
cirq_quregs = get_named_qubits(multi_and.signature.lefts())
Expand Down

0 comments on commit 7be77d7

Please sign in to comment.