Skip to content

Refactor TracePath to return a struct with relevant data#935

Open
AndresFerCervell wants to merge 4 commits into
gambitproject:masterfrom
AndresFerCervell:tracepath-return-value
Open

Refactor TracePath to return a struct with relevant data#935
AndresFerCervell wants to merge 4 commits into
gambitproject:masterfrom
AndresFerCervell:tracepath-return-value

Conversation

@AndresFerCervell

@AndresFerCervell AndresFerCervell commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Issues closed by this PR

None. Related to #492 and #876

Description of the changes in this PR

This PR adds a return structure in TracePath (src/solvers/logit/path.[cc/h]).
The struct has the following fields:

  • Final parameter value (“lambda” in our terminology)
  • Final vector (as represented in TracePath)
  • Status
  • Message (for the human-readable explanation)

I intended to pass that error upstream by returning an empty list in nfglogit and efglogit. However, it raises an exception in the Python API, so I have decided to remove it for now.

Therefore, this PR does not solve the problem of warning the user about not having found NE, but it keeps the struct that will be of use in the future.

If it is a priority to warn the C++ users when the NE is not found, a check could be easily implemented in logit.cc. Otherwise, I would wait until path.cc is abstracted to make all the changes together in Python too.

Suggestions are welcome!

How to review this PR

-Review the TracePathResult struct definition in path.h and the updated return statements in path.cc.

@tturocy tturocy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a minor change to be consistent in how we handle the vector of coordinates between calling the function and its return value.

Comment thread src/solvers/logit/path.cc

if (fabs(h) <= c_hmin) {
return;
return {x.back(), x, false, "Stepsize fell below minimum threshold."};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the setup of the return struct.

I can see the benefit of having the parameter value reported separately. But actually, we should also be consistent with the calling convention of the function. At the moment TracePath is actually completely independent of where the "parameter" ($\lambda$ for QRE) sits in the vector. In our implementation in QRE we put the parameter as the last coordinate, but we could just as easily make it the first coordinate and TracePath itself would operate exactly the same. So there's no guarantee that calling code necessarily is using x.back() here to be the free parameter.

To be parallel with the calling convention we can simply return final_point, and then this would leave it up to the calling code how it would interpret that point.

return RegretTerminationFunction(game, p_point, p_regret);
},
[&callback](const Vector<double> &p_point) -> void { callback.AppendPoint(p_point); });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ideally we try to avoid isolated whitespace changes unless they're tied to some adjacent changes, just to keep from having spurious diffs.

Comment thread src/tools/logit/logit.cc
return 1;
}
}
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is another whitespace change, but it involves removing the blank line at the end of the file. By convention files should end with a blank line. This should be caught by having the pre-commit hook installed, which is very useful for a lot of tidiness checking - see the dev docs at https://gambitproject.readthedocs.io/en/latest/developer.contributing.html#how-to-submit-a-contribution.

@tturocy tturocy added this to the gambit-16.7.0 milestone Jun 16, 2026
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.

2 participants