bool Teuchos::haveSameValues( const ParameterList& list1, const ParameterList& list2 ) { // Check that the top-level names of the two parameter lists are the same //const std::string ¶mListName1 = list1.name(); //const std::string ¶mListName2 = list2.name(); //if ( paramListName1 != paramListName2 ) { // return false; //} ParameterList::ConstIterator itr1, itr2; for( itr1 = list1.begin(), itr2 = list2.begin(); itr1 != list1.end() && itr2 != list2.end(); ++itr1, ++itr2 ) { const std::string &entryName1 = list1.name(itr1); const std::string &entryName2 = list2.name(itr2); const ParameterEntry &entry1 = list1.entry(itr1); const ParameterEntry &entry2 = list2.entry(itr2); if( entryName1 != entryName2 ) { return false; } if( entry1.isList() && entry2.isList() ) { if ( !haveSameValues( getValue<ParameterList>(entry1), getValue<ParameterList>(entry2)) ) { // Note: Above we cast to a non-const ParameterList even through we // only need a const ParameterList. We have to do this since a // non-const ParameterList is always added initially which determines // the value. return false; } } else { if( entry1.getAny() != entry2.getAny() ) { return false; } } } // Check that the two parameter lists are the same length: if ((itr1 != list1.end()) || (itr2 != list2.end())) { return false; } return true; }
static ParseNode f_internalDcop(Parser* parser, const ParameterList& params) { SpecialFunction function = SpecialInformation::functionObject("DCOP", params[0].toString()); int functionId = SpecialInformation::function(Group::DCOP, params[0].toString()); if (functionId == -1) return f_executeSlot(parser, params); //return ParseNode::error("unknown function"); else if ((uint)function.minArg() > params.count() - 1) return ParseNode::error("too few parameters"); else if ((uint)function.maxArg() < params.count() - 1) return ParseNode::error("too many parameters"); KommanderWidget* widget = parser->currentWidget(); if (widget) widget = widget->widgetByName(params[1].toString()); if (!widget) return ParseNode::error("unknown widget"); QStringList args; ParameterList::ConstIterator it = params.begin(); ++it; // skip function ++it; // skip widget while (it != params.end()) { args += (*it).toString(); ++it; } return widget->handleDCOP(functionId, args); }
XMLObject XMLParameterListWriter::convertParameterList( const ParameterList& p, ParameterEntry::ParameterEntryID& idCounter, EntryIDsMap& entryIDsMap, const ValidatortoIDMap& validatorIDsMap) const { XMLObject rtn(getParameterListTagName()); for (ParameterList::ConstIterator i=p.begin(); i!=p.end(); ++i){ RCP<const ParameterEntry> entry = p.getEntryRCP(i->first); if(entry->isList()){ XMLObject newPL = convertParameterList( getValue<ParameterList>(entry), idCounter, entryIDsMap, validatorIDsMap); newPL.addAttribute( getNameAttributeName(), p.name(i)); newPL.addAttribute( ParameterEntryXMLConverter::getIdAttributeName(), idCounter); entryIDsMap.insert(EntryIDsMap::value_type(entry, idCounter)); rtn.addChild(newPL); ++idCounter; } else{ rtn.addChild(ParameterEntryXMLConverterDB::convertEntry( entry, p.name(i), idCounter, validatorIDsMap)); entryIDsMap.insert(EntryIDsMap::value_type(entry, idCounter)); ++idCounter; } } return rtn; }
void * SymbolTableVisitor::visitStreamSpec(StreamSpec *spec) { string scope = syms->getScope(); if (spec->getName() == "anon") { spec->setName( createAnonName() ); syms->setScope("streamit"); } string name = spec->getName(); syms->addEntry(name, spec, NULL); syms->pushScope(name); ParameterList::iterator iter; ParameterList *pl = spec->getParams(); for (iter = pl->begin(); iter != pl->end(); iter++) { Parameter *p = *iter; FEContext *c = spec->getContext(); string n = p->getName(); Type *t = p->getType(); syms->addEntry(p->getName(), (FENode*)(new StmtVarDecl(c, t, n, 0)), 0); } FEPrintVisitor::visitStreamSpec(spec); syms->setScope(scope); return NULL; }
void ClsQHarborImpl::doDialog(int iItemType, string strItemID, int iIndex) { string strItemType; string strItemName; string strSubItemName; ParameterList paramLst; list<string> lstParams; if(iItemType == ClsFESystemManager::ITEM_GROUP) { strItemType = "Group"; clsItem = ClsFESystemManager::Instance()->getFEGroup( strItemID ); if(clsItem!=NULL) { strItemName = dynamic_cast<ClsFEGroup*>(clsItem)->getGroupName(); ClsNeuron* clsNeuron = dynamic_cast<ClsFEGroup*>(clsItem)->getNeuron( ); if(clsNeuron!=NULL) { strSubItemName = dynamic_cast<ClsFEGroup*>(clsItem)->getGroupNeuronLabel(); paramLst = clsNeuron->getListParameters(); } } } else if (iItemType == ClsFESystemManager::ITEM_CONNECTION) { strItemType = "Connection"; clsItem = ClsFESystemManager::Instance()->getFEConnection( strItemID ); if(clsItem!=NULL) { strItemName = dynamic_cast<ClsFEConnection*>(clsItem)->getConnectionName(); ClsSynapse* clsSynapse = dynamic_cast<ClsFEConnection*>(clsItem)->getSynapse( ); if(clsSynapse!=NULL) { strSubItemName = dynamic_cast<ClsFEConnection*>(clsItem)->getConnectionSynapseLabel(); paramLst = clsSynapse->getListParameters(); } } } for(ParameterList::iterator it=paramLst.begin(); it!=paramLst.end(); it++) { if(dynamic_cast<ClsDoubleParameter*>(*it)) { pair<string, string> pairTemp((*it)->getLabel(), (*it)->getName()); mapParams.insert(pairTemp); lstParams.push_back((*it)->getLabel()); } } if(lstParams.size()>0) { if(iIndex<0) { qtableEntries->insertRows(0,1); qtableEntries->setText(0, COL_TYPE, strItemType); qtableEntries->setText(0, COL_NAME, strItemName); qtableEntries->setText(0, COL_ID, strItemID); qtableEntries->setText(0, COL_CHILD, strSubItemName); } ClsQHarborDialogImpl* clsQHarborDialogImpl = new ClsQHarborDialogImpl(strItemType, strItemID, strItemName, strSubItemName, lstParams, iIndex, this); connect(clsQHarborDialogImpl, SIGNAL(sigDoItem(string,int)), SLOT(slotDoItem(string,int))); connect(clsQHarborDialogImpl, SIGNAL(sigDoItemCanceled(int)), SLOT(slotDoItemCanceled(int))); clsQHarborDialogImpl->show(); } }
std::queue<ParameterList> ComparisonHelper::getMetricsToCompare(const ParameterList &pList) { // extract all of the metrics to be tested std::queue<ParameterList> metrics; for(auto it = pList.begin(); it != pList.end(); ++it) { if (pList.isSublist(it->first)) { metrics.push(pList.sublist(it->first)); } } return metrics; }
bool TypeRegistry::same_parameters(const ParameterList &p1, const ParameterList &p2) const { if (p1.size() != p2.size()) return false; ParameterList::const_iterator j=p2.begin(); for (ParameterList::const_iterator i=p1.begin(); i!=p1.end(); ++i, ++j) { if (TypeNameUtils::trim(i->type_specifier) != TypeNameUtils::trim(j->type_specifier)) return false; } return true; }
void LCDWidget::set(const ParameterList &pList) { ostringstream params; for (ParameterList::const_iterator it = pList.begin(); it != pList.end(); ++it) { params << *it << " "; } setWidgetParameters(params.str()); }
void BCManager::run() { if (jacT != Teuchos::null) isAdjoint = true; typedef ParameterList::ConstIterator ParamIter; for (ParamIter i = bcParams.begin(); i != bcParams.end(); ++i) { std::string const& name = bcParams.name(i); Teuchos::ParameterEntry const& entry = bcParams.entry(i); assert(entry.isList()); applyBC(Teuchos::getValue<ParameterList>(entry)); } }
bool Teuchos::operator==( const ParameterList& list1, const ParameterList& list2 ) { // Check that the top-level names of the two parameter lists are the same //const std::string ¶mListName1 = list1.name(); //const std::string ¶mListName2 = list2.name(); //if ( paramListName1 != paramListName2 ) { // return false; //} ParameterList::ConstIterator itr1, itr2; for( itr1 = list1.begin(), itr2 = list2.begin(); itr1 != list1.end() && itr2 != list2.end(); ++itr1, ++itr2 ) { const std::string &entryName1 = list1.name(itr1); const std::string &entryName2 = list2.name(itr2); const ParameterEntry &entry1 = list1.entry(itr1); const ParameterEntry &entry2 = list2.entry(itr2); if( entryName1 != entryName2 ) { return false; } else if( entry1 != entry2 ) { return false; } // Note that the above statement automatically recursively compare the // sublists since ParameterList objects are stored in the 'any' variable // held by the ParameterEntry object and this same comparison operator will // be used. } // Check that the two parameter lists are the same length: if ((itr1 != list1.end()) || (itr2 != list2.end())) { return false; } return true; }
void XMLParameterListWriter::buildInitialValidatorMap( const ParameterList& p, ValidatortoIDMap& validatorIDsMap) const { for (ParameterList::ConstIterator i=p.begin(); i!=p.end(); ++i) { const ParameterEntry& entry = p.entry(i); if(entry.isList()){ buildInitialValidatorMap( getValue<ParameterList>(entry), validatorIDsMap); } else if(nonnull(entry.validator())){ validatorIDsMap.insert(entry.validator()); } } }
void SexpParser::ListToString(stringstream& ss, const ParameterList& lst) { string space; ss.setf(ios_base::fixed,ios_base::floatfield); ss.precision(2); for ( ParameterList::TVector::const_iterator i = lst.begin(); i != lst.end(); ++i ) { if (i->type() == typeid(string)) { ss << space; ss << boost::any_cast<string>(*i); } else if (i->type() == typeid(float)) { ss << space; ss << boost::any_cast<float>(*i); } else if (i->type() == typeid(int)) { ss << space; ss <<boost::any_cast<int>(*i); } else if (i->type() == typeid(ParameterList)) { const any* v = &(*i); const ParameterList* lst = any_cast<ParameterList>(v); ss << space; ss << '('; ListToString(ss,*lst); ss << ')'; } else { ss << space; ss << "(error data format unknown)"; } space = " "; } }
TEUCHOS_UNIT_TEST( Teuchos_ParameterList, xmlUpdateAndBroadcast ) { const RCP<const Comm<int> > comm = DefaultComm<int>::getComm(); // Test the broadcast functionality to avoid unscalable I/O collisions std::string inputFile="input.xml"; ParameterList A; ParameterList B; updateParametersFromXmlFile(inputFile, &A); updateParametersFromXmlFileAndBroadcast(inputFile, &B, *comm); out << "B = " << B; TEST_ASSERT( B.begin() != B.end() ); // Avoid false positive from empty lists // See if any process returned a failed (i.e. a non-zero local_failed) int local_failed = !(A == B); int global_failed = -1; reduceAll( *comm, Teuchos::REDUCE_SUM, local_failed, outArg(global_failed) ); TEST_EQUALITY_CONST( global_failed, 0 ); }
static ParseNode f_executeSlot(Parser* parser, const ParameterList& params) { ParameterList::ConstIterator it = params.begin(); QString slotName = (*it).toString()+"("; ++it; QString widgetName = (*it).toString(); KommanderWidget* widget = parser->currentWidget(); if (!widget) return ParseNode::error("unknown widget"); widget = widget->widgetByName(widgetName); if (!widget) return ParseNode::error("unknown widget"); QObject *object = widget->object(); if (!object) return ParseNode::error("unknown widget"); QStrList slotSignatures = object->metaObject()->slotNames(true); QStringList slotNames = QStringList::fromStrList(slotSignatures); int slotNum = -1; uint i = 0; while (i < slotNames.count()) { if (slotNames[i].startsWith(slotName)) { slotNum = i; break; } i++; } if (slotNum == -1) return ParseNode::error("unknown function"); QStringList args; ++it; // skip widget while (it != params.end()) { args += (*it).toString(); ++it; } InvokeClass* inv = new InvokeClass(0); inv->invokeSlot(object, slotSignatures.at(slotNum), args); inv->deleteLater(); return ParseNode(); }
std::string ML2MueLuParameterTranslator::SetParameterList(const Teuchos::ParameterList & paramList_in, const std::string& defaultVals) { Teuchos::ParameterList paramList = paramList_in; RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); // TODO: use internal out (GetOStream()) #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA) // TODO alternative with standard parameterlist from ML user guide? if (defaultVals != "") { TEUCHOS_TEST_FOR_EXCEPTION(defaultVals!="SA" && defaultVals!="NSSA", Exceptions::RuntimeError, "MueLu::MLParameterListInterpreter: only \"SA\" and \"NSSA\" allowed as options for ML default parameters."); Teuchos::ParameterList ML_defaultlist; ML_Epetra::SetDefaults(defaultVals,ML_defaultlist); // merge user parameters with default parameters MueLu::MergeParameterList(paramList_in, ML_defaultlist, true); paramList = ML_defaultlist; } #else if (defaultVals != "") { // If no validator available: issue a warning and set parameter value to false in the output list *out << "Warning: MueLu_ENABLE_ML=OFF. No ML default values available." << std::endl; } #endif // HAVE_MUELU_ML // // Move smoothers/aggregation/coarse parameters to sublists // // ML allows to have level-specific smoothers/aggregation/coarse parameters at the top level of the list or/and defined in sublists: // See also: ML Guide section 6.4.1, MueLu::CreateSublists, ML_CreateSublists ParameterList paramListWithSubList; MueLu::CreateSublists(paramList, paramListWithSubList); paramList = paramListWithSubList; // swap Teuchos::ParameterList adaptingParamList = paramList; // copy of paramList which is used to removed already interpreted parameters // // Validate parameter list // { bool validate = paramList.get("ML validate parameter list", true); /* true = default in ML */ if (validate) { #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA) // Validate parameter list using ML validator int depth = paramList.get("ML validate depth", 5); /* 5 = default in ML */ TEUCHOS_TEST_FOR_EXCEPTION(! ML_Epetra::ValidateMLPParameters(paramList, depth), Exceptions::RuntimeError, "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!"); #else // If no validator available: issue a warning and set parameter value to false in the output list *out << "Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl; paramList.set("ML validate parameter list", false); #endif // HAVE_MUELU_ML } // if(validate) } // scope // stringstream for concatenating xml parameter strings. std::stringstream mueluss; // create surrounding MueLu parameter list mueluss << "<ParameterList name=\"MueLu\">" << std::endl; // loop over all ML parameters in provided parameter list for (ParameterList::ConstIterator param = paramListWithSubList.begin(); param != paramListWithSubList.end(); ++param) { // extract ML parameter name const std::string & pname=paramListWithSubList.name(param); // extract corresponding (ML) value // remove ParameterList specific information from result string std::stringstream valuess; valuess << paramList.entry(param); std::string valuestr = valuess.str(); replaceAll(valuestr, "[unused]", ""); replaceAll(valuestr, "[default]", ""); valuestr = trim(valuestr); // transform ML parameter to corresponding MueLu parameter and generate XML string std::string valueInterpreterStr = "\"" + valuestr + "\""; std::string ret = MasterList::interpretParameterName(MasterList::ML2MueLu(pname),valueInterpreterStr); // add XML string if (ret != "") { mueluss << ret << std::endl; // remove parameter from ML parameter list adaptingParamList.remove(pname,false); } // special handling for energy minimization // TAW: this is not optimal for symmetric problems but at least works. // for symmetric problems the "energy minimization" parameter should not exist anyway... if (pname == "energy minimization: enable") { mueluss << "<Parameter name=\"problem: symmetric\" type=\"bool\" value=\"false\"/>" << std::endl; mueluss << "<Parameter name=\"transpose: use implicit\" type=\"bool\" value=\"false\"/>" << std::endl; } // special handling for smoothers if (pname == "smoother: type") { mueluss << GetSmootherFactory(paramList, adaptingParamList, pname, valuestr); } // special handling for level-specific smoothers if (pname.find("smoother: list (level",0) == 0) { // Scan pname (ex: pname="smoother: type (level 2)") std::string type, option; int levelID=-1; { typedef Teuchos::ArrayRCP<char>::size_type size_type; Teuchos::Array<char> ctype (size_type(pname.size()+1)); Teuchos::Array<char> coption(size_type(pname.size()+1)); int matched = sscanf(pname.c_str(),"%s %[^(](level %d)", ctype.getRawPtr(), coption.getRawPtr(), &levelID); // use [^(] instead of %s to allow for strings with white-spaces (ex: "ifpack list") type = std::string(ctype.getRawPtr()); option = std::string(coption.getRawPtr()); option.resize(option.size () - 1); // remove final white-space if (matched != 3 || (type != "smoother:")) { TEUCHOS_TEST_FOR_EXCEPTION(true, MueLu::Exceptions::RuntimeError, "MueLu::CreateSublist(), Line " << __LINE__ << ". " << "Error in creating level-specific sublists" << std::endl << "Offending parameter: " << pname << std::endl); } mueluss << "<ParameterList name=\"level " << levelID << "\">" << std::endl; mueluss << GetSmootherFactory(paramList.sublist(pname),adaptingParamList.sublist(pname), "smoother: type", paramList.sublist(pname).get<std::string>("smoother: type")); mueluss << "</ParameterList>" << std::endl; } } // special handling for coarse level TEUCHOS_TEST_FOR_EXCEPTION(paramList.isParameter("coarse: type"), Exceptions::RuntimeError, "MueLu::MLParameterListInterpreter::Setup(): The parameter \"coarse: type\" should not exist but being stored in \"coarse: list\" instead."); if ( pname == "coarse: list" ) { // interpret smoother/coarse solver data. // Note, that we inspect the "coarse: list" sublist to define the "coarse" smoother/solver // Be aware, that MueLu::CreateSublists renames the prefix of the parameters in the "coarse: list" from "coarse" to "smoother". // Therefore, we have to check the values of the "smoother" parameters TEUCHOS_TEST_FOR_EXCEPTION(!paramList.sublist("coarse: list").isParameter("smoother: type"), Exceptions::RuntimeError, "MueLu::MLParameterListInterpreter::Setup(): no coarse grid solver defined."); mueluss << GetSmootherFactory(paramList.sublist("coarse: list"), adaptingParamList.sublist("coarse: list"), "coarse: type", paramList.sublist("coarse: list").get<std::string>("smoother: type")); } } // for mueluss << "</ParameterList>" << std::endl; return mueluss.str(); }
void ClsQHarborImpl::doDialog(int iItemType, string strItemID, int iIndex){ #ifndef _WINDOWS // cannot get this to work under minGW at the moment... string strItemType; string strItemName; string strSubItemName; ParameterList paramLst; list<string> lstParams; if(iItemType == ClsFESystemManager::ITEM_GROUP){ strItemType = "Group"; clsItem = ClsFESystemManager::Instance()->getFEGroup( strItemID ); if(clsItem!=NULL){ strItemName = dynamic_cast<ClsFEGroup*>(clsItem)->getGroupName(); ClsNeuron* clsNeuron = dynamic_cast<ClsFEGroup*>(clsItem)->getNeuron( ); if(clsNeuron!=NULL){ strSubItemName = dynamic_cast<ClsFEGroup*>(clsItem)->getGroupNeuronLabel(); paramLst = clsNeuron->getListParameters(); } } } else if (iItemType == ClsFESystemManager::ITEM_CONNECTION){ strItemType = "Connection"; clsItem = ClsFESystemManager::Instance()->getFEConnection( strItemID ); if(clsItem!=NULL){ strItemName = dynamic_cast<ClsFEConnection*>(clsItem)->getConnectionName(); ClsSynapse* clsSynapse = dynamic_cast<ClsFEConnection*>(clsItem)->getSynapse( ); if(clsSynapse!=NULL){ strSubItemName = dynamic_cast<ClsFEConnection*>(clsItem)->getConnectionSynapseLabel(); paramLst = clsSynapse->getListParameters(); } } } for(ParameterList::iterator it=paramLst.begin(); it!=paramLst.end(); it++){ if(dynamic_cast<ClsDoubleParameter*>(*it)){ pair<string, string> pairTemp((*it)->getLabel(), (*it)->getName()); mapParams.insert(pairTemp); lstParams.push_back((*it)->getLabel()); } } if(lstParams.size()>0){ if(iIndex<0){ tableWidget->insertRow ( 0 ); addItem(0, COL_TYPE, strItemType.c_str()); addItem(0, COL_NAME, strItemName.c_str()); addItem(0, COL_ID, strItemID.c_str()); addItem(0, COL_CHILD, strSubItemName.c_str()); addItem(0, COL_PARAM_LABEL, ""); addItem(0, COL_MIN, ""); addItem(0, COL_MAX, ""); addItem(0, COL_VALUE, ""); addItem(0, COL_PARAM_NAME, ""); } ClsQHarborDialogImpl* clsQHarborDialogImpl = new ClsQHarborDialogImpl(strItemType, strItemID, strItemName, strSubItemName, lstParams, iIndex, this); connect(clsQHarborDialogImpl, SIGNAL(sigDoItem(string,int)), SLOT(slotDoItem(string,int))); connect(clsQHarborDialogImpl, SIGNAL(sigDoItemCanceled(int)), SLOT(slotDoItemCanceled(int))); clsQHarborDialogImpl->show(); } #endif }
void ParameterListInterpreter<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::SetEasyParameterList(const Teuchos::ParameterList& constParamList) { // Create a non const copy of the parameter list // Working with a modifiable list is much much easier than with original one ParameterList paramList = constParamList; // Translate cycle type parameter if (paramList.isParameter("cycle type")) { std::map<std::string,CycleType> cycleMap; cycleMap["V"] = VCYCLE; cycleMap["W"] = WCYCLE; std::string cycleType = paramList.get<std::string>("cycle type"); TEUCHOS_TEST_FOR_EXCEPTION(cycleMap.count(cycleType) == 0, Exceptions::RuntimeError, "Invalid cycle type: \"" << cycleType << "\""); Cycle_ = cycleMap[cycleType]; } this->maxCoarseSize_ = paramList.get<int> ("coarse: max size", Hierarchy::GetDefaultMaxCoarseSize()); this->numDesiredLevel_ = paramList.get<int> ("max levels", Hierarchy::GetDefaultMaxLevels()); this->graphOutputLevel_ = paramList.get<int> ("debug: graph level", -1); blockSize_ = paramList.get<int> ("number of equations", 1); // Save level data if (paramList.isSublist("print")) { ParameterList printList = paramList.sublist("print"); if (printList.isParameter("A")) this->matricesToPrint_ = Teuchos::getArrayFromStringParameter<int>(printList, "A"); if (printList.isParameter("P")) this->prolongatorsToPrint_ = Teuchos::getArrayFromStringParameter<int>(printList, "P"); if (printList.isParameter("R")) this->restrictorsToPrint_ = Teuchos::getArrayFromStringParameter<int>(printList, "R"); } // Translate verbosity parameter this->verbosity_ = static_cast<MsgType>(Hierarchy::GetDefaultVerbLevel()); // cast int to enum if (paramList.isParameter("verbosity")) { std::map<std::string,MsgType> verbMap; verbMap["none"] = None; verbMap["low"] = Low; verbMap["medium"] = Medium; verbMap["high"] = High; verbMap["extreme"] = Extreme; verbMap["test"] = Test; std::string verbosityLevel = paramList.get<std::string>("verbosity"); TEUCHOS_TEST_FOR_EXCEPTION(verbMap.count(verbosityLevel) == 0, Exceptions::RuntimeError, "Invalid verbosity level: \"" << verbosityLevel << "\""); this->verbosity_ = verbMap[verbosityLevel]; this->SetVerbLevel(this->verbosity_); } // Detect if we need to transfer coordinates to coarse levels. We do that iff // - we use "laplacian" dropping on some level, or // - we use repartitioning on some level // This is not ideal, as we may have "repartition: enable" turned on by default // and not present in the list, but it is better than nothing. useCoordinates_ = false; if ((paramList.isParameter("repartition: enable") && paramList.get<bool>("repartition: enable") == true) || (paramList.isParameter("aggregation: drop scheme") && paramList.get<std::string>("aggregation: drop scheme") == "laplacian")) { useCoordinates_ = true; } else { for (int levelID = 0; levelID < this->numDesiredLevel_; levelID++) { std::string levelStr = "level" + toString(levelID); if (paramList.isSublist(levelStr)) { const ParameterList& levelList = paramList.sublist(levelStr); if ((levelList.isParameter("repartition: enable") && levelList.get<bool>("repartition: enable") == true) || (levelList.isParameter("aggregation: drop scheme") && levelList.get<std::string>("aggregation: drop scheme") == "laplacian")) { useCoordinates_ = true; break; } } } } // Detect if we do implicit P and R rebalance if (paramList.isParameter("repartition: enable") && paramList.get<bool>("repartition: enable") == true) this->doPRrebalance_ = paramList.get<bool>("repartition: rebalance P and R", Hierarchy::GetDefaultPRrebalance()); this->implicitTranspose_ = paramList.get<bool>("transpose: use implicit", Hierarchy::GetDefaultImplicitTranspose()); // Create default manager RCP<FactoryManager> defaultManager = rcp(new FactoryManager()); defaultManager->SetVerbLevel(this->verbosity_); UpdateFactoryManager(paramList, ParameterList(), *defaultManager); defaultManager->Print(); for (int levelID = 0; levelID < this->numDesiredLevel_; levelID++) { RCP<FactoryManager> levelManager; if (paramList.isSublist("level " + toString(levelID))) { // Some level specific parameters, update default manager bool mustAlreadyExist = true; ParameterList& levelList = paramList.sublist("level " + toString(levelID), mustAlreadyExist); levelManager = rcp(new FactoryManager(*defaultManager)); levelManager->SetVerbLevel(defaultManager->GetVerbLevel()); UpdateFactoryManager(levelList, paramList, *levelManager); } else { // No level specific parameter, use default manager levelManager = defaultManager; } this->AddFactoryManager(levelID, 1, levelManager); } if (paramList.isParameter("strict parameter checking") && paramList.get<bool> ("strict parameter checking")) { ParameterList unusedParamList; // Check for unused parameters that aren't lists for (ParameterList::ConstIterator itr = paramList.begin(); itr != paramList.end(); ++itr) { const ParameterEntry& entry = paramList.entry(itr); if (!entry.isList() && !entry.isUsed()) unusedParamList.setEntry(paramList.name(itr), entry); } #if 0 // Check for unused parameters in level-specific sublists for (int levelID = 0; levelID < this->numDesiredLevel_; levelID++) { std::string levelStr = "level" + toString(levelID); if (paramList.isSublist(levelStr)) { const ParameterList& levelList = paramList.sublist(levelStr); for (ParameterList::ConstIterator itr = levelList.begin(); itr != levelList.end(); ++itr) { const ParameterEntry& entry = levelList.entry(itr); if (!entry.isList() && !entry.isUsed()) unusedParamList.sublist(levelStr).setEntry(levelList.name(itr), entry); } } } #endif if (unusedParamList.numParams() > 0) { std::ostringstream unusedParamsStream; int indent = 4; unusedParamList.print(unusedParamsStream, indent); TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(true, Teuchos::Exceptions::InvalidParameter, "WARNING: Unused parameters were detected. Please check spelling and type." << std::endl << unusedParamsStream.str()); } } // FIXME: parameters passed to packages, like Ifpack2, are not touched by us, resulting in "[unused]" flag // being displayed. On the other hand, we don't want to simply iterate through them touching. I don't know // what a good solution looks like this->GetOStream(static_cast<MsgType>(Runtime1 | Test), 0) << paramList << std::endl; }
static void LoadMetricInfo(std::vector<MetricAnalyzerInfo> & metricInfoSet, const RCP<const Zoltan2::EvaluatePartition <basic_id_t> > &metricObject, const ParameterList &metricsParameters) { // at this point we should be looking at a metricsPlist with the following format - note that weight is optional // <ParameterList name="metriccheck1"> // <Parameter name="check" type="string" value="imbalance"/> // <Parameter name="lower" type="double" value="0.99"/> // <Parameter name="upper" type="double" value="1.4"/> // </ParameterList> // <ParameterList name="metriccheck2"> // <Parameter name="check" type="string" value="imbalance"/> // <Parameter name="weight" type="int" value="0"/> // <Parameter name="lower" type="double" value="0.99"/> // <Parameter name="upper" type="double" value="1.4"/> // </ParameterList> // first let's get a list of all the headings, so "metriccheck1", "metriccheck2" in this case // I've currently got this enforcing those names strictly to make sure formatting is correct // But really the headings could just be any unique names and are arbitrary int headingIndex = 1; for (auto iterateArbitraryHeadingNames = metricsParameters.begin(); iterateArbitraryHeadingNames != metricsParameters.end(); ++iterateArbitraryHeadingNames) { auto headingName = metricsParameters.name(iterateArbitraryHeadingNames); // we could be flexible on these headers but for now let's enforce it to get any convention inconsistencies cleaned up std::string expectedHeadingName = "metriccheck" + std::to_string(headingIndex); if( expectedHeadingName != headingName) { throw std::logic_error( "The parameter list expected to find a heading with name '" + expectedHeadingName + "' but instead found '" + headingName ); } // get the parameters specific to the check we want to run const ParameterList & metricCheckParameters = metricsParameters.sublist(headingName); MetricAnalyzerInfo metricInfo = getMetricInfo(metricCheckParameters, metricObject); metricInfoSet.push_back(metricInfo); ++headingIndex; } }
void HierarchyUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::AddNonSerializableDataToHierarchy(HierarchyManager& HM, Hierarchy& H, const ParameterList& paramList) { for (ParameterList::ConstIterator it = paramList.begin(); it != paramList.end(); it++) { const std::string& levelName = it->first; // Check for mach of the form "level X" where X is a positive integer if (paramList.isSublist(levelName) && levelName.find("level ") == 0 && levelName.size() > 6) { int levelID = strtol(levelName.substr(6).c_str(), 0, 0); if (levelID > 0) { // Do enough level adding so we can be sure to add the data to the right place for (int i = H.GetNumLevels(); i <= levelID; i++) H.AddNewLevel(); } RCP<Level> level = H.GetLevel(levelID); RCP<FactoryManager> M = Teuchos::rcp_dynamic_cast<FactoryManager>(HM.GetFactoryManager(levelID)); TEUCHOS_TEST_FOR_EXCEPTION(M.is_null(), Exceptions::InvalidArgument, "MueLu::Utils::AddNonSerializableDataToHierarchy: cannot get FactoryManager"); // Grab the level sublist & loop over parameters const ParameterList& levelList = paramList.sublist(levelName); for (ParameterList::ConstIterator it2 = levelList.begin(); it2 != levelList.end(); it2++) { const std::string& name = it2->first; TEUCHOS_TEST_FOR_EXCEPTION(name != "A" && name != "P" && name != "R" && name != "Nullspace" && name != "Coordinates" && !IsParamMuemexVariable(name), Exceptions::InvalidArgument, "MueLu::Utils::AddNonSerializableDataToHierarchy: parameter list contains unknown data type"); if (name == "A") { level->Set(name, Teuchos::getValue<RCP<Matrix > > (it2->second),NoFactory::get()); M->SetFactory(name, NoFactory::getRCP()); // TAW: not sure about this: be aware that this affects all levels // However, A is accessible through NoFactory anyway, so it should // be fine here. } else if( name == "P" || name == "R") { level->AddKeepFlag(name,NoFactory::get(),MueLu::UserData); level->Set(name, Teuchos::getValue<RCP<Matrix > > (it2->second), M->GetFactory(name).get()); } else if (name == "Nullspace") { level->AddKeepFlag(name,NoFactory::get(),MueLu::UserData); level->Set(name, Teuchos::getValue<RCP<MultiVector > >(it2->second), NoFactory::get()); //M->SetFactory(name, NoFactory::getRCP()); // TAW: generally it is a bad idea to overwrite the factory manager data here // One should do this only in very special cases } else if(name == "Coordinates") //Scalar of Coordinates MV is always double { level->AddKeepFlag(name,NoFactory::get(),MueLu::UserData); level->Set(name, Teuchos::getValue<RCP<Xpetra::MultiVector<double, LocalOrdinal, GlobalOrdinal, Node> > >(it2->second), NoFactory::get()); //M->SetFactory(name, NoFactory::getRCP()); // TAW: generally it is a bad idea to overwrite the factory manager data here } #ifdef HAVE_MUELU_MATLAB else { //Custom variable for Muemex size_t typeNameStart = name.find_first_not_of(' '); size_t typeNameEnd = name.find(' ', typeNameStart); std::string typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart); std::transform(typeName.begin(), typeName.end(), typeName.begin(), ::tolower); level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData); if(typeName == "matrix") level->Set(name, Teuchos::getValue<RCP<Matrix> >(it2->second), NoFactory::get()); else if(typeName == "multivector") level->Set(name, Teuchos::getValue<RCP<MultiVector> >(it2->second), NoFactory::get()); else if(typeName == "map") level->Set(name, Teuchos::getValue<RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > >(it2->second), NoFactory::get()); else if(typeName == "ordinalvector") level->Set(name, Teuchos::getValue<RCP<Xpetra::Vector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node> > >(it2->second), NoFactory::get()); else if(typeName == "scalar") level->Set(name, Teuchos::getValue<Scalar>(it2->second), NoFactory::get()); else if(typeName == "double") level->Set(name, Teuchos::getValue<double>(it2->second), NoFactory::get()); else if(typeName == "complex") level->Set(name, Teuchos::getValue<std::complex<double> >(it2->second), NoFactory::get()); else if(typeName == "int") level->Set(name, Teuchos::getValue<int>(it2->second), NoFactory::get()); else if(typeName == "string") level->Set(name, Teuchos::getValue<std::string>(it2->second), NoFactory::get()); } #endif } } } }
static MetricAnalyzerInfo getMetricInfo( const ParameterList & metricCheckParameters, const RCP<const Zoltan2::EvaluatePartition <basic_id_t> > &metricObject) { MetricAnalyzerInfo result; // will fill these values for (auto iterateAllKeys = metricCheckParameters.begin(); iterateAllKeys != metricCheckParameters.end(); ++iterateAllKeys) { auto checkName = metricCheckParameters.name(iterateAllKeys); if ( checkName != WEIGHT_PARAMETER_NAME && checkName != KEYWORD_PARAMETER_NAME && checkName != UPPER_PARAMETER_NAME && checkName != LOWER_PARAMETER_NAME && checkName != NORMED_PARAMETER_NAME ) { throw std::logic_error( "Key name: '" + checkName + "' is not understood." ); } } // pick up the weight index - this parameter is optional so we check it first - this way we can communicate with EvaluatePartition properly in the next step int selectedWeightIndex = UNDEFINED_PARAMETER_INT_INDEX; // meaning not specified so default case if( metricCheckParameters.isParameter(WEIGHT_PARAMETER_NAME)) { selectedWeightIndex = metricCheckParameters.get<int>(WEIGHT_PARAMETER_NAME); if( selectedWeightIndex < 0 ) { throw std::logic_error( "Optional weight index was specified as: " + std::to_string(selectedWeightIndex) + " Weight index must be 0 or positive." ); // I think that's the best I can do for error checking weight index right now - we may want to specify the cap when we know it } } // pick up the norm index - this parameter is optional so we check it first - this way we can communicate with EvaluatePartition properly in the next step int selectedNormedSetting = UNDEFINED_PARAMETER_INT_INDEX; // meaning not specified so default case if( metricCheckParameters.isParameter(NORMED_PARAMETER_NAME)) { bool bNormSetting = metricCheckParameters.get<bool>(NORMED_PARAMETER_NAME); selectedNormedSetting = bNormSetting ? 1 : 0; if( selectedNormedSetting != 0 && selectedNormedSetting != 1 ) { throw std::logic_error( "Optional normed parameter was specified as: " + std::to_string(selectedNormedSetting) + " Normed parameter must be true or false." ); } } // one of the parameters called "check" should define a string which is a keyword which correlates to an EvaluatePartition API all // this area needs some consideration - how and where shall we map and define the naming conventions if( metricCheckParameters.isParameter(KEYWORD_PARAMETER_NAME)) { std::string theKeyWord = metricCheckParameters.get<std::string>(KEYWORD_PARAMETER_NAME); // this is going to need some consideration - how is the adapter scalar_t type to be properly handled? result.theValue = convertParameterChoicesToEvaluatePartitionAPICall(metricObject, theKeyWord, selectedWeightIndex, selectedNormedSetting ); // now we can obtain the upper and lower bounds for this test result.bFoundUpperBound = metricCheckParameters.isParameter(UPPER_PARAMETER_NAME); result.bFoundLowerBound = metricCheckParameters.isParameter(LOWER_PARAMETER_NAME); if (!result.bFoundUpperBound && !result.bFoundLowerBound) { throw std::logic_error( "The parameter list failed to find an entry for '" + std::string(UPPER_PARAMETER_NAME) + "' or '" + std::string(LOWER_PARAMETER_NAME) + "' and at least one is required." ); } else if (result.bFoundUpperBound && result.bFoundLowerBound) { result.lowerValue = metricCheckParameters.get<double>(LOWER_PARAMETER_NAME); result.upperValue = metricCheckParameters.get<double>(UPPER_PARAMETER_NAME); } else if (result.bFoundUpperBound) { result.upperValue = metricCheckParameters.get<double>(UPPER_PARAMETER_NAME); } else { result.lowerValue = metricCheckParameters.get<double>(LOWER_PARAMETER_NAME); } result.parameterDescription = theKeyWord; if( selectedWeightIndex != UNDEFINED_PARAMETER_INT_INDEX ) { result.parameterDescription = result.parameterDescription + " (weight: " + std::to_string(selectedWeightIndex) + ")"; } else if( selectedNormedSetting != UNDEFINED_PARAMETER_INT_INDEX ) { // throw above would catch the case where both of these were set result.parameterDescription = result.parameterDescription + " (normed: " + ( ( selectedNormedSetting == 0 ) ? "false" : "true" ) + ")"; } } return result; }
void ClsQHarborImpl::slotItemChanged(int iItemType, string _strID ) { #ifdef DEBUG_CLSQHARBORIMPL cout << "ClsQHarborImpl::slotItemChanged(int iType, string strID )" << endl; #endif if(!bSimulationRunning) { ClsItem* clsItemTemp = NULL; ParameterList paramLst; string _strSubItemName; string _strItemName; if(iItemType == ClsFESystemManager::ITEM_GROUP) { clsItemTemp = ClsFESystemManager::Instance()->getFEGroup( _strID ); if(clsItemTemp!=NULL) { _strItemName = dynamic_cast<ClsFEGroup*>(clsItemTemp)->getGroupName(); ClsNeuron* clsNeuron = dynamic_cast<ClsFEGroup*>(clsItemTemp)->getNeuron( ); if(clsNeuron!=NULL) { _strSubItemName = dynamic_cast<ClsFEGroup*>(clsItemTemp)->getGroupNeuronLabel(); paramLst = clsNeuron->getListParameters(); } } } else if (iItemType == ClsFESystemManager::ITEM_CONNECTION) { clsItemTemp = ClsFESystemManager::Instance()->getFEConnection( _strID ); if(clsItemTemp!=NULL) { _strItemName = dynamic_cast<ClsFEConnection*>(clsItemTemp)->getConnectionName(); ClsSynapse* clsSynapse = dynamic_cast<ClsFEConnection*>(clsItemTemp)->getSynapse( ); if(clsSynapse!=NULL) { _strSubItemName = dynamic_cast<ClsFEConnection*>(clsItemTemp)->getConnectionSynapseLabel(); paramLst = clsSynapse->getListParameters(); } } } list<string> lstParams; for(ParameterList::iterator it=paramLst.begin(); it!=paramLst.end(); it++) { if(dynamic_cast<ClsDoubleParameter*>(*it)) { lstParams.push_back((*it)->getName()); } } /* checks: - item name - item subtype - subtype parameter - subtype min, max, value */ if(clsItemTemp!=NULL) { // cout << "/* check the min, max, value settings */" << endl; for(int ii = 0; ii<qtableEntries->numRows(); ii++) { string strID = qtableEntries->text(ii, COL_ID); if(!strID.compare(_strID)) { bool bSubItemTypeChanged = false; /* check (omitted) + change name */ qtableEntries->setText(ii, COL_NAME, _strItemName); string str = qtableEntries->text(ii, COL_CHILD); // cout << "str: " << str << endl; // cout << "_strSubItemName: " << _strSubItemName << endl; if(_strSubItemName.compare(str)) { // cout << "subitem type changed" << endl; bSubItemTypeChanged = true; qtableEntries->setText(ii, COL_CHILD, _strSubItemName); } else { // cout << "subitem type NOT changed" << endl; bSubItemTypeChanged = false; } bool bParameterSupported = true; if(bSubItemTypeChanged) { /* check if subitem supports parameter */ string str = qtableEntries->text(ii, COL_PARAM_NAME); if(std::find(lstParams.begin(), lstParams.end(), str)!=lstParams.end()) { // cout << "PARAMETER SUPPORTED" << endl; } else { // cout << "PARAMETER _NOT_ SUPPORTED" << endl; bParameterSupported = false; } } if(bParameterSupported) { string strParamName = qtableEntries->text(ii, COL_PARAM_NAME); fillMinMaxValueField(clsItemTemp, strParamName, ii); } else { qtableEntries->setText(ii, COL_PARAM_LABEL, ""); qtableEntries->setText(ii, COL_PARAM_NAME, ""); qtableEntries->setText(ii, COL_MIN, ""); qtableEntries->setText(ii, COL_MAX, ""); qtableEntries->setText(ii, COL_VALUE, ""); } } } } for(int ii = 0; ii<qtableEntries->numCols(); ii++) { qtableEntries->adjustColumn(ii); } } };
void ParameterList::validateParametersAndSetDefaults( ParameterList const& validParamList, int const depth ) { typedef std::deque<ListPlusValidList> sublist_list_t; #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream(); OSTab tab(out); *out << "\n*** Entering ParameterList::validateParametersAndSetDefaults(...) " "for this->name()=\""<<this->name()<<"\"...\n"; #endif // // A) loop through and validate the parameters at this level. // // Here we generate a list of sublists that we will search next // sublist_list_t sublist_list; { Iterator itr; for (itr = this->nonconstBegin(); itr != this->nonconstEnd(); ++itr) { const std::string &entryName = this->name(itr); ParameterEntry &theEntry = this->nonconstEntry(itr); #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE OSTab tab(out); *out << "\nentryName=\""<<entryName<<"\"\n"; #endif const ParameterEntry *validEntry = validParamList.getEntryPtr(entryName); TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG( !validEntry, Exceptions::InvalidParameterName ,"Error, the parameter {name=\""<<entryName<<"\"," "type=\""<<theEntry.getAny(false).typeName()<<"\"" ",value=\""<<filterValueToString(theEntry)<<"\"}" "\nin the parameter (sub)list \""<<this->name()<<"\"" "\nwas not found in the list of valid parameters!" "\n\nThe valid parameters and types are:\n" <<validParamList.currentParametersString() ); RCP<const ParameterEntryValidator> validator; if (nonnull(validator=validEntry->validator())) { validator->validateAndModify(entryName, this->name(), &theEntry); theEntry.setValidator(validator); } else { const bool validType = ( validEntry!=NULL ? theEntry.getAny(false).type() == validEntry->getAny(false).type() : false ); TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG( !validType, Exceptions::InvalidParameterType ,"Error, the parameter {name=\""<<entryName<<"\"," "type=\""<<theEntry.getAny(false).typeName()<<"\"" ",value=\""<<filterValueToString(theEntry)<<"\"}" "\nin the parameter (sub)list \""<<this->name()<<"\"" "\nexists in the list of valid parameters but has the wrong type." "\n\nThe correct type is \"" << validEntry->getAny(false).typeName() << "\"." ); // Note: If there is no validator for this item, then we can not // validate the value of the parameter, only its type! } if( theEntry.isList() && depth > 0 ) { sublist_list.push_back( ListPlusValidList( &getValue<ParameterList>(theEntry), &getValue<ParameterList>(*validEntry) ) ); } } } // // B) Loop through the valid parameters at this level that are not set in // *this, and set their defaults. // { ConstIterator itr; for (itr = validParamList.begin(); itr != validParamList.end(); ++itr) { const std::string &validEntryName = validParamList.name(itr); const ParameterEntry &validEntry = validParamList.entry(itr); const ParameterEntry *theEntry = this->getEntryPtr(validEntryName); if (!theEntry) { // This entry does not exist, so add it. Here we will only set the // value of the entry and its validator and and leave off the // documentation. The reason that the validator is set is so that it // can be used to extract and validate entries in the transformed list // *this without having to refer back to the valid parameter list. ParameterEntry newEntry; newEntry.setAnyValue( validEntry.getAny(), true // isDefault ); newEntry.setValidator(validEntry.validator()); this->setEntry(validEntryName,newEntry); } } } // // C) Loop through the sublists and validate their parameters and set their // defaults! // for ( sublist_list_t::iterator sl_itr = sublist_list.begin(); sl_itr != sublist_list.end(); ++sl_itr ) { if (!sl_itr->validList->disableRecursiveValidation_) { sl_itr->list->validateParametersAndSetDefaults(*sl_itr->validList,depth-1); } } #ifdef TEUCHOS_PARAMETER_LIST_SHOW_TRACE *out << "\n*** Existing ParameterList::validateParametersAndSetDefaults(...) " "for this->name()=\""<<this->name()<<"\"...\n"; #endif }