11from kirin import ir , interp as _interp
2- from kirin .analysis import const
2+ from kirin .analysis import ForwardFrame , const
33from kirin .dialects import scf , func
44
55from bloqade .squin import gate
6- from bloqade .validation .analysis import ValidationFrame
7- from bloqade .validation .analysis .lattice import Error
86
9- from .analysis import GeminiLogicalValidationAnalysis
7+ from .analysis import _GeminiLogicalValidationAnalysis
108
119
1210@scf .dialect .register (key = "gemini.validate.logical" )
@@ -15,87 +13,82 @@ class __ScfGeminiLogicalValidation(_interp.MethodTable):
1513 @_interp .impl (scf .IfElse )
1614 def if_else (
1715 self ,
18- interp : GeminiLogicalValidationAnalysis ,
19- frame : ValidationFrame ,
16+ interp : _GeminiLogicalValidationAnalysis ,
17+ frame : ForwardFrame ,
2018 stmt : scf .IfElse ,
2119 ):
22- frame .errors .append (
20+ interp .add_validation_error (
21+ stmt ,
2322 ir .ValidationError (
2423 stmt , "If statements are not supported in logical Gemini programs!"
25- )
26- )
27- return (
28- Error (
29- message = "If statements are not supported in logical Gemini programs!"
3024 ),
3125 )
26+ return (interp .lattice .bottom (),)
3227
3328 @_interp .impl (scf .For )
3429 def for_loop (
3530 self ,
36- interp : GeminiLogicalValidationAnalysis ,
37- frame : ValidationFrame ,
31+ interp : _GeminiLogicalValidationAnalysis ,
32+ frame : ForwardFrame ,
3833 stmt : scf .For ,
3934 ):
40- if isinstance (stmt .iterable .hints .get ("const" ), const .Value ):
41- return (interp .lattice .top (),)
35+ if not isinstance (stmt .iterable .hints .get ("const" ), const .Value ):
4236
43- frame .errors .append (
44- ir .ValidationError (
37+ interp .add_validation_error (
4538 stmt ,
46- "Non-constant iterable in for loop is not supported in Gemini logical programs!" ,
39+ ir .ValidationError (
40+ stmt ,
41+ "Non-constant iterable in for loop is not supported in Gemini logical programs!" ,
42+ ),
4743 )
48- )
4944
50- return (
51- Error (
52- message = "Non-constant iterable in for loop is not supported in Gemini logical programs!"
53- ),
54- )
45+ return (interp .lattice .bottom (),)
5546
5647
5748@func .dialect .register (key = "gemini.validate.logical" )
5849class __FuncGeminiLogicalValidation (_interp .MethodTable ):
5950 @_interp .impl (func .Invoke )
6051 def invoke (
6152 self ,
62- interp : GeminiLogicalValidationAnalysis ,
63- frame : ValidationFrame ,
53+ interp : _GeminiLogicalValidationAnalysis ,
54+ frame : ForwardFrame ,
6455 stmt : func .Invoke ,
6556 ):
66- frame .errors .append (
57+ interp .add_validation_error (
58+ stmt ,
6759 ir .ValidationError (
6860 stmt ,
6961 "Function invocations not supported in logical Gemini program!" ,
7062 help = "Make sure to decorate your function with `@logical(inline = True)` or `@logical(aggressive_unroll = True)` to inline function calls" ,
71- )
63+ ),
7264 )
7365
74- return tuple (
75- Error (
76- message = "Function invocations not supported in logical Gemini program!"
77- )
78- for _ in stmt .results
79- )
66+ return tuple (interp .lattice .bottom () for _ in stmt .results )
8067
8168
8269@gate .dialect .register (key = "gemini.validate.logical" )
8370class __GateGeminiLogicalValidation (_interp .MethodTable ):
71+
8472 @_interp .impl (gate .stmts .U3 )
85- def u3 (
73+ @_interp .impl (gate .stmts .T )
74+ @_interp .impl (gate .stmts .Rx )
75+ @_interp .impl (gate .stmts .Ry )
76+ @_interp .impl (gate .stmts .Rz )
77+ def non_clifford (
8678 self ,
87- interp : GeminiLogicalValidationAnalysis ,
88- frame : ValidationFrame ,
89- stmt : gate .stmts .U3 ,
79+ interp : _GeminiLogicalValidationAnalysis ,
80+ frame : ForwardFrame ,
81+ stmt : gate .stmts .SingleQubitGate | gate . stmts . RotationGate ,
9082 ):
9183 if interp .first_gate :
9284 interp .first_gate = False
9385 return ()
9486
95- frame .errors .append (
87+ interp .add_validation_error (
88+ stmt ,
9689 ir .ValidationError (
9790 stmt ,
98- "U3 gate can only be used for initial state preparation, i.e. as the first gate!" ,
99- )
91+ f"Non-clifford gate { stmt . name } can only be used for initial state preparation, i.e. as the first gate!" ,
92+ ),
10093 )
10194 return ()
0 commit comments