Skip to content

Commit bb8900c

Browse files
committed
Fix phase runtime and test
1 parent 7b8826a commit bb8900c

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/bloqade/pyqrack/squin/runtime.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,12 @@ class PhaseOpRuntime(MtrxOpRuntime):
217217

218218
def mat(self, adjoint: bool) -> list[complex]:
219219
sign = (-1) ** (not adjoint)
220-
phase = np.exp(sign * 1j * self.theta)
221-
return [self.global_ * phase, 0, 0, phase]
220+
local_phase = np.exp(sign * 1j * self.theta)
221+
222+
# NOTE: this is just 1 if we want a local shift
223+
global_phase = np.exp(sign * 1j * self.theta * self.global_)
224+
225+
return [global_phase, 0, 0, local_phase]
222226

223227

224228
@dataclass(frozen=True)

test/pyqrack/test_squin.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def new():
2323
assert out == [1.0] + [0.0] * (2**3 - 1)
2424

2525
@squin.kernel
26-
def measure():
26+
def m():
2727
q = squin.qubit.new(3)
2828
m = squin.qubit.measure(q)
2929
squin.qubit.reset(q)
3030
return m
3131

3232
target = PyQrack(3)
33-
result = target.run(measure)
33+
result = target.run(m)
3434
assert isinstance(result, list)
3535
assert result == [0, 0, 0]
3636

@@ -157,17 +157,15 @@ def main():
157157
h = squin.op.h()
158158
squin.qubit.apply(h, q)
159159

160-
# rotate local phase by pi/2
161-
p = squin.op.shift(math.pi / 2)
160+
p = squin.op.shift(math.pi)
162161
squin.qubit.apply(p, q)
163162

164-
# the next hadamard should rotate it back to 0
165163
squin.qubit.apply(h, q)
166164
return squin.qubit.measure(q)
167165

168166
target = PyQrack(1)
169167
result = target.run(main)
170-
assert result == [0]
168+
assert result == [1]
171169

172170

173171
def test_sp():
@@ -334,7 +332,8 @@ def main():
334332
# test_mult()
335333
# test_kron()
336334
# test_scale()
337-
# test_phase()
335+
# for i in range(100):
336+
# test_phase()
338337
# test_sp()
339338
# test_adjoint()
340339
# for i in range(100):

0 commit comments

Comments
 (0)