#include "cli.h" #include "entrypoints.h" #include "../utility/storm.h" #include "src/storage/SymbolicModelDescription.h" #include "src/settings/modules/DebugSettings.h" #include "src/settings/modules/IOSettings.h" #include "src/settings/modules/CoreSettings.h" #include "src/exceptions/OptionParserException.h" #include "src/settings/modules/JaniExportSettings.h" #include "src/utility/storm-version.h" #include "src/storage/jani/JSONExporter.h" // Includes for the linked libraries and versions header. #ifdef STORM_HAVE_INTELTBB # include "tbb/tbb_stddef.h" #endif #ifdef STORM_HAVE_GLPK # include "glpk.h" #endif #ifdef STORM_HAVE_GUROBI # include "gurobi_c.h" #endif #ifdef STORM_HAVE_Z3 # include "z3.h" #endif #ifdef STORM_HAVE_MSAT # include "mathsat.h" #endif #ifdef STORM_HAVE_CUDA #include #include #endif #ifdef STORM_HAVE_SMTRAT #include "lib/smtrat.h" #endif namespace storm { namespace cli { std::string getCurrentWorkingDirectory() { char temp[512]; return (GetCurrentDir(temp, 512 - 1) ? std::string(temp) : std::string("")); } void printHeader(const std::string name, const int argc, const char* argv[]) { std::cout << name << std::endl; std::cout << "---------------" << std::endl << std::endl; std::cout << storm::utility::StormVersion::longVersionString() << std::endl; #ifdef STORM_HAVE_INTELTBB std::cout << "Linked with Intel Threading Building Blocks v" << TBB_VERSION_MAJOR << "." << TBB_VERSION_MINOR << " (Interface version " << TBB_INTERFACE_VERSION << ")." << std::endl; #endif #ifdef STORM_HAVE_GLPK std::cout << "Linked with GNU Linear Programming Kit v" << GLP_MAJOR_VERSION << "." << GLP_MINOR_VERSION << "." << std::endl; #endif #ifdef STORM_HAVE_GUROBI std::cout << "Linked with Gurobi Optimizer v" << GRB_VERSION_MAJOR << "." << GRB_VERSION_MINOR << "." << GRB_VERSION_TECHNICAL << "." << std::endl; #endif #ifdef STORM_HAVE_Z3 unsigned int z3Major, z3Minor, z3BuildNumber, z3RevisionNumber; Z3_get_version(&z3Major, &z3Minor, &z3BuildNumber, &z3RevisionNumber); std::cout << "Linked with Microsoft Z3 Optimizer v" << z3Major << "." << z3Minor << " Build " << z3BuildNumber << " Rev " << z3RevisionNumber << "." << std::endl; #endif #ifdef STORM_HAVE_MSAT char* msatVersion = msat_get_version(); std::cout << "Linked with " << msatVersion << "." << std::endl; msat_free(msatVersion); #endif #ifdef STORM_HAVE_SMTRAT std::cout << "Linked with SMT-RAT " << SMTRAT_VERSION << "." << std::endl; #endif #ifdef STORM_HAVE_CARL std::cout << "Linked with CARL." << std::endl; // TODO get version string #endif #ifdef STORM_HAVE_CUDA int deviceCount = 0; cudaError_t error_id = cudaGetDeviceCount(&deviceCount); if (error_id == cudaSuccess) { std::cout << "Compiled with CUDA support, "; // This function call returns 0 if there are no CUDA capable devices. if (deviceCount == 0) { std::cout<< "but there are no available device(s) that support CUDA." << std::endl; } else { std::cout << "detected " << deviceCount << " CUDA Capable device(s):" << std::endl; } int dev, driverVersion = 0, runtimeVersion = 0; for (dev = 0; dev < deviceCount; ++dev) { cudaSetDevice(dev); cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, dev); std::cout << "CUDA Device " << dev << ": \"" << deviceProp.name << "\"" << std::endl; // Console log cudaDriverGetVersion(&driverVersion); cudaRuntimeGetVersion(&runtimeVersion); std::cout << " CUDA Driver Version / Runtime Version " << driverVersion / 1000 << "." << (driverVersion % 100) / 10 << " / " << runtimeVersion / 1000 << "." << (runtimeVersion % 100) / 10 << std::endl; std::cout << " CUDA Capability Major/Minor version number: " << deviceProp.major<<"."<(uLargeInteger.QuadPart) / 10000.0; // 100 ns Resolution to milliseconds uLargeInteger.LowPart = ftUser.dwLowDateTime; uLargeInteger.HighPart = ftUser.dwHighDateTime; double userTime = static_cast(uLargeInteger.QuadPart) / 10000.0; std::cout << "CPU Time: " << std::endl; std::cout << "\tKernel Time: " << std::setprecision(5) << kernelTime << "ms" << std::endl; std::cout << "\tUser Time: " << std::setprecision(5) << userTime << "ms" << std::endl; #endif } bool parseOptions(const int argc, const char* argv[]) { try { storm::settings::mutableManager().setFromCommandLine(argc, argv); } catch (storm::exceptions::OptionParserException& e) { storm::settings::manager().printHelp(); throw e; return false; } if (storm::settings::getModule().isHelpSet()) { storm::settings::manager().printHelp(storm::settings::getModule().getHelpModuleName()); return false; } if (storm::settings::getModule().isVersionSet()) { storm::settings::manager().printVersion(); return false; } if (storm::settings::getModule().isVerboseSet()) { storm::utility::setLogLevel(l3pp::LogLevel::INFO); } if (storm::settings::getModule().isDebugSet()) { storm::utility::setLogLevel(l3pp::LogLevel::DEBUG); } if (storm::settings::getModule().isTraceSet()) { storm::utility::setLogLevel(l3pp::LogLevel::TRACE); } if (storm::settings::getModule().isLogfileSet()) { storm::utility::initializeFileLogging(); } return true; } void processOptions() { if (storm::settings::getModule().isLogfileSet()) { storm::utility::initializeFileLogging(); } auto ioSettings = storm::settings::getModule(); if (ioSettings.isPrismOrJaniInputSet()) { storm::storage::SymbolicModelDescription model; if (ioSettings.isPrismInputSet()) { model = storm::parseProgram(ioSettings.getPrismInputFilename()); if (ioSettings.isPrismToJaniSet()) { model = model.toJani(true); } } else if (ioSettings.isJaniInputSet()) { model = storm::parseJaniModel(ioSettings.getJaniInputFilename()).first; } // Then proceed to parsing the properties (if given), since the model we are building may depend on the property. std::vector> formulas; if (storm::settings::getModule().isPropertySet()) { if (model.isJaniModel()) { formulas = storm::parseFormulasForJaniModel(storm::settings::getModule().getProperty(), model.asJaniModel()); } else { formulas = storm::parseFormulasForPrismProgram(storm::settings::getModule().getProperty(), model.asPrismProgram()); } } if(model.isJaniModel() && storm::settings::getModule().isJaniFileSet()) { if (storm::settings::getModule().isExportAsStandardJaniSet()) { storm::jani::Model normalisedModel = storm::jani::Model(model.asJaniModel()); normalisedModel.makeStandardJaniCompliant(); storm::jani::JsonExporter::toFile(normalisedModel, formulas, storm::settings::getModule().getJaniFilename()); } else { storm::jani::JsonExporter::toFile(model.asJaniModel(), formulas, storm::settings::getModule().getJaniFilename()); } } // Get the string that assigns values to the unknown currently undefined constants in the model. std::string constantDefinitionString = ioSettings.getConstantDefinitionString(); model = model.preprocess(constantDefinitionString); if (storm::settings::getModule().isParametricSet()) { #ifdef STORM_HAVE_CARL buildAndCheckSymbolicModel(model, formulas, true); #else STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "No parameters are supported in this build."); #endif } else if (storm::settings::getModule().isExactSet()) { #ifdef STORM_HAVE_CARL buildAndCheckSymbolicModel(model, formulas, true); #else STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "No exact numbers are supported in this build."); #endif } else { buildAndCheckSymbolicModel(model, formulas, true); } } else if (storm::settings::getModule().isExplicitSet()) { STORM_LOG_THROW(storm::settings::getModule().getEngine() == storm::settings::modules::CoreSettings::Engine::Sparse, storm::exceptions::InvalidSettingsException, "Only the sparse engine supports explicit model input."); // If the model is given in an explicit format, we parse the properties without allowing expressions // in formulas. std::vector> formulas; if (storm::settings::getModule().isPropertySet()) { formulas = storm::parseFormulasForExplicit(storm::settings::getModule().getProperty()); } buildAndCheckExplicitModel(formulas, true); } else { STORM_LOG_THROW(false, storm::exceptions::InvalidSettingsException, "No input model."); } } } }