Skip to content

Conversation

@rocky
Copy link
Member

@rocky rocky commented Aug 23, 2025

Fixes #1476

There are probably more places where we need to do something similar, but this is a start.

@rocky rocky force-pushed the IterationLimit-fix branch 3 times, most recently from 3be2a1b to 6aaacb0 Compare August 23, 2025 19:09
@rocky rocky marked this pull request as draft August 23, 2025 19:19
# Also, we can get either a MaxIterations failure, *or* a $IterationLimit error.
#
# For a not so well behaving function, the result can be less accurate:
# >> FindMaximum[-Exp[-1/x^2]+1., {x,1.2}, MaxIterations->10]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In[4]:= FindMaximum[-Exp[-1/x^2]+1., {x,1.2}, MaxIterations->2]                 

FindMaximum::cvmit: 
   Failed to converge to the requested accuracy or precision within 2
     iterations.

Out[4]= {1., {x -> 0.168461}}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. For FindMaximum, at iterations 2 it fails. At 10 though it doesn't which is what the test was.

Also, when it fails, it gives a value, and Mathics3 does not.

@rocky
Copy link
Member Author

rocky commented Aug 24, 2025

@mmatera: I am seeing here that we get a lot of Iteration limit occurrences in FindRoot, and one in combinatorica testing. I haven't had time to track these down.

But there is a bit here that should be done independent of improving $InterationLimit. As too often is the case, in looking at failures, there is a bit of other stuff that should be improved.

In particular, I think we should set the IterationLimit to 4096 as it is in WMA. And then to deal with the slowness of tests that were we to hit 4096, we set that in a Module with a local setting.

So at some point I'll split this PR in two.

rocky and others added 3 commits August 24, 2025 14:29
However also go over adjust tests so that they don't slow down.
Co-authored-by: Juan Mauricio Matera <matera@fisica.unlp.edu.ar>
@rocky rocky force-pushed the IterationLimit-fix branch from 5fab132 to 5fc89db Compare August 24, 2025 18:30

# iteration is used to keep track of evaluation chains and is
# compared against $IterationLimit.
self.iteration_count = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In MathicsSession, the same evaluation object is used in all the evaluations of the session. At which point self.iteration_count is reset to 0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - thanks. So we should reset this on each test.

We've added a number of other fields too, so those should probably be reset as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the old Mathics, one Evaluation object was created each time a line in the CLI or a cell in the web interface was executed. At some point, we change this behavior because most of the time, the Evaluation object does not change between evaluations. Now, since the evaluation always starts with a call to evaluation in the MathicsSession object, it is sufficient to reset the value there.

@rocky rocky marked this pull request as ready for review August 24, 2025 21:44
@rocky
Copy link
Member Author

rocky commented Aug 24, 2025

@mmatera if this is okay to go as one PR, great. If not, I'll split it in two tomorrow along the lines mentioned before.

@mmatera
Copy link
Contributor

mmatera commented Aug 24, 2025

@mmatera if this is okay to go as one PR, great. If not, I'll split it in two tomorrow along the lines mentioned before.

I think this is OK for now. Then, I can try to fix the output of FindMinimum and friends.

@mmatera
Copy link
Contributor

mmatera commented Aug 24, 2025

LGTM. @rocky, merge this when you feel it is ready.

@rocky rocky merged commit a06eab1 into master Aug 24, 2025
13 checks passed
@rocky rocky deleted the IterationLimit-fix branch August 24, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$IterationLimit is not limiting evalation expansion

3 participants