1919
2020It was initially generated by xDSL (using the ``xdsl-tblgen`` tool) starting from the
2121catalyst/mlir/include/MBQC/IR/MBQCDialect.td file in the catalyst repository.
22+
23+ For detailed documentation on the operations contained in this dialect, please refer to the MBQC
24+ dialect documentation in Catalyst.
2225"""
2326
2427from typing import TypeAlias
2528
26- from xdsl .dialects .builtin import I32 , Float64Type , IntegerAttr , IntegerType
29+ from xdsl .dialects .builtin import (
30+ I32 ,
31+ AnyAttr ,
32+ Float64Type ,
33+ IntegerAttr ,
34+ IntegerType ,
35+ MemRefType ,
36+ StringAttr ,
37+ TensorType ,
38+ i1 ,
39+ )
2740from xdsl .ir import Dialect , EnumAttribute , Operation , SpacedOpaqueSyntaxAttribute , SSAValue
2841from xdsl .irdl import (
2942 IRDLOperation ,
3750from xdsl .utils .exceptions import VerifyException
3851from xdsl .utils .str_enum import StrEnum # StrEnum is standard in Python>=3.11
3952
40- from .quantum import QubitType
53+ from ..xdsl_extras import MemRefRankConstraint , TensorRankConstraint
54+ from .quantum import QubitType , QuregType
4155
4256QubitSSAValue : TypeAlias = SSAValue [QubitType ]
4357
@@ -69,6 +83,10 @@ class MeasureInBasisOp(IRDLOperation):
6983
7084 name = "mbqc.measure_in_basis"
7185
86+ assembly_format = """
87+ `[` $plane `,` $angle `]` $in_qubit (`postselect` $postselect^)? attr-dict `:` type(results)
88+ """
89+
7290 in_qubit = operand_def (QubitType )
7391
7492 plane = prop_def (MeasurementPlaneAttr )
@@ -81,10 +99,6 @@ class MeasureInBasisOp(IRDLOperation):
8199
82100 out_qubit = result_def (QubitType )
83101
84- assembly_format = """
85- `[` $plane `,` $angle `]` $in_qubit (`postselect` $postselect^)? attr-dict `:` type(results)
86- """
87-
88102 def __init__ (
89103 self ,
90104 in_qubit : QubitSSAValue | Operation ,
@@ -115,10 +129,54 @@ def verify_(self):
115129 raise VerifyException ("'postselect' must be 0 or 1." )
116130
117131
132+ @irdl_op_definition
133+ class GraphStatePrepOp (IRDLOperation ):
134+ """Allocate resources for a new graph state."""
135+
136+ # pylint: disable=too-few-public-methods
137+
138+ name = "mbqc.graph_state_prep"
139+
140+ assembly_format = """
141+ `(` $adj_matrix `:` type($adj_matrix) `)` `[` `init` $init_op `,` `entangle` $entangle_op `]` attr-dict `:` type(results)
142+ """
143+
144+ adj_matrix = operand_def (
145+ (TensorType .constr (i1 ) & TensorRankConstraint (1 ))
146+ | (MemRefType .constr (i1 ) & MemRefRankConstraint (1 ))
147+ )
148+
149+ init_op = prop_def (StringAttr )
150+
151+ entangle_op = prop_def (StringAttr )
152+
153+ qreg = result_def (QuregType )
154+
155+ def __init__ (
156+ self , adj_matrix : AnyAttr , init_op : str | StringAttr , entangle_op : str | StringAttr
157+ ):
158+ if isinstance (init_op , str ):
159+ init_op = StringAttr (data = init_op )
160+
161+ if isinstance (entangle_op , str ):
162+ entangle_op = StringAttr (data = entangle_op )
163+
164+ properties = {"init_op" : init_op , "entangle_op" : entangle_op }
165+
166+ qreg = QuregType ()
167+
168+ super ().__init__ (
169+ operands = (adj_matrix ,),
170+ result_types = (qreg ,),
171+ properties = properties ,
172+ )
173+
174+
118175MBQC = Dialect (
119176 "mbqc" ,
120177 [
121178 MeasureInBasisOp ,
179+ GraphStatePrepOp ,
122180 ],
123181 [
124182 MeasurementPlaneAttr ,
0 commit comments