MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / demo_setSuperOp

Function demo_setSuperOp

examples/isolated/initialising_superoperators.cpp:64–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62
63
64void demo_setSuperOp() {
65
66 // inline literal (C++ only)
67 SuperOp a = createSuperOp(1);
68 setSuperOp(a, {
69 {1,2,3,4},
70 {5,0.0000000006-(10E-11) * 3.14_i,7,8},
71 {9,10,11,12},
72 {13,14,15,16+1.23_i}});
73 reportSuperOp(a);
74 destroySuperOp(a);
75
76 // 2D vector (C++ only)
77 vector<vector<qcomp>> vec {
78 {-9,-8, -8, -9},
79 {7, 7, 6, 6},
80 {0, -1, -2, -3},
81 {-4_i, -5_i, 0, 0}
82 };
83 SuperOp b = createSuperOp(1);
84 setSuperOp(b, vec);
85 reportSuperOp(b);
86 destroySuperOp(b);
87
88 // nested pointers
89 int n = 3;
90 int d = 1 << (2*n);
91 qcomp** ptrs = (qcomp**) malloc(d * sizeof *ptrs);
92 for (int i=0; i<d; i++) {
93 ptrs[i] = (qcomp*) malloc(d * sizeof **ptrs);
94 for (int j=0; j<d; j++)
95 ptrs[i][j] = (j==5)*(i + j*1_i);
96 }
97 SuperOp c = createSuperOp(n);
98 setSuperOp(c, ptrs);
99 reportSuperOp(c);
100 destroySuperOp(c);
101
102 // array of pointers (decays, so C++ supported too)
103 qcomp* ptrArr[64];
104 for (int i=0; i<d; i++)
105 ptrArr[i] = ptrs[i];
106 SuperOp e = createSuperOp(n);
107 setSuperOp(e, ptrArr);
108 reportSuperOp(e);
109 destroySuperOp(e);
110
111 // cleanup
112 for (int i=0; i<d; i++)
113 free(ptrs[i]);
114 free(ptrs);
115}
116
117
118void demo_syncSuperOp() {

Callers 1

mainFunction · 0.70

Calls 4

createSuperOpFunction · 0.85
setSuperOpFunction · 0.85
reportSuperOpFunction · 0.85
destroySuperOpFunction · 0.85

Tested by

no test coverage detected