stanfordnlp/CoreNLP · error · java.lang.UnsupportedOperationException

No maximum number of iterations has been specified.

Error message

No maximum number of iterations has been specified.

What it means

SGDWithAdaGradAndFOBOS.minimize() throws this UnsupportedOperationException when neither maxIterations nor numPasses has been set to a positive value, so the optimizer has no defined stopping point. SGD cannot run indefinitely, so this fail-fast check prevents an infinite training loop.

Solutions

  1. Call optimizer.setMaxIterations(n) with a positive n before minimize()
  2. Or call optimizer.setNumPasses(n) to specify passes over the data
  3. Check the options/properties parsing actually populates maxIterations or numPasses

Example fix

// before
SGDWithAdaGradAndFOBOS opt = new SGDWithAdaGradAndFOBOS();
opt.minimize(f, 1e-4, initial);
// after
SGDWithAdaGradAndFOBOS opt = new SGDWithAdaGradAndFOBOS();
opt.setMaxIterations(50000);
opt.minimize(f, 1e-4, initial);
Defensive patterns

Strategy: validation

Validate before calling

SGDWithAdaGradAndFOBOS opt = new SGDWithAdaGradAndFOBOS();
if (opt.maxIterations <= 0 && opt.numPasses <= 0) opt.setMaxIterations(50000);

Try / catch

try { opt.minimize(f, 1e-4, initial); } catch (UnsupportedOperationException e) { opt.setMaxIterations(50000); opt.minimize(f, 1e-4, initial); }

Prevention

When it happens

Trigger: Constructing SGDWithAdaGradAndFOBOS and calling minimize() without calling setMaxIterations(n) or setNumPasses(n) (or leaving both at their defaults of 0).

Common situations: Programmatic optimizer setup where the required setter was omitted; converting from batch optimizers (which converge on their own) to stochastic ones that require an iteration budget; properties/config file not supplying the iteration field.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/2a52c0ce1e3b5fca. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/optimization/SGDWithAdaGradAndFOBOS.java:343

      }
      featureGrouping = ((HasFeatureGrouping)f).getFeatureGrouping();
    }
    if (prior == Prior.sgLASSO) {
      bCache = new double[initial.length];
    }

    System.arraycopy(initial, 0, x, 0, x.length);

    int numBatches =  1;
    if (f instanceof AbstractStochasticCachingDiffUpdateFunction) {
      if (totalSamples > 0)
        numBatches = totalSamples / bSize;
    }

    boolean have_max = (maxIterations > 0 || numPasses > 0);

    if (!have_max){
      throw new UnsupportedOperationException("No maximum number of iterations has been specified.");
    } else{
      maxIterations = Math.max(maxIterations, numPasses*numBatches);
    }

    sayln("       Batch size of: " + bSize);
    sayln("       Data dimension of: " + totalSamples );
    sayln("       Batches per pass through data:  " + numBatches );
    sayln("       Number of passes is = " + numPasses);
    sayln("       Max iterations is = " + maxIterations);

    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    //            Loop
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Timing total = new Timing();
    Timing current = new Timing();

View on GitHub (pinned to 1b7edd19c4)