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

Function getRandomKrausMap

tests/utils/random.cpp:405–431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

403
404
405vector<qmatrix> getRandomKrausMap(int numQb, int numOps) {
406 DEMAND( numOps >= 1 );
407
408 // generate random unitaries
409 vector<qmatrix> ops(numOps);
410 for (auto& u : ops)
411 u = getRandomUnitary(numQb);
412
413 // generate random weights
414 vector<qreal> weights(numOps);
415 for (auto& w : weights)
416 w = getRandomReal(0, 1);
417
418 // normalise random weights
419 qreal sum = 0;
420 for (auto& w : weights)
421 sum += w;
422 for (auto& w : weights)
423 w = std::sqrt(w/sum);
424
425 // normalise unitaries according to weights
426 for (int i=0; i<numOps; i++)
427 ops[i] *= weights[i];
428
429 DEMAND( isApproxCPTP(ops) );
430 return ops;
431}
432
433
434

Callers 2

SECTIONFunction · 0.50
SECTIONFunction · 0.50

Calls 3

isApproxCPTPFunction · 0.85
getRandomUnitaryFunction · 0.70
getRandomRealFunction · 0.70

Tested by

no test coverage detected