Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to do better at estimating playouts remaining, while requiring less time to do so. #582

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
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
19 changes: 14 additions & 5 deletions src/UCTSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,17 @@ bool UCTSearch::is_running() const {
}

int UCTSearch::est_playouts_left() const {
auto elapsed_millis = now() - m_start_time;
auto elapsed_millis = now() - m_time_after_initial_playouts;
auto playouts = m_playouts.load();
if (!Limits.dynamic_controls_set() && !Limits.movetime) {
// No time control, use playouts or visits.
const auto playouts_left =
std::max(0, std::min(m_maxplayouts - playouts,
m_maxnodes - m_root->get_visits()));
return playouts_left;
} else if (elapsed_millis < 1000 || playouts < 100) {
// Until we reach 1 second or 100 playouts playout_rate
// is not reliable, so just return max.
} else if (elapsed_millis < 10 || playouts < 10 * cfg_num_threads) {
// Until we reach 10 millisecond and 10 playouts per thread playout_rate
// is too risky to use, so just return max.
return MAXINT_DIV2;
} else {
const auto playout_rate = 1.0f * playouts / elapsed_millis;
Expand Down Expand Up @@ -446,6 +446,7 @@ Move UCTSearch::think(BoardHistory&& new_bh) {

bool keeprunning = true;
int last_update = 0;
bool initial_playouts_done = false;
do {
auto currstate = bh_.shallow_clone();
auto result = play_simulation(currstate, m_root.get(), 0);
Expand All @@ -458,7 +459,15 @@ Move UCTSearch::think(BoardHistory&& new_bh) {
last_update = depth;
dump_analysis(Time.elapsed(), false);
}

if (!initial_playouts_done) {
// Always update this time stamp so the pruning check is against
// an initialized value.
m_time_after_initial_playouts = now();
// One playout per thread, before we consider things warmed up.
if (m_playouts >= cpus) {
initial_playouts_done = true;
}
}
// check if we should still search
keeprunning = is_running();
keeprunning &= !should_halt_search();
Expand Down
1 change: 1 addition & 0 deletions src/UCTSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class UCTSearch {
int64_t m_target_time{0};
int64_t m_max_time{0};
int64_t m_start_time{0};
int64_t m_time_after_initial_playouts{0};
std::atomic<bool> m_run{false};
int m_maxplayouts;
int m_maxnodes;
Expand Down