Skip to content

bugfix for lsqml where we *always* use joint obj and probe step lengths even though the flag is set to false#66

Merged
mdw771 merged 2 commits intomainfrom
lsqml_bug_always_uses_joint_obj_prb_step
Mar 18, 2026
Merged

bugfix for lsqml where we *always* use joint obj and probe step lengths even though the flag is set to false#66
mdw771 merged 2 commits intomainfrom
lsqml_bug_always_uses_joint_obj_prb_step

Conversation

@a4894z
Copy link
Copy Markdown
Collaborator

@a4894z a4894z commented Mar 17, 2026

Just a quick bugfix in LSQML that causes the use of joint obj and probe step length calculation even if we set the flag to true telling it to use independent step length calculation

@a4894z a4894z requested a review from mdw771 March 17, 2026 18:43
@mdw771
Copy link
Copy Markdown
Collaborator

mdw771 commented Mar 18, 2026

Just a quick bugfix in LSQML that causes the use of joint obj and probe step length calculation even if we set the flag to true telling it to use independent step length calculation

The existing code isn't a bug, it's the intended behavior. As the name suggests, that option is only relevant when the object is multislice. If it is multislice and this option is True, it calculates the step sizes jointly. For single-slice object, it is supposed to always calculate object and probe sizes jointly. This is also consistent with the logic in PtychoShelves. Any particular reason you want to calculate object/probe steps independently for single-slice?

@a4894z
Copy link
Copy Markdown
Collaborator Author

a4894z commented Mar 18, 2026

Just a quick bugfix in LSQML that causes the use of joint obj and probe step length calculation even if we set the flag to true telling it to use independent step length calculation

The existing code isn't a bug, it's the intended behavior. As the name suggests, that option is only relevant when the object is multislice. If it is multislice and this option is True, it calculates the step sizes jointly. For single-slice object, it is supposed to always calculate object and probe sizes jointly. This is also consistent with the logic in PtychoShelves. Any particular reason you want to calculate object/probe steps independently for single-slice?

joint_step_ptychoshelves_vs_corrected

The math for joint step length calculation is incorrect; step lengths should always be real and positive here and the current code has a hack that zeros out any negative steps in the real part (red curve) and totally ignores the imag part (blue curve).

I have the corrected version implemented (black curve) but haven't tried to push it here yet, treating the faulty current version as the default (see attached image).

As a work around, I've just been doing non-joint probe and sample step calculations in a separate branch (the non-joint versions are mathematically correct), and it's working fine for me...the faulty current version for joint step calculation is occasionally unstable numerically for me but then again it could be that I'm using a object step scalar (from PtyChi options) of ~5.0 instead of the default 1.0.

Would it be better to change this pull request with the option to use non-joint steps for sample and probe on-demand, but leaving the faulty current version still the default?

@mdw771
Copy link
Copy Markdown
Collaborator

mdw771 commented Mar 18, 2026

Ok, fair enough. I split the option into single_slice_solve_obj_prb_step_size_jointly and multislice_solve_obj_prb_step_size_jointly. The single slice one defaults to True, multislice one defaults to False so that the default behavior is unchanged.

@mdw771 mdw771 merged commit 0f9d9af into main Mar 18, 2026
2 checks passed
@mdw771 mdw771 deleted the lsqml_bug_always_uses_joint_obj_prb_step branch March 18, 2026 19:07
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