<commit_before>/** @package TBTKTools
 *  @file main.cpp
 *  @brief Estimates the DOS using random smapling of LDOS.
 *
 *  Reads model from text file and estimates the DOS using the
 *  ChebyshevSolver.
 *
 *  Takes filename of file to parse as first argument.
 *
 *  @author <NAME>
 */

#include "Model.h"
#include "FileParser.h"
#include "ChebyshevSolver.h"
#include "CPropertyExtractor.h"
#include "DOS.h"
#include "FileWriter.h"
#include "Util.h"
#include "GPUResourceManager.h"
#include "Streams.h"

#include <complex>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <getopt.h>

using namespace std;
using namespace TBTK;

const complex<double> i(0, 1);
int main(int argc, char **argv){
	Util::Streams::openLog();
	int isVerbose		= false;
	int forceGPU		= false;
	int forceCPU		= false;
	int numSamples		= 100;
	int scaleFactor		= 20;
	int numCoefficients	= 5000;
	int energyResolution	= 10000;

	while(true){
		static struct option long_options[] = {
			//Sets flags.
			{"verbose",		no_argument,		&isVerbose,	1},
			{"use-gpu",		no_argument,		&forceGPU,	1},
			{"use-cpu",		no_argument,		&forceCPU,	1},
			//Does not set flags.
			{"scale-factor",	required_argument,	0,		's'},
			{"coefficients",	required_argument,	0,		'c'},
			{"energy-resolution",	required_argument,	0,		'r'},
			{"samples",		required_argument,	0,		'S'},
			{0,			0,			0,		0}
		};

		int option_index = 0;
		int c = getopt_long(argc, argv, "s:c:r:S:", long_options, &option_index);
		if(c == -1)
			break;

		switch(c){
		case 0:
			//If the option sets a flag, do nothing.
			if(long_options[option_index].flag != 0)
				break;
			cout << "option " << long_options[option_index].name;
			if(optarg)
				cout << " with argument " << optarg;
			cout << "\n";
			break;
		case 's':
			scaleFactor = atof(optarg);
			break;
		case 'c':
			numCoefficients = atoi(optarg);
			break;
		case 'r':
			energyResolution = atoi(optarg);
			break;
		case 'S':
			numSamples = atoi(optarg);
			break;
		default:
			cout << "Error: Unknown argument.\n";
			exit(1);
		}
	}

	//Supress output if not verbose
	if(!isVerbose){
		Util::Streams::setStdMuteOut();
		Util::Streams::setStdMuteErr();
	}

	//Get input file name
	if(argc != optind+1){
		cout << "Input file missing.\n";
		exit(1);
	}
	string fileName = argv[optind];

	//Use GPU if devices
	bool useGPU;
	if(GPUResourceManager::getInstance().getNumDevices() > 0)
		useGPU = true;
	else
		useGPU = false;

	if(forceGPU && forceCPU){
		Util::Streams::err << "Error: --use-cpu and --use-gpu cannot be simultaneously specified.\n";
		exit(1);
	}
	if(forceGPU)
		useGPU = true;
	if(forceCPU)
		useGPU = false;

	//Parse model from file and setup output target
	Model *model = FileParser::readModel(fileName);
	model->constructCOO();

	FileWriter::setFileName("TBTKResults.h5");

	//Setup ChebyshevSolver and corresponding PropertyExtractor
	ChebyshevSolver cSolver;
	cSolver.setModel(model);
	cSolver.setScaleFactor(scaleFactor);

	CPropertyExtractor pe(
		&cSolver,
		numCoefficients,<commit_msg>Updated EstimateDOS to use TBTKAssert and TBTKExit<commit_after>/** @package TBTKTools
 *  @file main.cpp
 *  @brief Estimates the DOS using random smapling of LDOS.
 *
 *  Reads model from text file and estimates the DOS using the
 *  ChebyshevSolver.
 *
 *  Takes filename of file to parse as first argument.
 *
 *  @author <NAME>
 */

#include "Model.h"
#include "FileParser.h"
#include "ChebyshevSolver.h"
#include "CPropertyExtractor.h"
#include "DOS.h"
#include "FileWriter.h"
#include "Util.h"
#include "GPUResourceManager.h"
#include "Streams.h"

#include <complex>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <getopt.h>

using namespace std;
using namespace TBTK;

const complex<double> i(0, 1);
int main(int argc, char **argv){
	Util::Streams::openLog();
	int isVerbose		= false;
	int forceGPU		= false;
	int forceCPU		= false;
	int numSamples		= 100;
	int scaleFactor		= 20;
	int numCoefficients	= 5000;
	int energyResolution	= 10000;

	while(true){
		static struct option long_options[] = {
			//Sets flags.
			{"verbose",		no_argument,		&isVerbose,	1},
			{"use-gpu",		no_argument,		&forceGPU,	1},
			{"use-cpu",		no_argument,		&forceCPU,	1},
			//Does not set flags.
			{"scale-factor",	required_argument,	0,		's'},
			{"coefficients",	required_argument,	0,		'c'},
			{"energy-resolution",	required_argument,	0,		'r'},
			{"samples",		required_argument,	0,		'S'},
			{0,			0,			0,		0}
		};

		int option_index = 0;
		int c = getopt_long(argc, argv, "s:c:r:S:", long_options, &option_index);
		if(c == -1)
			break;

		switch(c){
		case 0:
			//If the option sets a flag, do nothing.
			if(long_options[option_index].flag != 0)
				break;
			cout << "option " << long_options[option_index].name;
			if(optarg)
				cout << " with argument " << optarg;
			cout << "\n";
			break;
		case 's':
			scaleFactor = atof(optarg);
			break;
		case 'c':
			numCoefficients = atoi(optarg);
			break;
		case 'r':
			energyResolution = atoi(optarg);
			break;
		case 'S':
			numSamples = atoi(optarg);
			break;
		default:
			TBTKExit(
				"EstimateDOS",
				"Unknown argument.",
				""
			);
		}
	}

	//Supress output if not verbose
	if(!isVerbose)
		Util::Streams::setStdMuteOut();

	//Get input file name
	TBTKAssert(
		argc == optind+1,
		"EstimateDOS",
		"Input file missing.",
		""
	);
	string fileName = argv[optind];

	//Use GPU if devices
	bool useGPU;
	if(GPUResourceManager::getInstance().getNumDevices() > 0)
		useGPU = true;
	else
		useGPU = false;

	TBTKAssert(
		!(forceGPU && forceCPU),
		"EstimateDOS",
		"--use-cpu and --use-gpu cannot be simultaneously specified.",
		""
	);
	if(forceGPU)
		useGPU = true;
	if(forceCPU)
		useGPU = false;

	//Parse model from file and setup output target
	Model *model = FileParser::readModel(fileName);
	model->constructCOO();

	FileWriter::setFileName("TBTKResults.h5");

	//Setup ChebyshevSolver and corresponding PropertyExtractor
	ChebyshevSolver cSolver;
	cSolver.setModel(model);
	cSolver.setScaleFactor(scaleFactor);

	CPropertyExtractor pe(
		&cSolver,
		numCoefficients,
{'fraction_non_alphanumeric': 0.1457236842105263, 'fraction_numerical': 0.011677631578947368, 'mean_word_length': 3.795741324921136, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2860607', 'n_tokens_mistral': 2568, 'n_tokens_neox': 2283, 'n_words': 580}