/* * Read potential parameters from file. */ void LocalLamellarOrderingExternal::readParameters(std::istream &in) { if (nAtomType_ == 0) { UTIL_THROW("nAtomType must be set before readParam"); } if (!boundaryPtr_) { UTIL_THROW("Boundary must be set before readParam"); } // Read parameters read<int>(in, "perpDirection", perpDirection_); if (perpDirection_ < 0 || perpDirection_ >= Dimension) { UTIL_THROW("Invalid index for perpendicular direction."); } read<int>(in, "parallelDirection", parallelDirection_); if (parallelDirection_ < 0 || parallelDirection_ >= Dimension) { UTIL_THROW("Invalid index for parallel direction."); } read<double>(in, "fraction", fraction_); prefactor_.allocate(nAtomType_); readDArray<double>(in, "prefactor", prefactor_, nAtomType_); read<double>(in, "externalParameter", externalParameter_); read<double>(in, "interfaceWidth", width_); read<int>(in, "periodicity", periodicity_); isInitialized_ = true; }
/* * Read potential parameters from file. */ void PeriodicExternal::readParameters(std::istream &in) { if (nAtomType_ == 0) { UTIL_THROW("nAtomType must be set before readParam"); } if (!boundaryPtr_) { UTIL_THROW("Boundary must be set before readParam"); } // Read parameters prefactor_.allocate(nAtomType_); readDArray<double>(in, "prefactor", prefactor_, nAtomType_); read<double>(in, "externalParameter", externalParameter_); read<int>(in, "nWaveVectors", nWaveVectors_); read<double>(in, "C", C_); waveVectors_.allocate(nWaveVectors_); readDArray<Vector>(in, "waveVectors", waveVectors_, nWaveVectors_); phases_.allocate(nWaveVectors_); readDArray<double>(in, "phases", phases_, nWaveVectors_); read<Vector>(in, "shift", shift_); read<double>(in, "interfaceWidth", interfaceWidth_); read<int>(in, "periodicity", periodicity_); isInitialized_ = true; }
void McSimulation::load(const std::string& filename) { if (isInitialized_) { UTIL_THROW("Error: Called load when already initialized"); } if (!isRestarting_) { UTIL_THROW("Error: Called load without restart option"); } // Load from archive Serializable::IArchive ar; std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary; fileMaster().openRestartIFile(filename, ar.file(), mode); load(ar); ar.file().close(); #ifdef UTIL_MPI #ifdef MCMD_PERTURB if (system().hasPerturbation()) { // Read one command file, after reading multiple restart files. Util::Log::file() << "Set to use a single command file" << std::endl; setIoCommunicator(); } #endif #endif isInitialized_ = true; }
/* * Remove all ghosts. */ void AtomStorage::clearGhosts() { // Precondition if (locked_) UTIL_THROW("AtomStorage is locked"); // Clear ghosts from the map map_.clearGhosts(ghostSet_); // Transfer ghosts from the set to the reservoir Atom* atomPtr; while (ghostSet_.size() > 0) { atomPtr = &ghostSet_.pop(); ghostReservoir_.push(*atomPtr); } if (ghostSet_.size() != 0) { UTIL_THROW("Nonzero ghostSet size at end of clearGhosts"); } if (map_.nGhost() != 0) { UTIL_THROW("Nonzero nGhost in map at end of clearGhosts"); } if (map_.nGhostDistinct() != 0) { UTIL_THROW("Nonzero nGhostDistinct at end of clearGhosts"); } }
/* * Load state from an archive. */ void ClusterHistogram::loadParameters(Serializable::IArchive& ar) { // Load interval and outputFileName Analyzer::loadParameters(ar); loadParameter<int>(ar,"speciesId", speciesId_); if (speciesId_ < 0) { UTIL_THROW("Negative speciesId"); } if (speciesId_ >= system().simulation().nSpecies()) { UTIL_THROW("speciesId > nSpecies"); } loadParameter<int>(ar, "atomTypeId", atomTypeId_); if (atomTypeId_ < 0) { UTIL_THROW("Negative atomTypeId"); } loadParameter<double>(ar, "cutoff", cutoff_); if (cutoff_ < 0) { UTIL_THROW("Negative cutoff"); } identifier_.initialize(speciesId_, atomTypeId_, cutoff_); loadParameter<int>(ar, "histMin", histMin_); loadParameter<int>(ar, "histMax", histMax_); ar >> hist_; ar >> nSample_; isInitialized_ = true; }
/* * Load internal state from an archive. */ void McSimulation::loadParameters(Serializable::IArchive &ar) { if (isInitialized_) { UTIL_THROW("Error: Called readParam when already initialized"); } #ifdef UTIL_MPI if (hasIoCommunicator()) { UTIL_THROW("Error: Has a param communicator in loadParameters"); } #endif Simulation::loadParameters(ar); loadParamComposite(ar, system()); loadParamComposite(ar, *mcMoveManagerPtr_); loadParamComposite(ar, analyzerManager()); loadParameter<int>(ar, "saveInterval", saveInterval_); if (saveInterval_ > 0) { loadParameter<std::string>(ar, "saveFileName", saveFileName_); } system().loadConfig(ar); ar >> iStep_; isValid(); isInitialized_ = true; }
/* * Load state from an archive. */ void StructureFactor::loadParameters(Serializable::IArchive& ar) { Analyzer::loadParameters(ar); ar & nAtomType_; loadParameter<int>(ar, "nMode", nMode_); loadDMatrix<double>(ar, "modes", modes_, nMode_, nAtomType_); loadParameter<int>(ar, "nWave", nWave_); loadDArray<IntVector>(ar, "waveIntVectors", waveIntVectors_, nWave_); ar & structureFactors_; ar & nSample_; // Validate if (nAtomType_ != system().simulation().nAtomType()) { UTIL_THROW("Inconsistent values of nAtomType_"); } if (modes_.capacity1() != nMode_) { UTIL_THROW("Inconsistent capacity1 for modes array"); } if (modes_.capacity2() != nAtomType_) { UTIL_THROW("Inconsistent capacity2 for modes array"); } if (waveIntVectors_.capacity() != nWave_) { UTIL_THROW("Inconsistent capacity for waveIntVector"); } // Allocate temporary data structures waveVectors_.allocate(nWave_); fourierModes_.allocate(nWave_, nMode_); isInitialized_ = true; }
/* * Read and execute commands from a specified command file. */ void McSimulation::readCommands(std::istream &in) { if (!isInitialized_) { UTIL_THROW("McSimulation is not initialized"); } std::string command; std::string filename; std::ifstream inputFile; std::ofstream outputFile; #ifndef UTIL_MPI std::istream& inBuffer = in; #else std::stringstream inBuffer; std::string line; #endif bool readNext = true; while (readNext) { // iffdef UTIL_MPI, read a line and copy to stringstream inBuffer // ifndef UTIL_MPI, inBuffer is simply a reference to istream in. #ifdef UTIL_MPI // Read a command line, and broadcast if necessary. if (!hasIoCommunicator() || isIoProcessor()) { getNextLine(in, line); } if (hasIoCommunicator()) { bcast<std::string>(communicator(), line, 0); } // Copy the command line to inBuffer. inBuffer.clear(); for (unsigned i=0; i < line.size(); ++i) { inBuffer.put(line[i]); } #endif inBuffer >> command; Log::file() << command; if (isRestarting_) { if (command == "RESTART") { int endStep; inBuffer >> endStep; Log::file() << " " << iStep_ << " to " << endStep << std::endl; simulate(endStep, isRestarting_); isRestarting_ = false; } else { UTIL_THROW("Missing RESTART command"); } } else {
void ScoreFeatureManager::configure(const std::vector<std::string> args) { bool domainAdded = false; bool sparseDomainAdded = false; for (size_t i = 0; i < args.size(); ++i) { if (args[i] == "--IgnoreSentenceId") { m_includeSentenceId = true; } else if (args[i].substr(0,8) == "--Domain") { string type = args[i].substr(8); ++i; UTIL_THROW_IF(i == args.size(), ScoreFeatureArgumentException, "Missing domain file"); string domainFile = args[i]; UTIL_THROW_IF(domainAdded, ScoreFeatureArgumentException, "Only allowed one domain feature"); if (type == "Subset") { m_features.push_back(ScoreFeaturePtr(new SubsetDomainFeature(domainFile))); } else if (type == "Ratio") { m_features.push_back(ScoreFeaturePtr(new RatioDomainFeature(domainFile))); } else if (type == "Indicator") { m_features.push_back(ScoreFeaturePtr(new IndicatorDomainFeature(domainFile))); } else { UTIL_THROW(ScoreFeatureArgumentException, "Unknown domain feature type " << type); } domainAdded = true; m_includeSentenceId = true; } else if (args[i].substr(0,14) == "--SparseDomain") { string type = args[i].substr(14); ++i; UTIL_THROW_IF(i == args.size(), ScoreFeatureArgumentException, "Missing domain file"); string domainFile = args[i]; UTIL_THROW_IF(sparseDomainAdded, ScoreFeatureArgumentException, "Only allowed one sparse domain feature"); if (type == "Subset") { m_features.push_back(ScoreFeaturePtr(new SparseSubsetDomainFeature(domainFile))); } else if (type == "Ratio") { m_features.push_back(ScoreFeaturePtr(new SparseRatioDomainFeature(domainFile))); } else if (type == "Indicator") { m_features.push_back(ScoreFeaturePtr(new SparseIndicatorDomainFeature(domainFile))); } else { UTIL_THROW(ScoreFeatureArgumentException, "Unknown domain feature type " << type); } sparseDomainAdded = true; m_includeSentenceId = true; } else if(args[i] == "--GHKMFeatureSparse"){ //MARIA m_features.push_back(ScoreFeaturePtr(new InternalStructFeatureSparse())); } else if(args[i] == "--GHKMFeatureDense"){ //MARIA m_features.push_back(ScoreFeaturePtr(new InternalStructFeatureDense())); } else { UTIL_THROW(ScoreFeatureArgumentException,"Unknown score argument " << args[i]); } } }
/* * Set nAtomType */ void PeriodicExternal::setNAtomType(int nAtomType) { if (nAtomType <= 0) { UTIL_THROW("nAtomType <= 0"); } if (nAtomType > MaxAtomType) { UTIL_THROW("nAtomType > PeriodicExternal::MaxAtomType"); } nAtomType_ = nAtomType; }
/* * Set nAtomType */ void LocalLamellarOrderingExternal::setNAtomType(int nAtomType) { if (nAtomType <= 0) { UTIL_THROW("nAtomType <= 0"); } if (nAtomType > MaxAtomType) { UTIL_THROW("nAtomType > LocalLamellarOrderingExternal::MaxAtomType"); } nAtomType_ = nAtomType; }
/* * Set nAtomType */ void OrthoBoxExternal::setNAtomType(int nAtomType) { if (nAtomType <= 0) { UTIL_THROW("nAtomType <= 0"); } if (nAtomType > MaxAtomType) { UTIL_THROW("nAtomType > OrthoBoxExternal::MaxAtomType"); } nAtomType_ = nAtomType; }
/* * Set nAtomType */ void NucleationExternal::setNAtomType(int nAtomType) { if (nAtomType <= 0) { UTIL_THROW("nAtomType <= 0"); } if (nAtomType > MaxAtomType) { UTIL_THROW("nAtomType > NucleationExternal::MaxAtomType"); } nAtomType_ = nAtomType; }
/* * Clear memory block (reset to empty state). */ void MemoryIArchive::clear() { if (!isAllocated()) { UTIL_THROW("Archive is not allocated"); } if (!ownsData_) { UTIL_THROW("Archive does not own data"); } cursor_ = begin(); end_ = begin(); }
void OnDiskWrapper::BeginLoad(const std::string &filePath) { if (!OpenForLoad(filePath)) { UTIL_THROW(util::FileOpenException, "Couldn't open for loading: " << filePath); } if (!m_vocab.Load(*this)) UTIL_THROW(util::FileOpenException, "Couldn't load vocab"); UINT64 rootFilePos = GetMisc("RootNodeOffset"); m_rootSourceNode = new PhraseNode(rootFilePos, *this); }
/* * Finalize receiving block, check consistency. */ void Buffer::endRecvBlock() { if (recvSize_ != 0) { UTIL_THROW("Error: Recv counter != 0 at end of block"); } if (recvPtr_ != recvBlockEnd_) { UTIL_THROW("Error: Inconsistent recv cursor at end of block"); } recvBlockBegin_ = 0; recvBlockEnd_ = 0; recvSize_ = 0; recvType_ = NONE; }
/* * Clear accumulators. */ void McMuExchange::setup() { nMolecule_ = system().nMolecule(speciesId_); if (nMolecule_ > accumulators_.capacity()) { UTIL_THROW("nMolecule > capacity"); } if (nMolecule_ <= 0) { UTIL_THROW("nMolecule <= 0"); } for (int iMol = 0; iMol < nMolecule_; ++iMol) { accumulators_[iMol].clear(); } }
/* * Read saveInterval and saveFileName. */ void Integrator::readParameters(std::istream& in) { read<int>(in, "saveInterval", saveInterval_); if (saveInterval_ > 0) { if (Analyzer::baseInterval > 0) { if (saveInterval_ % Analyzer::baseInterval != 0) { UTIL_THROW("saveInterval is not a multiple of baseInterval"); } } else { UTIL_THROW("Analyzer::baseInterval is not positive"); } read<std::string>(in, "saveFileName", saveFileName_); } }
/* * Return address for a new ghost Atom. */ Atom* AtomStorage::newGhostPtr() { // Preconditions if (newGhostPtr_ != 0) UTIL_THROW("Unregistered newGhostPtr_ still active"); if (locked_ ) UTIL_THROW("AtomStorage is locked"); if (ghostReservoir_.size() == 0) UTIL_THROW("Atom to pop from empty atomReservoir"); newGhostPtr_ = &ghostReservoir_.pop(); newGhostPtr_->clear(); newGhostPtr_->setIsGhost(true); return newGhostPtr_; }
/* * Reset cursor to beginning, prepare to reread. */ void MemoryIArchive::reset() { if (!isAllocated()) { UTIL_THROW("Archive is not allocated"); } cursor_ = begin(); }
void ConstrainedDecoding::Load() { const StaticData &staticData = StaticData::Instance(); bool addBeginEndWord = (staticData.GetSearchAlgorithm() == ChartDecoding) || (staticData.GetSearchAlgorithm() == ChartIncremental); InputFileStream constraintFile(m_path); std::string line; long sentenceID = staticData.GetStartTranslationId() - 1; while (getline(constraintFile, line)) { vector<string> vecStr = Tokenize(line, "\t"); Phrase phrase(0); if (vecStr.size() == 1) { sentenceID++; phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[0], staticData.GetFactorDelimiter(), NULL); } else if (vecStr.size() == 2) { sentenceID = Scan<long>(vecStr[0]); phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[1], staticData.GetFactorDelimiter(), NULL); } else { UTIL_THROW(util::Exception, "Reference file not loaded"); } if (addBeginEndWord) { phrase.InitStartEndWord(); } m_constraints.insert(make_pair(sentenceID,phrase)); } }
/* * Allocate and initialize all containers (private). */ void AtomStorage::allocate() { // Precondition if (isInitialized_) { UTIL_THROW("AtomStorage can only be initialized once"); } atoms_.allocate(atomCapacity_); atomReservoir_.allocate(atomCapacity_); atomSet_.allocate(atoms_); int i; for (i = atomCapacity_ - 1; i >=0; --i) { atomReservoir_.push(atoms_[i]); } ghosts_.allocate(ghostCapacity_); ghostReservoir_.allocate(ghostCapacity_); ghostSet_.allocate(ghosts_); for (i = ghostCapacity_ - 1; i >=0; --i) { ghostReservoir_.push(ghosts_[i]); } map_.allocate(totalAtomCapacity_); snapshot_.allocate(atomCapacity_); isInitialized_ = true; }
/* * Determine whether an atom exchange and reneighboring is needed. */ bool Integrator::isExchangeNeeded(double skin) { if (!atomStorage().isCartesian()) { UTIL_THROW("Error: Coordinates not Cartesian in isExchangeNeeded"); } // Calculate maximum square displacment on this node double maxSqDisp = atomStorage().maxSqDisplacement(); int needed = 0; if (sqrt(maxSqDisp) > 0.5*skin) { needed = 1; } timer_.stamp(CHECK); #if UTIL_MPI int neededAll; domain().communicator().Allreduce(&needed, &neededAll, 1, MPI::INT, MPI::MAX); timer_.stamp(ALLREDUCE); return bool(neededAll); #else return bool(needed); #endif }
/* * Determine whether an atom exchange and reneighboring is needed. */ bool Integrator::isExchangeNeeded(double skin) { if (!atomStorage().isCartesian()) { UTIL_THROW("Error: Coordinates not Cartesian in isExchangeNeeded"); } // Calculate maximum square displacment on this node double maxSqDisp = atomStorage().maxSqDisplacement(); timer_.stamp(CHECK); // Decide on master node if maximum exceeds threshhold. int needed; #if UTIL_MPI double maxSqDispAll; // global maximum domain().communicator().Reduce(&maxSqDisp, &maxSqDispAll, 1, MPI::DOUBLE, MPI::MAX, 0); if (domain().communicator().Get_rank() == 0) { needed = 0; if (sqrt(maxSqDispAll) > 0.5*skin) { needed = 1; } } domain().communicator().Bcast(&needed, 1, MPI::INT, 0); timer_.stamp(ALLREDUCE); #else if (sqrt(maxSqDisp) > 0.5*skin) { needed = 1; } #endif return bool(needed); }
GlobalLexicalModelUnlimited::GlobalLexicalModelUnlimited(const std::string &line) :StatelessFeatureFunction(0, line) { UTIL_THROW(util::Exception, "GlobalLexicalModelUnlimited hasn't been refactored for new feature function framework yet"); // TODO need to update arguments to key=value const vector<string> modelSpec = Tokenize(line); for (size_t i = 0; i < modelSpec.size(); i++ ) { bool ignorePunctuation = true, biasFeature = false, restricted = false; size_t context = 0; string filenameSource, filenameTarget; vector< string > factors; vector< string > spec = Tokenize(modelSpec[i]," "); // read optional punctuation and bias specifications if (spec.size() > 0) { if (spec.size() != 2 && spec.size() != 3 && spec.size() != 4 && spec.size() != 6) { std::cerr << "Format of glm feature is <factor-src>-<factor-tgt> [ignore-punct] [use-bias] " << "[context-type] [filename-src filename-tgt]"; //return false; } factors = Tokenize(spec[0],"-"); if (spec.size() >= 2) ignorePunctuation = Scan<size_t>(spec[1]); if (spec.size() >= 3) biasFeature = Scan<size_t>(spec[2]); if (spec.size() >= 4) context = Scan<size_t>(spec[3]); if (spec.size() == 6) { filenameSource = spec[4]; filenameTarget = spec[5]; restricted = true; } } else factors = Tokenize(modelSpec[i],"-"); if ( factors.size() != 2 ) { std::cerr << "Wrong factor definition for global lexical model unlimited: " << modelSpec[i]; //return false; } const vector<FactorType> inputFactors = Tokenize<FactorType>(factors[0],","); const vector<FactorType> outputFactors = Tokenize<FactorType>(factors[1],","); throw runtime_error("GlobalLexicalModelUnlimited should be reimplemented as a stateful feature"); GlobalLexicalModelUnlimited* glmu = NULL; // new GlobalLexicalModelUnlimited(inputFactors, outputFactors, biasFeature, ignorePunctuation, context); if (restricted) { cerr << "loading word translation word lists from " << filenameSource << " and " << filenameTarget << endl; if (!glmu->Load(filenameSource, filenameTarget)) { std::cerr << "Unable to load word lists for word translation feature from files " << filenameSource << " and " << filenameTarget; //return false; } } } }
LanguageModelKen<lm::ngram::ProbingModel>& InMemoryPerSentenceOnDemandLM::GetPerThreadLM() const { LanguageModelKen<lm::ngram::ProbingModel> *lm; lm = m_perThreadLM.get(); if (lm == NULL) { lm = new LanguageModelKen<lm::ngram::ProbingModel>(); string* filename = m_tmpFilename.get(); if (filename == NULL) { UTIL_THROW(util::Exception, "Can't get a thread-specific LM because no temporary filename has been set for this thread\n"); } else { lm->LoadModel(*filename, util::POPULATE_OR_READ); } VERBOSE(1, filename); VERBOSE(1, "\tLM initialized\n"); m_perThreadLM.reset(lm); } assert(lm); return *lm; }
FFState* CoveredReferenceFeature::EvaluateWhenApplied( const ChartHypothesis& /* cur_hypo */, int /* featureID - used to index the state in the previous hypotheses */, ScoreComponentCollection* accumulator) const { UTIL_THROW(util::Exception, "Not implemented"); }
/* * Set the nBondType_ member */ void HarmonicBond::setNBondType(int nBondType) { if (nBondType > MaxNBondType) { UTIL_THROW("nBondType > HarmonicBond::MaxNBondType"); } nBondType_ = nBondType; }
/* * Set the nAngleType_ member. */ void CosineSqAngle::setNAngleType(int nAngleType) { if (nAngleType > MaxNAngleType) { UTIL_THROW("nAngleType > CosineSqAngle::MaxNAngleType"); } nAngleType_ = nAngleType; }
const TargetPhraseCollectionWithSourcePhrase* PhraseDictionary:: GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const& range) const { UTIL_THROW(util::Exception, "Legacy method not implemented"); //Phrase phrase = src.GetSubString(range); //return GetTargetPhraseCollection(phrase); }