|
| 1 | +import pytest |
1 | 2 | from kirin import ir, types |
2 | 3 | from kirin.passes import Fold |
3 | 4 | from kirin.dialects import py, func, ilist |
@@ -384,10 +385,51 @@ def test_wire_measure_and_reset(): |
384 | 385 | constructed_method.print() |
385 | 386 |
|
386 | 387 |
|
| 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 | + |
387 | 427 | # test_wire_measure_and_reset() |
388 | 428 | # test_qubit_measure_and_reset() |
389 | 429 | # test_wire_reset() |
390 | 430 |
|
391 | 431 | # test_parallel_qubit_1q_application() |
392 | 432 | # test_parallel_wire_1q_application() |
393 | 433 | # test_parallel_control_gate_wire_application() |
| 434 | + |
| 435 | +# test_wire_apply_site_verification() |
0 commit comments