torchspin.fitgui#
The interactive fitting panel needs the gui extra
(pip install "torchspin[gui]"). TorchSpin — interactive fitting panel (torchspin.fitgui) shows it in
use.
Interactive fitting panel for Jupyter (ipywidgets + matplotlib).
FitSession runs torchspin.esfit() in a background thread and collects the
live progress (through FitOptions.progress); FitPanel shows parameter sliders
with bounds and “fix” toggles, method/budget controls, Start/Stop/Reset buttons, and a
figure with data, current best fit, residual and the RMSD trace. In JupyterLab use
%matplotlib widget (ipympl) for a live canvas; with any other backend the figure is
refreshed as a PNG.
Requires ipywidgets and matplotlib (pip install "torchspin[gui]").
- class torchspin.fitgui.FitSession(data, model, p0, vary=None, lb=None, ub=None, options=None, names=None, progress_interval=0.5)[source]#
A fit that runs in a background thread and reports its progress.
Parameters mirror
esfit()(data, model, p0, vary/lb/ub, options);nameslabels the parameters.start()launches the fit (esfitin a daemon thread, so the kernel stays responsive),stop()asks it to finish at the next evaluation (the result is then the best fit so far,interrupted=True),resultholds theFitResultwhen done andhistorythe (evaluations, best RMSD, elapsed) trace.simulate(p)evaluates the model once, scaled to the data the way esfit does (least-squares amplitude and baseline).Bounds: with
lb/ub(or neither, which defaults to ±10 % ofp0) the bounds are absolute and are kept across restarts and slider moves; withvarythey arep0 ± varyaround the start of each run.start(vary=...)with zero entries fixes those parameters for that run only (the panel’s “fix” boxes), so a fixed parameter can be released again on the next run.varyis not clipped at anything physical here, because a plain parameter vector carries no information about what each entry means:varylarger thanp0gives a negative lower bound, which for a linewidth or a weight lets the optimizer explore unphysical values. Pass explicitlb/ubfor those parameters (lb=np.maximum(p0 - vary, floor)), or useesfit()’s dict style, where the field names are known and non-negative fields are clipped at zero as EasySpin does.
- class torchspin.fitgui.FitPanel(session, figsize=(7.0, 6.5), refresh_s=0.5, x=None, xlabel='B (mT)')[source]#
ipywidgets panel around a
FitSession.panel.show()displays the panel (or putpanel.widgetas the last expression of a cell — not both);panel.result/panel.p_currentgive the fit result and the slider values. Sliders can be moved while idle (the starting simulation is redrawn); the “fix” boxes exclude parameters from the next fit; “Sliders → start” adopts the slider values as the new starting point.