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
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
- [ ] Program icon/logo
- [ ] Desktop integration

- [ ] Implement function to set limit on ion histories or time to run
- [X] Implement function to set limit on ion histories or time to run
E.g., the "Ions to run" label can become a ToolButton, allowing the user
to set the limit either on the # of ions or in time

Expand Down
14 changes: 12 additions & 2 deletions source/gui/mcdriverobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "mcdriver.h"

#include <climits>
#include <fstream>

#include <QFile>
Expand All @@ -21,7 +22,8 @@ McDriverObj::McDriverObj()
max_ions_(100),
nThreads_(1),
seed_(123456789),
updInterval_(1000)
updInterval_(1000),
max_cpu_time_(0)
{
// internal start signal connection
connect(this, &McDriverObj::startSignal, this, &McDriverObj::start_, Qt::QueuedConnection);
Expand All @@ -45,10 +47,13 @@ void McDriverObj::setOptions(const mcconfig &opt, bool initFromFile)
{
options_ = opt;
if (initFromFile) {
max_ions_ = opt.Run.max_no_ions;
setMaxIons(opt.Run.max_no_ions);
nThreads_ = opt.Run.threads;
seed_ = opt.Run.seed;
updInterval_ = opt.Output.storage_interval;
setMaxCpuTime(opt.Run.max_cpu_time > static_cast<size_t>(INT_MAX)
? INT_MAX
: static_cast<int>(opt.Run.max_cpu_time));
}
emit configChanged();
setModified(true);
Expand All @@ -61,6 +66,7 @@ std::string McDriverObj::json() const
opt.Run.seed = seed_;
opt.Run.threads = nThreads_;
opt.Output.storage_interval = updInterval_;
opt.Run.max_cpu_time = static_cast<size_t>(max_cpu_time_);
return opt.toJSON();
}

Expand Down Expand Up @@ -143,6 +149,7 @@ bool McDriverObj::validateOptions(QString *msg) const
opt.Run.seed = seed_;
opt.Run.threads = nThreads_;
opt.Output.storage_interval = updInterval_;
opt.Run.max_cpu_time = static_cast<size_t>(max_cpu_time_);

bool isValid = true;

Expand Down Expand Up @@ -283,6 +290,7 @@ void McDriverObj::saveJson(const QString &fname)
opt.Run.seed = seed_;
opt.Run.threads = nThreads_;
opt.Output.storage_interval = updInterval_;
opt.Run.max_cpu_time = static_cast<size_t>(max_cpu_time_);
}

opt.Output.outfilename = fileName().toStdString();
Expand Down Expand Up @@ -347,6 +355,7 @@ void McDriverObj::start(bool b)
opt.Run.seed = seed_;
opt.Run.threads = nThreads_;
opt.Output.storage_interval = updInterval_;
opt.Run.max_cpu_time = static_cast<size_t>(max_cpu_time_);

driver_->init(opt);

Expand All @@ -360,6 +369,7 @@ void McDriverObj::start(bool b)
mcconfig::run_options par = driver_->config().Run;
par.max_no_ions = max_ions_;
par.threads = nThreads_;
par.max_cpu_time = static_cast<size_t>(max_cpu_time_);
driver_->setRunOptions(par);

mcconfig::output_options opts = driver_->config().Output;
Expand Down
17 changes: 14 additions & 3 deletions source/gui/mcdriverobj.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MCDRIVEROBJ_H
#define MCDRIVEROBJ_H

#include <algorithm>
#include <chrono>

#include <QObject>
Expand All @@ -25,6 +26,10 @@ class McDriverObj : public QObject
Q_OBJECT

public:
// Largest integer exactly representable as double (53-bit mantissa).
// QDoubleSpinBox uses double internally; larger integers lose precision.
static constexpr quint64 kMaxExactIons = 1ULL << 53;

// helper class for getting real-time info
// for the running simulation
class running_sim_info
Expand Down Expand Up @@ -131,18 +136,23 @@ class McDriverObj : public QObject
const mccore *getSim() const;

// get run parameters
size_t maxIons() const { return max_ions_; }
quint64 maxIons() const { return max_ions_; }
int nThreads() const { return nThreads_; }
int seed() const { return seed_; }
int updInterval() const { return updInterval_; }
int maxCpuTime() const { return max_cpu_time_; }

public slots:

// set run parameters
void setMaxIons(int n) { max_ions_ = n; };
void setMaxIons(quint64 n)
{
max_ions_ = (n >= 1) ? std::min(n, kMaxExactIons) : 1;
};
void setNThreads(int n) { nThreads_ = n; };
void setSeed(int n) { seed_ = n; }
void setUpdInterval(int n) { updInterval_ = n; }
void setMaxCpuTime(int n) { max_cpu_time_ = std::max(0, n); }

private slots:

Expand Down Expand Up @@ -187,10 +197,11 @@ private slots:
int io_ret_;
std::string io_err_;

size_t max_ions_;
quint64 max_ions_;
int nThreads_;
int seed_;
int updInterval_;
int max_cpu_time_;

// run info
running_sim_info info_;
Expand Down
41 changes: 34 additions & 7 deletions source/gui/simcontrolwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "optionsmodel.h"
#include "simulationoptionsview.h"

