void FullGateWriterImpl::write(GatePtr pGate, std::ostream& outputStream) { std::string delimeter = "*"; outputStream << "Gate:"; unsigned int nbSeq = pGate->getLabelSeq().size(); for(unsigned int i = 0; i < nbSeq; i++) { outputStream << pGate->getLabelSeq()[i]; if(i < nbSeq - 1) { outputStream << delimeter; } } outputStream << std::endl; outputStream << "--Gate cost:" << pGate->getCost(); outputStream << std::endl; outputStream << "--Gate matrix:" << std::endl; MatrixPtr pMatrix = pGate->getMatrix(); int nbRows, nbColumns; pMatrix->getSize(nbRows, nbColumns); for(int i = 0; i < nbRows; i++) { for(int j = 0; j < nbColumns; j++) { char printfBuffer[PRINT_BUFFER_LENGTH]; ComplexVal val = pMatrix->getValue(i,j); printVal(printfBuffer, val); outputStream << printfBuffer; } outputStream << std::endl; } }
bool checkIdentity(MatrixPtr pMatrix) { int nbRows, nbColums; pMatrix->getSize(nbRows, nbColums); for(int row = 0; row < nbRows; row++) { for(int column = 0; column < nbColums; column++) { ComplexVal v = pMatrix->getValue(row, column); ComplexVal identityElement = (row == column) ? (ComplexVal)1.0 : (ComplexVal)0.0; //If matrix[row][column] differs from I[row][column], consider matrix is not identity mreal_t err = std::norm(v - identityElement); if(err > IDENTITY_NOISE_THRESOLD) { return true; } } } return false; }