14
14
15
15
#define DEBUG_TYPE " ppm_specs"
16
16
17
- #include " mlir/Analysis/SliceAnalysis.h"
17
+ #include < algorithm>
18
+ #include < string>
19
+
20
+ #include < nlohmann/json.hpp>
21
+
18
22
#include " mlir/IR/PatternMatch.h"
19
23
#include " mlir/Pass/Pass.h"
20
- #include " mlir/Transforms/GreedyPatternRewriteDriver.h"
21
-
22
24
23
25
#include " QEC/IR/QECDialect.h"
24
- #include " QEC/Transforms/Patterns.h"
25
- #include " Quantum/IR/QuantumOps.h"
26
- #include " QEC/Utils/PauliStringWrapper.h"
27
- #include < algorithm>
28
- #include < string>
29
26
30
27
using namespace llvm ;
31
28
using namespace mlir ;
32
29
using namespace catalyst ;
33
30
using namespace catalyst ::qec;
31
+ using json = nlohmann::json;
34
32
35
33
namespace catalyst {
36
34
namespace qec {
@@ -39,7 +37,6 @@ namespace qec {
39
37
#define GEN_PASS_DECL_COUNTPPMSPECSPASS
40
38
#include " QEC/Transforms/Passes.h.inc"
41
39
42
-
43
40
struct CountPPMSpecsPass : public impl ::CountPPMSpecsPassBase<CountPPMSpecsPass> {
44
41
using CountPPMSpecsPassBase::CountPPMSpecsPassBase;
45
42
@@ -55,11 +52,6 @@ struct CountPPMSpecsPass : public impl::CountPPMSpecsPassBase<CountPPMSpecsPass>
55
52
// Skip top-level container ops if desired
56
53
if (isa<ModuleOp>(op)) return ;
57
54
58
- // TODO: Remove debug in future
59
- // llvm::outs()<<"\n-----------------------------MLIR------------------------------\n";
60
- // op->print(llvm::outs());
61
- // llvm::outs()<<"\n-----------------------------MLIR------------------------------\n";
62
-
63
55
StringRef gate_name = op->getName ().getStringRef ();
64
56
65
57
if (gate_name == " quantum.alloc" ) {
@@ -69,7 +61,7 @@ struct CountPPMSpecsPass : public impl::CountPPMSpecsPassBase<CountPPMSpecsPass>
69
61
}
70
62
71
63
if (gate_name == " qec.ppm" ) {
72
- PPM_Specs[" num_of_ppm" ] = PPM_Specs[ " num_of_ppm " ] + 1 ;
64
+ PPM_Specs[" num_of_ppm" ]++ ;
73
65
}
74
66
75
67
if (gate_name == " qec.ppr" ) {
@@ -86,29 +78,15 @@ struct CountPPMSpecsPass : public impl::CountPPMSpecsPassBase<CountPPMSpecsPass>
86
78
PPM_Specs[max_weight_pi_key] = static_cast <int >(pauli_product_attr.size ());
87
79
}
88
80
else {
89
- PPM_Specs[num_pi_key] = PPM_Specs[num_pi_key] + 1 ;
81
+ PPM_Specs[num_pi_key]++ ;
90
82
PPM_Specs[max_weight_pi_key] = std::max (PPM_Specs[max_weight_pi_key], static_cast <int >(pauli_product_attr.size ()));
91
83
}
92
84
}
93
85
}
94
- // TODO: Implement depth using slicing
95
- // mlir::SetVector <Operation *> backwardSlice;
96
- // getBackwardSlice(op, &backwardSlice);
97
- // llvm::outs()<<"\n-----------------------------SLICE-----------------------------\n";
98
- // llvm::outs()<<"Backward slicing\n";
99
- // for (Operation *o : backwardSlice) {
100
- // if (o->getName().getStringRef() == "quantum.extract") {
101
- // llvm::outs() << *o << "\n";
102
- // }
103
- // }
104
- // llvm::outs()<<"\n-----------------------------SLICE------------------------------\n";
105
86
});
106
87
107
- llvm::outs () << " {\n " ;
108
- for (const auto &entry : PPM_Specs) {
109
- llvm::outs () << ' "' << entry.first << ' "' << " :" << entry.second << " ,\n " ;
110
- }
111
- llvm::outs () << " }\n " ;
88
+ json PPM_Specs_Json = PPM_Specs;
89
+ llvm::outs () << PPM_Specs_Json.dump (4 ) << " \n " ;
112
90
return ;
113
91
}
114
92
0 commit comments