Skip to content

Commit 9427571

Browse files
committed
simple site verification test
1 parent 59f763d commit 9427571

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/squin/stim/stim.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from kirin import ir, types
23
from kirin.passes import Fold
34
from kirin.dialects import py, func, ilist
@@ -384,10 +385,51 @@ def test_wire_measure_and_reset():
384385
constructed_method.print()
385386

386387

388+
def test_wire_apply_site_verification():
389+
390+
stmts: list[ir.Statement] = [
391+
# Create qubit register
392+
(n_qubits := as_int(3)),
393+
(qreg := qasm2.core.QRegNew(n_qubits=n_qubits.result)),
394+
# Get qubis out
395+
(idx0 := as_int(0)),
396+
(q0 := qasm2.core.QRegGet(reg=qreg.result, idx=idx0.result)),
397+
(idx1 := as_int(1)),
398+
(q1 := qasm2.core.QRegGet(reg=qreg.result, idx=idx1.result)),
399+
(idx2 := as_int(2)),
400+
(q2 := qasm2.core.QRegGet(reg=qreg.result, idx=idx2.result)),
401+
# Unwrap to get wires
402+
(w0 := squin.wire.Unwrap(qubit=q0.result)),
403+
(w1 := squin.wire.Unwrap(qubit=q1.result)),
404+
(w2 := squin.wire.Unwrap(qubit=q2.result)),
405+
# set up control gate
406+
(op1 := squin.op.stmts.X()),
407+
(cx := squin.op.stmts.Control(op1.result, n_controls=1)),
408+
# improper application, dangling qubit that verification should catch!
409+
(app := squin.wire.Apply(cx.result, w0.result, w1.result, w2.result)),
410+
# wrap things back
411+
(squin.wire.Wrap(wire=app.results[0], qubit=q0.result)),
412+
(squin.wire.Wrap(wire=app.results[1], qubit=q1.result)),
413+
(squin.wire.Wrap(wire=app.results[2], qubit=q2.result)),
414+
(ret_none := func.ConstantNone()),
415+
(func.Return(ret_none)),
416+
]
417+
418+
constructed_method = gen_func_from_stmts(stmts)
419+
constructed_method.print()
420+
421+
squin_to_stim = squin_passes.SquinToStim(constructed_method.dialects)
422+
423+
with pytest.raises(ValueError):
424+
squin_to_stim(constructed_method)
425+
426+
387427
# test_wire_measure_and_reset()
388428
# test_qubit_measure_and_reset()
389429
# test_wire_reset()
390430

391431
# test_parallel_qubit_1q_application()
392432
# test_parallel_wire_1q_application()
393433
# test_parallel_control_gate_wire_application()
434+
435+
# test_wire_apply_site_verification()

0 commit comments

Comments
 (0)