Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/command/genbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ int MainCmds::genbook(const vector<string>& args) {
if(!bonusInitialBoard.isEqualForTesting(book->getInitialHist().getRecentBoard(0), false, false))
throw StringError(
"Book initial board and initial board in bonus sgf file do not match\n" +
Board::toStringSimple(book->getInitialHist().getRecentBoard(0),'\n') + "\n" +
Board::toStringSimple(bonusInitialBoard,'\n')
Board::toStringSimple(book->getInitialHist().getRecentBoard(0)) + "\n" +
Board::toStringSimple(bonusInitialBoard)
);
if(bonusInitialPla != book->initialPla)
throw StringError(
Expand Down
4 changes: 2 additions & 2 deletions cpp/command/selfplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ int MainCmds::selfplay(const vector<string>& args) {

//Note that this inputsVersion passed here is NOT necessarily the same as the one used in the neural net self play, it
//simply controls the input feature version for the written data
TrainingDataWriter* tdataWriter = new TrainingDataWriter(
tdataOutputDir, inputsVersion, maxRowsPerTrainFile, firstFileRandMinProp, dataBoardLen, dataBoardLen, Global::uint64ToHexString(rand.nextUInt64()));
auto tdataWriter = new TrainingDataWriter(
tdataOutputDir, nullptr, inputsVersion, maxRowsPerTrainFile, firstFileRandMinProp, dataBoardLen, dataBoardLen, Global::uint64ToHexString(rand.nextUInt64()));
ofstream* sgfOut = NULL;
if(sgfOutputDir.length() > 0) {
sgfOut = new ofstream();
Expand Down
127 changes: 15 additions & 112 deletions cpp/core/config_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "../core/fileutils.h"

#include <cmath>
#include <fstream>
#include <sstream>

Expand Down Expand Up @@ -113,8 +112,6 @@ void ConfigParser::processIncludedFile(const std::string &fname) {
baseDirs.pop_back();
}



bool ConfigParser::parseKeyValue(const std::string& trimmedLine, std::string& key, std::string& value) {
// Parse trimmed line, taking into account comments and quoting.
key.clear();
Expand Down Expand Up @@ -598,14 +595,7 @@ enabled_t ConfigParser::getEnabled(const string& key) {
return x;
}

int ConfigParser::getInt(const string& key) {
string value = getString(key);
int x;
if(!Global::tryStringToInt(value,x))
throw IOError("Could not parse '" + value + "' as int for key '" + key + "' in config file " + fileName);
return x;
}
int ConfigParser::getInt(const string& key, int min, int max) {
int ConfigParser::getInt(const string& key, const int min, const int max) {
assert(min <= max);
string value = getString(key);
int x;
Expand All @@ -615,19 +605,8 @@ int ConfigParser::getInt(const string& key, int min, int max) {
throw IOError("Key '" + key + "' must be in the range " + Global::intToString(min) + " to " + Global::intToString(max) + " in config file " + fileName);
return x;
}
vector<int> ConfigParser::getInts(const string& key) {
vector<string> values = getStrings(key);
vector<int> ret;
for(size_t i = 0; i<values.size(); i++) {
const string& value = values[i];
int x;
if(!Global::tryStringToInt(value,x))
throw IOError("Could not parse '" + value + "' as int for key '" + key + "' in config file " + fileName);
ret.push_back(x);
}
return ret;
}
vector<int> ConfigParser::getInts(const string& key, int min, int max) {

vector<int> ConfigParser::getInts(const string& key, const int min, const int max) {
vector<string> values = getStrings(key);
vector<int> ret;
for(size_t i = 0; i<values.size(); i++) {
Expand Down Expand Up @@ -670,15 +649,7 @@ vector<std::pair<int,int>> ConfigParser::getNonNegativeIntDashedPairs(const stri
return ret;
}


int64_t ConfigParser::getInt64(const string& key) {
string value = getString(key);
int64_t x;
if(!Global::tryStringToInt64(value,x))
throw IOError("Could not parse '" + value + "' as int64_t for key '" + key + "' in config file " + fileName);
return x;
}
int64_t ConfigParser::getInt64(const string& key, int64_t min, int64_t max) {
int64_t ConfigParser::getInt64(const string& key, const int64_t min, const int64_t max) {
assert(min <= max);
string value = getString(key);
int64_t x;
Expand All @@ -688,19 +659,8 @@ int64_t ConfigParser::getInt64(const string& key, int64_t min, int64_t max) {
throw IOError("Key '" + key + "' must be in the range " + Global::int64ToString(min) + " to " + Global::int64ToString(max) + " in config file " + fileName);
return x;
}
vector<int64_t> ConfigParser::getInt64s(const string& key) {
vector<string> values = getStrings(key);
vector<int64_t> ret;
for(size_t i = 0; i<values.size(); i++) {
const string& value = values[i];
int64_t x;
if(!Global::tryStringToInt64(value,x))
throw IOError("Could not parse '" + value + "' as int64_t for key '" + key + "' in config file " + fileName);
ret.push_back(x);
}
return ret;
}
vector<int64_t> ConfigParser::getInt64s(const string& key, int64_t min, int64_t max) {

vector<int64_t> ConfigParser::getInt64s(const string& key, const int64_t min, const int64_t max) {
vector<string> values = getStrings(key);
vector<int64_t> ret;
for(size_t i = 0; i<values.size(); i++) {
Expand All @@ -715,15 +675,7 @@ vector<int64_t> ConfigParser::getInt64s(const string& key, int64_t min, int64_t
return ret;
}


uint64_t ConfigParser::getUInt64(const string& key) {
string value = getString(key);
uint64_t x;
if(!Global::tryStringToUInt64(value,x))
throw IOError("Could not parse '" + value + "' as uint64_t for key '" + key + "' in config file " + fileName);
return x;
}
uint64_t ConfigParser::getUInt64(const string& key, uint64_t min, uint64_t max) {
uint64_t ConfigParser::getUInt64(const string& key, const uint64_t min, const uint64_t max) {
assert(min <= max);
string value = getString(key);
uint64_t x;
Expand All @@ -733,19 +685,8 @@ uint64_t ConfigParser::getUInt64(const string& key, uint64_t min, uint64_t max)
throw IOError("Key '" + key + "' must be in the range " + Global::uint64ToString(min) + " to " + Global::uint64ToString(max) + " in config file " + fileName);
return x;
}
vector<uint64_t> ConfigParser::getUInt64s(const string& key) {
vector<string> values = getStrings(key);
vector<uint64_t> ret;
for(size_t i = 0; i<values.size(); i++) {
const string& value = values[i];
uint64_t x;
if(!Global::tryStringToUInt64(value,x))
throw IOError("Could not parse '" + value + "' as uint64_t for key '" + key + "' in config file " + fileName);
ret.push_back(x);
}
return ret;
}
vector<uint64_t> ConfigParser::getUInt64s(const string& key, uint64_t min, uint64_t max) {

vector<uint64_t> ConfigParser::getUInt64s(const string& key, const uint64_t min, const uint64_t max) {
vector<string> values = getStrings(key);
vector<uint64_t> ret;
for(size_t i = 0; i<values.size(); i++) {
Expand All @@ -760,15 +701,7 @@ vector<uint64_t> ConfigParser::getUInt64s(const string& key, uint64_t min, uint6
return ret;
}


float ConfigParser::getFloat(const string& key) {
string value = getString(key);
float x;
if(!Global::tryStringToFloat(value,x))
throw IOError("Could not parse '" + value + "' as float for key '" + key + "' in config file " + fileName);
return x;
}
float ConfigParser::getFloat(const string& key, float min, float max) {
float ConfigParser::getFloat(const string& key, const float min, const float max) {
assert(min <= max);
string value = getString(key);
float x;
Expand All @@ -780,19 +713,8 @@ float ConfigParser::getFloat(const string& key, float min, float max) {
throw IOError("Key '" + key + "' must be in the range " + Global::floatToString(min) + " to " + Global::floatToString(max) + " in config file " + fileName);
return x;
}
vector<float> ConfigParser::getFloats(const string& key) {
vector<string> values = getStrings(key);
vector<float> ret;
for(size_t i = 0; i<values.size(); i++) {
const string& value = values[i];
float x;
if(!Global::tryStringToFloat(value,x))
throw IOError("Could not parse '" + value + "' as float for key '" + key + "' in config file " + fileName);
ret.push_back(x);
}
return ret;
}
vector<float> ConfigParser::getFloats(const string& key, float min, float max) {

vector<float> ConfigParser::getFloats(const string& key, const float min, const float max) {
vector<string> values = getStrings(key);
vector<float> ret;
for(size_t i = 0; i<values.size(); i++) {
Expand All @@ -809,15 +731,7 @@ vector<float> ConfigParser::getFloats(const string& key, float min, float max) {
return ret;
}


double ConfigParser::getDouble(const string& key) {
string value = getString(key);
double x;
if(!Global::tryStringToDouble(value,x))
throw IOError("Could not parse '" + value + "' as double for key '" + key + "' in config file " + fileName);
return x;
}
double ConfigParser::getDouble(const string& key, double min, double max) {
double ConfigParser::getDouble(const string& key, const double min, const double max) {
assert(min <= max);
string value = getString(key);
double x;
Expand All @@ -829,19 +743,8 @@ double ConfigParser::getDouble(const string& key, double min, double max) {
throw IOError("Key '" + key + "' must be in the range " + Global::doubleToString(min) + " to " + Global::doubleToString(max) + " in config file " + fileName);
return x;
}
vector<double> ConfigParser::getDoubles(const string& key) {
vector<string> values = getStrings(key);
vector<double> ret;
for(size_t i = 0; i<values.size(); i++) {
const string& value = values[i];
double x;
if(!Global::tryStringToDouble(value,x))
throw IOError("Could not parse '" + value + "' as double for key '" + key + "' in config file " + fileName);
ret.push_back(x);
}
return ret;
}
vector<double> ConfigParser::getDoubles(const string& key, double min, double max) {

vector<double> ConfigParser::getDoubles(const string& key, const double min, const double max) {
vector<string> values = getStrings(key);
vector<double> ret;
for(size_t i = 0; i<values.size(); i++) {
Expand Down
30 changes: 10 additions & 20 deletions cpp/core/config_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,24 @@ class ConfigParser {
std::string getString(const std::string& key);
bool getBool(const std::string& key);
enabled_t getEnabled(const std::string& key);
int getInt(const std::string& key);
int64_t getInt64(const std::string& key);
uint64_t getUInt64(const std::string& key);
float getFloat(const std::string& key);
double getDouble(const std::string& key);

std::string getString(const std::string& key, const std::set<std::string>& possibles);
int getInt(const std::string& key, int min, int max);
int64_t getInt64(const std::string& key, int64_t min, int64_t max);
uint64_t getUInt64(const std::string& key, uint64_t min, uint64_t max);
float getFloat(const std::string& key, float min, float max);
double getDouble(const std::string& key, double min, double max);
int getInt(const std::string& key, int min = std::numeric_limits<int>::min(), int max = std::numeric_limits<int>::max());
int64_t getInt64(const std::string& key, int64_t min = std::numeric_limits<int64_t>::min(), int64_t max = std::numeric_limits<int64_t>::max());
uint64_t getUInt64(const std::string& key, uint64_t min = std::numeric_limits<uint64_t>::min(), uint64_t max = std::numeric_limits<uint64_t>::max());
float getFloat(const std::string& key, float min = std::numeric_limits<float>::min(), float max = std::numeric_limits<float>::max());
double getDouble(const std::string& key, double min = std::numeric_limits<double>::min(), double max = std::numeric_limits<double>::max());

std::vector<std::string> getStrings(const std::string& key);
std::vector<std::string> getStringsNonEmptyTrim(const std::string& key);
std::vector<bool> getBools(const std::string& key);
std::vector<int> getInts(const std::string& key);
std::vector<int64_t> getInt64s(const std::string& key);
std::vector<uint64_t> getUInt64s(const std::string& key);
std::vector<float> getFloats(const std::string& key);
std::vector<double> getDoubles(const std::string& key);

std::vector<std::string> getStrings(const std::string& key, const std::set<std::string>& possibles);
std::vector<int> getInts(const std::string& key, int min, int max);
std::vector<int64_t> getInt64s(const std::string& key, int64_t min, int64_t max);
std::vector<uint64_t> getUInt64s(const std::string& key, uint64_t min, uint64_t max);
std::vector<float> getFloats(const std::string& key, float min, float max);
std::vector<double> getDoubles(const std::string& key, double min, double max);
std::vector<int> getInts(const std::string& key, int min = std::numeric_limits<int>::min(), int max = std::numeric_limits<int>::max());
std::vector<int64_t> getInt64s(const std::string& key, int64_t min = std::numeric_limits<int64_t>::min(), int64_t max = std::numeric_limits<int64_t>::max());
std::vector<uint64_t> getUInt64s(const std::string& key, uint64_t min = std::numeric_limits<uint64_t>::min(), uint64_t max = std::numeric_limits<uint64_t>::max());
std::vector<float> getFloats(const std::string& key, float min = std::numeric_limits<float>::min(), float max = std::numeric_limits<float>::max());
std::vector<double> getDoubles(const std::string& key, double min = std::numeric_limits<double>::min(), double max = std::numeric_limits<double>::max());

std::vector<std::pair<int,int>> getNonNegativeIntDashedPairs(const std::string& key, int min, int max);

Expand Down
32 changes: 16 additions & 16 deletions cpp/dataio/trainingwrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,48 +954,48 @@ void TrainingWriteBuffers::writeToTextOstream(ostream& out) {

//-------------------------------------------------------------------------------------

TrainingDataWriter::TrainingDataWriter(const string& outDir, int iVersion, int maxRowsPerFile, double firstFileMinRandProp, int dataXLen, int dataYLen, const string& randSeed)
: TrainingDataWriter(outDir,NULL,iVersion,maxRowsPerFile,firstFileMinRandProp,dataXLen,dataYLen,1,randSeed)
{}
TrainingDataWriter::TrainingDataWriter(ostream* dbgOut, int iVersion, int maxRowsPerFile, double firstFileMinRandProp, int dataXLen, int dataYLen, int onlyEvery, const string& randSeed)
: TrainingDataWriter(string(),dbgOut,iVersion,maxRowsPerFile,firstFileMinRandProp,dataXLen,dataYLen,onlyEvery,randSeed)
{}

TrainingDataWriter::TrainingDataWriter(const string& outDir, ostream* dbgOut, int iVersion, int maxRowsPerFile, double firstFileMinRandProp, int dataXLen, int dataYLen, int onlyEvery, const string& randSeed)
:outputDir(outDir),inputsVersion(iVersion),rand(randSeed),writeBuffers(NULL),debugOut(dbgOut),debugOnlyWriteEvery(onlyEvery),rowCount(0)
TrainingDataWriter::TrainingDataWriter(const string& outDir, ostream* dbgOut,
const int iVersion,
const int maxRowsPerFile,
const double firstFileMinRandProp,
const int dataXLen,
const int dataYLen,
const string& randSeed,
const int onlyWriteEvery)
:outputDir(outDir),inputsVersion(iVersion),rand(randSeed),writeBuffers(nullptr),debugOut(dbgOut),debugOnlyWriteEvery(onlyWriteEvery),rowCount(0)
{
int numBinaryChannels;
int numGlobalChannels;
//Note that this inputsVersion is for data writing, it might be different than the inputsVersion used
//to feed into a model during selfplay
static_assert(NNModelVersion::latestInputsVersionImplemented == 7, "");
if(inputsVersion == 3) {
if(iVersion == 3) {
numBinaryChannels = NNInputs::NUM_FEATURES_SPATIAL_V3;
numGlobalChannels = NNInputs::NUM_FEATURES_GLOBAL_V3;
}
else if(inputsVersion == 4) {
else if(iVersion == 4) {
numBinaryChannels = NNInputs::NUM_FEATURES_SPATIAL_V4;
numGlobalChannels = NNInputs::NUM_FEATURES_GLOBAL_V4;
}
else if(inputsVersion == 5) {
else if(iVersion == 5) {
numBinaryChannels = NNInputs::NUM_FEATURES_SPATIAL_V5;
numGlobalChannels = NNInputs::NUM_FEATURES_GLOBAL_V5;
}
else if(inputsVersion == 6) {
else if(iVersion == 6) {
numBinaryChannels = NNInputs::NUM_FEATURES_SPATIAL_V6;
numGlobalChannels = NNInputs::NUM_FEATURES_GLOBAL_V6;
}
else if(inputsVersion == 7) {
else if(iVersion == 7) {
numBinaryChannels = NNInputs::NUM_FEATURES_SPATIAL_V7;
numGlobalChannels = NNInputs::NUM_FEATURES_GLOBAL_V7;
}
else {
throw StringError("TrainingDataWriter: Unsupported inputs version: " + Global::intToString(inputsVersion));
throw StringError("TrainingDataWriter: Unsupported inputs version: " + Global::intToString(iVersion));
}

const bool hasMetadataInput = false;
writeBuffers = new TrainingWriteBuffers(
inputsVersion,
iVersion,
maxRowsPerFile,
numBinaryChannels,
numGlobalChannels,
Expand Down
4 changes: 1 addition & 3 deletions cpp/dataio/trainingwrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ struct TrainingWriteBuffers {

class TrainingDataWriter {
public:
TrainingDataWriter(const std::string& outputDir, int inputsVersion, int maxRowsPerFile, double firstFileMinRandProp, int dataXLen, int dataYLen, const std::string& randSeed);
TrainingDataWriter(std::ostream* debugOut, int inputsVersion, int maxRowsPerFile, double firstFileMinRandProp, int dataXLen, int dataYLen, int onlyWriteEvery, const std::string& randSeed);
TrainingDataWriter(const std::string& outputDir, std::ostream* debugOut, int inputsVersion, int maxRowsPerFile, double firstFileMinRandProp, int dataXLen, int dataYLen, int onlyWriteEvery, const std::string& randSeed);
TrainingDataWriter(const std::string& outDir, std::ostream* dbgOut, int iVersion, int maxRowsPerFile, double firstFileMinRandProp, int dataXLen, int dataYLen, const std::string& randSeed, int onlyWriteEvery = 1);
~TrainingDataWriter();

void writeGame(const FinishedGameData& data);
Expand Down
4 changes: 0 additions & 4 deletions cpp/game/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2688,10 +2688,6 @@ string Board::toStringSimple(const Board& board, char lineDelimiter) {
return s;
}

Board Board::parseBoard(int xSize, int ySize, const string& s) {
return parseBoard(xSize,ySize,s,'\n');
}

Board Board::parseBoard(int xSize, int ySize, const string& s, char lineDelimiter) {
Board board(xSize,ySize);
vector<string> lines = Global::split(Global::trim(s),lineDelimiter);
Expand Down
7 changes: 3 additions & 4 deletions cpp/game/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,11 @@ struct Board
void checkConsistency() const;
//For the moment, only used in testing since it does extra consistency checks.
//If we need a version to be used in "prod", we could make an efficient version maybe as operator==.
bool isEqualForTesting(const Board& other, bool checkNumCaptures, bool checkSimpleKo) const;
bool isEqualForTesting(const Board& other, bool checkNumCaptures = true, bool checkSimpleKo = true) const;

static Board parseBoard(int xSize, int ySize, const std::string& s);
static Board parseBoard(int xSize, int ySize, const std::string& s, char lineDelimiter);
static Board parseBoard(int xSize, int ySize, const std::string& s, char lineDelimiter = '\n');
static void printBoard(std::ostream& out, const Board& board, Loc markLoc, const std::vector<Move>* hist);
static std::string toStringSimple(const Board& board, char lineDelimiter);
static std::string toStringSimple(const Board& board, char lineDelimiter = '\n');
static nlohmann::json toJson(const Board& board);
static Board ofJson(const nlohmann::json& data);

Expand Down
4 changes: 0 additions & 4 deletions cpp/game/boardhistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,10 +914,6 @@ bool BoardHistory::makeBoardMoveTolerant(Board& board, Loc moveLoc, Player moveP
return true;
}

void BoardHistory::makeBoardMoveAssumeLegal(Board& board, Loc moveLoc, Player movePla, const KoHashTable* rootKoHashTable) {
makeBoardMoveAssumeLegal(board,moveLoc,movePla,rootKoHashTable,false);
}

void BoardHistory::makeBoardMoveAssumeLegal(Board& board, Loc moveLoc, Player movePla, const KoHashTable* rootKoHashTable, bool preventEncore) {
Hash128 posHashBeforeMove = board.pos_hash;

Expand Down
Loading