stan-dev / stan-dev/stan

Infinite loop in `WolfLSZoom` when using stan for optimization

Open
#3,229 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.8k
Forks
388
Avg merge
2d 17h
Merged PRs (30d)
15

Description

Summary:

Infinite loop in WolfLSZoom when using stan for optimization

Description:

When using Stan for optimization (with optimizing in rStan), the function WolfLSZoom (file bgfs_linesearch.hpp) is called, and causes infinite loop in some conditions.

When I run my script, it appears to be stuck in an infinite loop. Using Gdb on the code, I get the following values for local variables in the main loop of the WolfLSZoom function:

itNum = 59171617
alo = 0.73678486652303887
ahi = 0.73678486652303898

This indicates that there is indeed an infinite loop (itNum is high). The reason for that is that the loop is expected to terminate when ahi-alo < min_range, but ahi and alo stay constant because of rounding errors in the loop, and, in my particular case, ahi-alo = 2^(-53) > min_range = 10^(-16).

Do we expect to always have abs(ahi) < 1 and abs(alo) < 1? If so, then a simple fix could be to choose a larger value for min_range (10^(-15) would do the trick).

Reproducible Steps:

The bug is 100% reproducible with my R script, but, unfortunately, I cannot publish the source code of my example.

Version:

I am using rStan 2.21.8, but the bug seems to still exist in Stan's sources.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in bgfs_linesearch.hpp at the WolfLSZoom main loop and inspect how alo, ahi, itNum, and min_range interact when rounding prevents the interval from changing. Reproduce the reported boundary case if possible, then define a regression test that confirms the loop terminates without changing unrelated optimization behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.