#include <climits>
#include <QTimer>
#include <QVBoxLayout>
#include <QHBoxLayout>
Expand All @@ -14,6 +15,7 @@
#include <QLineEdit>
#include <QToolButton>
#include <QProgressBar>
#include <QDoubleSpinBox>
#include <QSpinBox>
#include <QLabel>
#include <QStyle>
Expand Down Expand Up @@ -64,13 +66,17 @@ SimControlWidget::SimControlWidget(MainUI *ui, QWidget *parent)
// because they can be overriden every time we run the sim
OptionsModel *model = mainui_->optionsModel;
QModelIndex driverOptionsIdx = model->index("Run");
QModelIndex idx = model->index("max_no_ions", 0, driverOptionsIdx);
OptionsItem *item = model->getItem(idx);
sbIons = (QSpinBox *)item->createEditor(this);
// QSpinBox is limited to INT_MAX. Used QDoubleSpinBox with 0 decimals
// to support integer values up to 2^53 exactly
sbIons = new QDoubleSpinBox;
sbIons->setDecimals(0);
sbIons->setRange(1, static_cast<double>(McDriverObj::kMaxExactIons));
sbIons->setSingleStep(100'000);
sbIons->setValue(static_cast<double>(driver_->maxIons()));
simCtrls.push_back(sbIons);

idx = model->index("threads", 0, driverOptionsIdx);
item = model->getItem(idx);
QModelIndex idx = model->index("threads", 0, driverOptionsIdx);
OptionsItem *item = model->getItem(idx);
sbNThreads = (QSpinBox *)item->createEditor(this);
simCtrls.push_back(sbNThreads);

Expand All @@ -85,6 +91,15 @@ SimControlWidget::SimControlWidget(MainUI *ui, QWidget *parent)
sbSeed = (QSpinBox *)item->createEditor(this);
simCtrls.push_back(sbSeed);

// 0 means no time limit.
sbMaxTime = new QSpinBox;
sbMaxTime->setRange(0, INT_MAX);
sbMaxTime->setSingleStep(60);
sbMaxTime->setSuffix(" s");
sbMaxTime->setSpecialValueText("no limit");
sbMaxTime->setValue(driver_->maxCpuTime());
sbMaxTime->setToolTip("Stop after this many CPU seconds. With N threads, wall time will be ~1/N of this value. 0 means no time limit.");

/* Create Info items */

QStringList ctrlLabels{ "Ions to run", "Threads", "Upd period (ms)", "Seed" };
Expand Down Expand Up @@ -158,6 +173,13 @@ SimControlWidget::SimControlWidget(MainUI *ui, QWidget *parent)
icol++;
}
}
{
QHBoxLayout *hbox3 = new QHBoxLayout;
hbox3->addWidget(new QLabel("Max CPU time (s)"));
hbox3->addWidget(sbMaxTime);
hbox3->addStretch();
vbox->addLayout(hbox3);
}
{
QHBoxLayout *hbox2 = new QHBoxLayout;
hbox2->addWidget(runIndicator);
Expand Down Expand Up @@ -191,12 +213,15 @@ SimControlWidget::SimControlWidget(MainUI *ui, QWidget *parent)

connect(driver_, &McDriverObj::configChanged, this, &SimControlWidget::revert);

connect(sbIons, QOverload<int>::of(&QSpinBox::valueChanged), driver_, &McDriverObj::setMaxIons);
connect(sbIons, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
[this](double v) { driver_->setMaxIons(static_cast<quint64>(v)); });
connect(sbNThreads, QOverload<int>::of(&QSpinBox::valueChanged), driver_,
&McDriverObj::setNThreads);
connect(sbSeed, QOverload<int>::of(&QSpinBox::valueChanged), driver_, &McDriverObj::setSeed);
connect(sbUpdInterval, QOverload<int>::of(&QSpinBox::valueChanged), driver_,
&McDriverObj::setUpdInterval);
connect(sbMaxTime, QOverload<int>::of(&QSpinBox::valueChanged), driver_,
&McDriverObj::setMaxCpuTime);
}

void SimControlWidget::onStart(bool b)
Expand Down Expand Up @@ -283,6 +308,7 @@ void SimControlWidget::onDriverStatusChanged()
sbNThreads->setEnabled(st != McDriverObj::mcRunning);
sbUpdInterval->setEnabled(st != McDriverObj::mcRunning);
sbSeed->setEnabled(st == McDriverObj::mcReset);
sbMaxTime->setEnabled(st != McDriverObj::mcRunning);
}

QString mytimefmt_(double t, bool ceil = false)
Expand Down Expand Up @@ -333,8 +359,9 @@ void SimControlWidget::onSimulationCreated()

void SimControlWidget::revert()
{
sbIons->setValue(driver_->maxIons());
sbIons->setValue(static_cast<double>(driver_->maxIons()));
sbNThreads->setValue(driver_->nThreads());
sbSeed->setValue(driver_->seed());
sbUpdInterval->setValue(driver_->updInterval());
sbMaxTime->setValue(driver_->maxCpuTime());
}
6 changes: 4 additions & 2 deletions source/gui/simcontrolwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class QLineEdit;
class QLabel;
class QDoubleSpinBox;
class QSpinBox;
class QProgressBar;
class QToolButton;
Expand Down Expand Up @@ -35,11 +36,12 @@ private slots:
McDriverObj *driver_;
QToolButton *btStart;
QToolButton *btReset;
QSpinBox *sbIons;
QDoubleSpinBox *sbIons;
QSpinBox *sbNThreads;
QSpinBox *sbSeed;
QSpinBox *sbUpdInterval;
std::vector<QSpinBox *> simCtrls;
QSpinBox *sbMaxTime;
std::vector<QWidget *> simCtrls;
std::vector<QLineEdit *> simIndicators;
QProgressBar *progressBar;
QLabel *runIndicator;
Expand Down