@@ -63,23 +63,23 @@ def NamedObservableAttr : EnumAttr<QuantumDialect, NamedObservable, "named_obser
6363
6464class Quantum_Op<string mnemonic, list<Trait> traits = []> : Op<QuantumDialect, mnemonic, traits>;
6565
66- def InitializeOp : Quantum_Op<"init"> {
66+ def InitializeOp : Quantum_Op<"init", [MemoryEffects<[MemAlloc<QuantumMemory>]>] > {
6767 let summary = "Initialize the quantum runtime.";
6868
6969 let assemblyFormat = [{
7070 attr-dict
7171 }];
7272}
7373
74- def FinalizeOp : Quantum_Op<"finalize"> {
74+ def FinalizeOp : Quantum_Op<"finalize", [MemoryEffects<[MemFree<QuantumMemory>]>] > {
7575 let summary = "Teardown the quantum runtime.";
7676
7777 let assemblyFormat = [{
7878 attr-dict
7979 }];
8080}
8181
82- def DeviceInitOp : Quantum_Op<"device"> {
82+ def DeviceInitOp : Quantum_Op<"device", [MemoryEffects<[MemAlloc<QuantumMemory>]>] > {
8383 let summary = "Initialize a quantum device.";
8484
8585 let arguments = (ins
@@ -95,7 +95,7 @@ def DeviceInitOp : Quantum_Op<"device"> {
9595
9696}
9797
98- def DeviceReleaseOp : Quantum_Op<"device_release"> {
98+ def DeviceReleaseOp : Quantum_Op<"device_release", [MemoryEffects<[MemFree<QuantumMemory>]>] > {
9999 let summary = "Release the active quantum device.";
100100
101101 let assemblyFormat = [{
@@ -172,7 +172,7 @@ def DeallocQubitOp : Memory_Op<"dealloc_qb"> {
172172 }];
173173}
174174
175- def DeallocOp : Memory_Op<"dealloc"> {
175+ def DeallocOp : Memory_Op<"dealloc", [MemoryEffects<[MemFree<QuantumMemory>]>] > {
176176 let summary = "Deallocate a quantum register.";
177177 let description = [{
178178 }];
@@ -856,7 +856,12 @@ def HamiltonianOp : Observable_Op<"hamiltonian"> {
856856class Measurement_Op<string mnemonic, list<Trait> traits = []> :
857857 Quantum_Op<mnemonic, traits # [MeasurementProcess]>;
858858
859- def MeasureOp : Quantum_Op<"measure"> {
859+ def MeasureOp : Quantum_Op<"measure",
860+ // Measurement both read and write since it collapses states
861+ // This is even more true for the mbqc variant, since that one's entire point
862+ // is to alter the state via measurement.
863+ [MemoryEffects<[MemRead<QuantumMemory>, MemWrite<QuantumMemory>]>]
864+ > {
860865 let summary = "A single-qubit projective measurement in the computational basis.";
861866 let description = [{
862867 }];
@@ -876,7 +881,7 @@ def MeasureOp : Quantum_Op<"measure"> {
876881 }];
877882}
878883
879- def SampleOp : Measurement_Op<"sample", [AttrSizedOperandSegments]> {
884+ def SampleOp : Measurement_Op<"sample", [AttrSizedOperandSegments, MemoryEffects<[MemAlloc]> ]> {
880885 let summary = "Sample eigenvalues from the given observable for the current state";
881886 let description = [{
882887 The `quantum.sample` operation represents the measurement process of sampling eigenvalues
@@ -942,7 +947,8 @@ def SampleOp : Measurement_Op<"sample", [AttrSizedOperandSegments]> {
942947 let hasVerifier = 1;
943948}
944949
945- def CountsOp : Measurement_Op<"counts", [AttrSizedOperandSegments, SameVariadicResultSize]> {
950+ def CountsOp : Measurement_Op<"counts", [AttrSizedOperandSegments, SameVariadicResultSize,
951+ MemoryEffects<[MemAlloc]>]> {
946952 let summary = "Compute sample counts for the given observable for the current state";
947953 let description = [{
948954 The `quantum.counts` operation represents the measurement process of sampling eigenvalues
@@ -1001,7 +1007,7 @@ def CountsOp : Measurement_Op<"counts", [AttrSizedOperandSegments, SameVariadicR
10011007 let hasVerifier = 1;
10021008}
10031009
1004- def ExpvalOp : Measurement_Op<"expval"> {
1010+ def ExpvalOp : Measurement_Op<"expval", [NoMemoryEffect] > {
10051011 let summary = "Compute the expectation value of the given observable for the current state";
10061012 let description = [{
10071013 The `quantum.expval` operation represents the measurement process of computing the
@@ -1038,7 +1044,7 @@ def ExpvalOp : Measurement_Op<"expval"> {
10381044 }];
10391045}
10401046
1041- def VarianceOp : Measurement_Op<"var"> {
1047+ def VarianceOp : Measurement_Op<"var", [NoMemoryEffect] > {
10421048 let summary = "Compute the variance of the given observable for the current state";
10431049 let description = [{
10441050 The `quantum.var` operation represents the measurement process of computing the variance of
@@ -1074,7 +1080,7 @@ def VarianceOp : Measurement_Op<"var"> {
10741080 }];
10751081}
10761082
1077- def ProbsOp : Measurement_Op<"probs", [AttrSizedOperandSegments]> {
1083+ def ProbsOp : Measurement_Op<"probs", [AttrSizedOperandSegments, MemoryEffects<[MemAlloc]> ]> {
10781084 let summary = "Compute computational basis probabilities for the current state";
10791085 let description = [{
10801086 The `quantum.probs` operation represents the measurement process of computing probabilities
@@ -1120,7 +1126,7 @@ def ProbsOp : Measurement_Op<"probs", [AttrSizedOperandSegments]> {
11201126 let hasVerifier = 1;
11211127}
11221128
1123- def StateOp : Measurement_Op<"state", [AttrSizedOperandSegments]> {
1129+ def StateOp : Measurement_Op<"state", [AttrSizedOperandSegments, MemoryEffects<[MemAlloc]> ]> {
11241130 let summary = "Return the current statevector";
11251131 let description = [{
11261132 The `quantum.state` operation represents the measurement process of returning the current
0 commit comments