void AIManager::startAIUpdate() { try { auto frameStartTime = std::chrono::high_resolution_clock::now(); while (continueExecution()) { processAIUpdate(); auto frameEndTime = std::chrono::high_resolution_clock::now(); auto diffTimeMicroSeconds = std::chrono::duration_cast<std::chrono::microseconds>(frameEndTime - frameStartTime).count(); float remainingTime = timeStep - (diffTimeMicroSeconds / 1000000.0); if (remainingTime >= 0.0f) { std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(remainingTime * 1000.0f))); frameStartTime = std::chrono::high_resolution_clock::now(); } else { frameStartTime = frameEndTime; } } }catch(std::exception &e) { Logger::logger().logError("Error cause AI thread crash: exception reported to main thread"); aiThreadExceptionPtr = std::current_exception(); } }
void LLCCEP_debugger::debugCore::executeProgram() { DEBUG_CORE_OK; continueExecution(); DEBUG_CORE_OK; }
bool GradientAscent1D::singleStep() { float newX = nextX(); std::tuple<float, float> funcOutput = (*(config->f))(newX); previousx = currentx; previousdx = currentdx; currentx = newX; currentdx = std::get<1>(funcOutput); currentVal = std::get<0>(funcOutput); // Decrease temperature when derivative flips sign if (sign(previousdx) == -1 * sign(currentdx)) { temperature *= config->temperatureDescent; } iterationCount++; return continueExecution(); }
bool QDeclarativeViewObserver::keyReleaseEvent(QKeyEvent *event) { if (!data->designModeBehavior) return false; switch(event->key()) { case Qt::Key_V: data->_q_changeToSingleSelectTool(); break; // disabled because multiselection does not do anything useful without design mode // case Qt::Key_M: // data->_q_changeToMarqueeSelectTool(); // break; case Qt::Key_I: data->_q_changeToColorPickerTool(); break; case Qt::Key_Z: data->_q_changeToZoomTool(); break; case Qt::Key_Enter: case Qt::Key_Return: if (!data->selectedItems().isEmpty()) data->subcomponentEditorTool->setCurrentItem(data->selectedItems().first()); break; case Qt::Key_Space: if (data->executionPaused) { continueExecution(data->slowdownFactor); } else { pauseExecution(); } break; default: break; } data->currentTool->keyReleaseEvent(event); return true; }
void AutoImportWindow::importImage() { if(continuous->isChecked()) { analyzeImport(true); } if(toBeImported_.isEmpty()) { finishExecution(); return; } if (imageExecuting_) { QString numberExec = imageExecuting_->directory(); if (!numberExec.isEmpty()) { if (dirToRowNumber_.keys().contains(numberExec)) { if (dirToRowNumber_[numberExec] < resultsTable_->rowCount()) { if (resultsTable_->item(dirToRowNumber_[numberExec], 0)) { resultsTable_->item(dirToRowNumber_[numberExec], 0)->setIcon(ApplicationData::icon("process_done")); } } } } } QString number; number = toBeImported_.keys().first(); QStringList files = toBeImported_[number]; toBeImported_.remove(number); //Get the original file name used for search QString baseName = files.first(); //Deduce parameters from baseName QMap<QString, QString> fileNameParams = FileNameParserDialog::parseFileName(baseName); QString importGroup_ = projectData.projectParameterData()->getValue("import_target_group"); QString importGroupSuffix = projectData.projectParameterData()->getValue("import_target_group_suffix"); //Add suffix to group name QString suffix = ""; //case importGroupSuffix=1 => parameter = specimennumber if(importGroupSuffix == "1") { //If the file name contains this param take it from there, otherwise search master.cfg if(fileNameParams.contains("specimennumber")) suffix = fileNameParams["specimennumber"]; else { suffix = projectData.projectParameterData()->getValue("specimennumber"); } } if(suffix == "-") suffix = ""; importGroup_ = importGroup_ + suffix; if (dirToRowNumber_.keys().contains(number)) { if (dirToRowNumber_[number] < resultsTable_->rowCount()) { if(resultsTable_->item(dirToRowNumber_[number], 0)) { resultsTable_->item(dirToRowNumber_[number], 0)->setIcon(ApplicationData::icon("process_executing")); resultsTable_->scrollToItem(resultsTable_->item(dirToRowNumber_[number], 0)); } } } statusLabel_->setText(QString("Currently importing and %2 are in queue...").arg(toBeImported_.keys().size())); projectData.projectParameterData()->set("import_imagenumber", number); //Create dir QDir workingDir = QDir(projectData.projectDir().canonicalPath() + "/" + importGroup_ + "/" + number); //create import group projectData.projectDir().mkpath(importGroup_); QFile(projectData.projectDir().absolutePath() + "/merge").link("../2dx_master.cfg", projectData.projectDir().absolutePath() + "/" + importGroup_ + "/2dx_master.cfg"); //create Dir projectData.projectDir().mkpath(importGroup_ + "/" + number); workingDir.mkpath("proc"); workingDir.mkpath("LOGS"); //Copy Config File projectData.projectParameterData()->saveAs(workingDir.canonicalPath() + "/2dx_image.cfg", true); imageExecuting_ = projectData.addImage(importGroup_, number); ParametersConfiguration* conf = imageExecuting_->parameters(); conf->set("imagenumber", number, false); bool hasAveraged = false; bool hasAligned = false; bool hasRaw = false; //Check for the averaged file if(files.size() > 1 && !files[1].isEmpty()) { conf->set("imagename", "image_2dx", false); conf->set("nonmaskimagename", "image_2dx", false); conf->set("imagename_original", files[1], false); conf->set("import_original_time", QString::number(QFileInfo(files[1]).created().toMSecsSinceEpoch()), false); scriptsToBeExecuted_.append("cp -f " + files[1] + " " + workingDir.canonicalPath() + "/" + "image_2dx.mrc"); if(deleteCheck->isChecked()) scriptsToBeExecuted_.append("rm -f " + files[1]); hasAveraged = true; } //Check for aligned file if (files.size() > 2 && !files[2].isEmpty()) { conf->set("movie_stackname", "movie_aligned", false); conf->set("movie_stackname_original", files[2], false); conf->set("import_original_time", QString::number(QFileInfo(files[2]).created().toMSecsSinceEpoch()), false); scriptsToBeExecuted_.append("cp -f " + files[2] + " " + workingDir.canonicalPath() + "/" + "movie_aligned.mrcs"); if(deleteCheck->isChecked()) scriptsToBeExecuted_.append("rm -f " + files[2]); hasAligned = true; } //Check for raw file if (files.size() > 3 && !files[3].isEmpty()) { int rawOption = conf->getVariant("import_rawstack_type").toInt(); if(rawOption == 1) { conf->set("import_rawstack", baseName + '.' + QFileInfo(files[3]).suffix(), false); conf->set("import_rawstack_original", files[3], false); conf->set("import_original_time", QString::number(QFileInfo(files[3]).created().toMSecsSinceEpoch()), false); scriptsToBeExecuted_.append("cp -f " + files[3] + " " + workingDir.canonicalPath() + "/" + baseName + '.' + QFileInfo(files[3]).suffix()); if(deleteCheck->isChecked()) scriptsToBeExecuted_.append("rm -f " + files[3]); hasRaw = true; } else if (rawOption == 2) { conf->set("import_rawstack", baseName + '.' + QFileInfo(files[3]).suffix(), false); conf->set("import_rawstack_original", files[3], false); conf->set("raw_gaincorrectedstack", "raw_gaincorrectedstack", false); conf->set("raw_gaincorrectedstack_original", files[3], false); conf->set("import_original_time", QString::number(QFileInfo(files[3]).created().toMSecsSinceEpoch()), false); scriptsToBeExecuted_.append("cp -f " + files[3] + " " + workingDir.canonicalPath() + "/" + "raw_gaincorrectedstack.mrcs"); if(deleteCheck->isChecked()) scriptsToBeExecuted_.append("rm -f " + files[3]); hasRaw = true; } } //Check for defects list file QString defectsFile = conf->getValue("import_defects_original"); if(QFileInfo(defectsFile).exists()) { conf->set("import_defects", "../" + QFileInfo(defectsFile).fileName(), false); scriptsToBeExecuted_.append("rsync -auvP " + defectsFile + " " + workingDir.canonicalPath() + "/../" + QFileInfo(defectsFile).fileName()); } //Check for gain reference file QString gainRefFile = conf->getValue("import_gainref_original"); if(QFileInfo(gainRefFile).exists()) { conf->set("import_gainref", "../" + QFileInfo(gainRefFile).fileName(), false); scriptsToBeExecuted_.append("rsync -auvP " + gainRefFile + " " + workingDir.canonicalPath() + "/../" + QFileInfo(gainRefFile).fileName()); } //Set the parameters from filename for(QString param : fileNameParams.keys()) { if(parameterMaster.containsParameter(param)) { conf->set(param, fileNameParams[param], false); //qDebug() << "Parameter set: " << param << " => " << fileNameParams[param]; } } conf->setModified(true); //Write to status folder if required if(userPreferenceData.get("status_folder_update") == "y" && QFileInfo(userPreferenceData.get("status_folder")).isDir()) { long currentMSecs = conf->getValue("import_original_time").toLong(); //Write the last imported data QFile saveFile(userPreferenceData.get("status_folder") + "/last.txt"); long lastMSecs = 0; if(saveFile.exists()) { if (saveFile.open(QIODevice::ReadOnly | QIODevice::Text)) { while (!saveFile.atEnd()) { lastMSecs = QString(saveFile.readLine().simplified()).toLong(); } saveFile.close(); } saveFile.remove(); } QString toBeWritten; if(currentMSecs >= lastMSecs) toBeWritten = QString::number(currentMSecs); else toBeWritten = QString::number(lastMSecs); if (saveFile.open(QIODevice::WriteOnly | QIODevice::Text)) { saveFile.write(toBeWritten.toLatin1()); } saveFile.close(); //Write the time stamp in the last hour processed data ProjectData::writeStatisticsToStatusFolder("last_recorded.txt", currentMSecs); ProjectData::writeStatisticsToStatusFolder("last_imported.txt"); } //register that this image was imported ImportFolderSettings(QDir(conf->getValue("import_dir"))).addImportedImage(baseName, importGroup_ + "/" + number, hasAveraged, hasAligned, hasRaw); //Add the scripts to be executed during import QStringList scripts = importSelectorDialog.scriptPaths(ProjectPreferences().scripts("import")); for(QString script : scripts) { if(!script.isEmpty()) scriptsToBeExecuted_.append("SCRIPT:" + script); } continueExecution(); }
void GradientAscent1D::execute() { while (continueExecution()) { singleStep(); } }