patrick-kidger / patrick-kidger/optimistix
Accessing the (success/not) result of the solver
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 623
- Forks
- 54
- PR merge metrics
- No merged PRs in 30d
Description
Hopefully this is trivial, but I'm having trouble accessing the success/not result of the solver:
Code snippet:
solver = optx.Newton(rtol=tol, atol=tol)
sol = optx.root_find(
self.objective_function,
solver,
initial_solution_guess,
args=(constraints,),
)
print("sol = ", sol)
result = sol.result
print("result = ", optx.RESULTS[result])
Output of print statements, note that nothing is returned for result = :
sol = Solution(
value=f64[3],
result=EnumerationItem(
_value=i32[],
_enumeration=<class 'optimistix._solution.RESULTS'>
),
aux=None,
stats={'max_steps': 256, 'num_steps': i64[]},
state=_NewtonChordState(
f=f64[3],
linear_state=None,
diff=f64[3],
diffsize=f64[],
diffsize_prev=f64[],
result=EnumerationItem(
_value=i32[],
_enumeration=<class 'optimistix._solution.RESULTS'>
),
step=i64[]
)
)
result =
I was expecting to see "successful" printed as per https://docs.kidger.site/optimistix/api/solution/ (I know the returned result is correct because I have a test suite I am comparing against and the numerical value is correct). I can access a '0' integer if I instead access the result._value attribute, but so far no luck getting the string message. I suspect I am using enums incorrectly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the optx.root_find result and the Solution API documentation linked in the issue, then reproduce the shown access pattern with optx.RESULTS. Check how the result enum is intended to be converted or displayed; done when the documented successful status is accessible without relying on the private _value attribute.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100