@@ -42,7 +42,38 @@ def gen_func_from_stmts(stmts):
4242
4343
4444def test_primitive_ops ():
45- pass
45+ # test a couple standard operators derived from PrimitiveOp
46+
47+ stmts = [
48+ (n_qubits := as_int (1 )),
49+ (qreg := squin .qubit .New (n_qubits = n_qubits .result )),
50+ (idx0 := as_int (0 )),
51+ (q := py .GetItem (qreg .result , idx0 .result )),
52+ # get wire
53+ (w := squin .wire .Unwrap (q .result )),
54+ # put wire through gates
55+ (h := squin .op .stmts .H ()),
56+ (t := squin .op .stmts .T ()),
57+ (x := squin .op .stmts .X ()),
58+ (v0 := squin .wire .Apply (h .result , w .result )),
59+ (v1 := squin .wire .Apply (t .result , v0 .results [0 ])),
60+ (v2 := squin .wire .Apply (x .result , v1 .results [0 ])),
61+ (func .Return (v2 .results [0 ])),
62+ ]
63+
64+ constructed_method = gen_func_from_stmts (stmts )
65+
66+ nsites_frame , _ = nsites .NSitesAnalysis (constructed_method .dialects ).run_analysis (
67+ constructed_method , no_raise = False
68+ )
69+
70+ has_n_sites = []
71+ for nsites_type in nsites_frame .entries .values ():
72+ if isinstance (nsites_type , nsites .HasNSites ):
73+ has_n_sites .append (nsites_type )
74+ assert nsites_type .sites == 1
75+
76+ assert len (has_n_sites ) == 3
4677
4778
4879# Kron, Mult, Control, Rot, and Scale all have methods defined for handling them in impls,
0 commit comments