Skip to content

Commit 64cd8a1

Browse files
committed
added post step
1 parent 12de2de commit 64cd8a1

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def gradient(self, x):
1414
def hessian(self, x):
1515
return 2.0 * scipy.sparse.eye(x.size, format="csc")
1616

17+
def post_step(self, iter_num, solver_info, x, grad):
18+
print(f"Iteration {iter_num}: x = {x}, grad = {grad}")
1719

1820
x, result = polysolve.minimize(
1921
Quadratic(),

src/polysolve.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,15 @@ namespace
196196
return f(x).cast<bool>();
197197
return Problem::stop(x);
198198
}
199+
200+
void post_step(const polysolve::nonlinear::PostStepData &data) override
201+
{
202+
py::gil_scoped_acquire gil;
203+
if (py::function f = optional_override(this, "post_step"))
204+
f(data.iter_num, data.solver_info, data.x, data.grad);
205+
}
199206
};
207+
200208
} // namespace
201209

202210
PYBIND11_MODULE(polysolve, m)

0 commit comments

Comments
 (0)