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

Function getRandomKrausMap

tests/deprecated/test_utilities.cpp:713–751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

711}
712
713vector<QMatrix> getRandomKrausMap(int numQb, int numOps) {
714 DEMAND( numOps >= 1 );
715 DEMAND( numOps <= 4*numQb*numQb );
716
717 // generate random unitaries
718 vector<QMatrix> ops;
719 for (int i=0; i<numOps; i++)
720 ops.push_back(getRandomUnitary(numQb));
721
722 // generate random weights
723 vector<qreal> weights(numOps);
724 for (int i=0; i<numOps; i++)
725 weights[i] = getRandomReal(0, 1);
726
727 // normalise random weights
728 qreal weightSum = 0;
729 for (int i=0; i<numOps; i++)
730 weightSum += weights[i];
731 for (int i=0; i<numOps; i++)
732 weights[i] = sqrt((qreal) weights[i]/weightSum);
733
734 // normalise ops
735 for (int i=0; i<numOps; i++)
736 ops[i] *= weights[i];
737
738 // check what we produced was a valid Kraus map
739 QMatrix iden = getIdentityMatrix(1 << numQb);
740 QMatrix prodSum = getZeroMatrix(1 << numQb);
741 for (int i=0; i<numOps; i++)
742 prodSum += getConjugateTranspose(ops[i]) * ops[i];
743
744 // in the rare scenario it is insufficiently numerically precise,
745 // replace the map with trivially precise diagonals
746 if( ! areEqual(prodSum, iden) )
747 for (int i=0; i<numOps; i++)
748 ops[i] = weights[i] * getRandomDiagonalUnitary(numQb);
749
750 return ops;
751}
752
753vector<QVector> getRandomOrthonormalVectors(int numQb, int numStates) {
754 DEMAND( numQb >= 1 );

Callers 1

Calls 7

areEqualFunction · 0.85
getRandomUnitaryFunction · 0.70
getRandomRealFunction · 0.70
getIdentityMatrixFunction · 0.70
getZeroMatrixFunction · 0.70
getConjugateTransposeFunction · 0.70
getRandomDiagonalUnitaryFunction · 0.70

Tested by

no test coverage detected