Skip to content

Conversation

MohamedAlmaki
Copy link
Contributor

@MohamedAlmaki MohamedAlmaki commented Sep 22, 2025

Description of work

This PR introduces batch processing of focused files for Pawly refinement in the GSASII GUI. The interface now supports handling multiple files at once, producing three output files per input, similar to single-file processing. Currently, the plot results are only available for the last refinement, but ideally, they should be generated for all files. This feature will be implemented in the future.

Closes #39606

To test:

Follow GSASII test instructions but using multiple focused files (i.e. 305793-305795): https://developer.mantidproject.org/Testing/EngineeringDiffraction/EngineeringDiffractionTestGuide.html


Reviewer

Your comments will be used as part of the gatekeeper process. Comment clearly on what you have checked and tested during your review. Provide an audit trail for any changes requested.

As per the review guidelines:

  • Is the code of an acceptable quality? (Code standards/GUI standards)
  • Has a thorough functional test been performed? Do the changes handle unexpected input/situations?
  • Are appropriately scoped unit and/or system tests provided?
  • Do the release notes conform to the guidelines and describe the changes appropriately?
  • Has the relevant (user and developer) documentation been added/updated?

Gatekeeper

As per the gatekeeping guidelines:

  • Has a thorough first line review been conducted, including functional testing?
  • At a high-level, is the code quality sufficient?
  • Are the base, milestone and labels correct?

@MohamedAlmaki MohamedAlmaki force-pushed the 39606-enable-pawly-batch branch from 43b9c36 to a009fc8 Compare September 22, 2025 14:33
@MohamedAlmaki MohamedAlmaki added Diffraction Issues and pull requests related to diffraction ISIS: Diffraction Issue and pull requests relating to Diffraction at ISIS labels Sep 22, 2025
@MohamedAlmaki MohamedAlmaki added this to the Release 6.14 milestone Sep 22, 2025
@MohamedAlmaki MohamedAlmaki force-pushed the 39606-enable-pawly-batch branch from a009fc8 to 336f8f3 Compare September 23, 2025 09:37
@MohamedAlmaki MohamedAlmaki marked this pull request as ready for review September 23, 2025 10:54
Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC left a comment

Choose a reason for hiding this comment

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

Thanks for this - I was able to batch process a sequence of runs in GSASII tab (for single and multiple spectra grouping).

Aside from some small comments below there are a few more things required:

  1. If you run a refinement with an all_banks.prm and two .gss files with one spectrum each (i.e. bank_1 and bank_2) you get this error
GSAS-II call failed with error: Traceback (most recent call last):
  File "C:\Users\xhg73778\AppData\Local\gsas2full\GSAS-II\GSASII\GSASIIscriptable.py", line 522, in load_pwd_from_reader
    Iparm1, Iparm2 = instprm
    ^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\mantid-conda\mantid\qt\python\mantidqtinterfaces\mantidqtinterfaces\Engineering\gui\engineering_diffraction\tabs\gsas2\call_G2sc.py", line 273, in <module>
    main()
  File "C:\mantid-conda\mantid\qt\python\mantidqtinterfaces\mantidqtinterfaces\Engineering\gui\engineering_diffraction\tabs\gsas2\call_G2sc.py", line 244, in main
    add_histograms(data_files, gsas_project, instrument_files, number_of_regions)
  File "C:\mantid-conda\mantid\qt\python\mantidqtinterfaces\mantidqtinterfaces\Engineering\gui\engineering_diffraction\tabs\gsas2\call_G2sc.py", line 45, in add_histograms
    project.add_powder_histogram(
  File "C:\Users\xhg73778\AppData\Local\gsas2full\GSAS-II\GSASII\GSASIIscriptable.py", line 980, in add_powder_histogram
    histname, new_names, pwdrdata = load_pwd_from_reader(r, iparams,
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xhg73778\AppData\Local\gsas2full\GSAS-II\GSASII\GSASIIscriptable.py", line 524, in load_pwd_from_reader
    Iparm1, Iparm2 = load_iprms(instprm, reader, bank=bank)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xhg73778\AppData\Local\gsas2full\GSAS-II\GSASII\GSASIIscriptable.py", line 504, in load_iprms
    raise G2ImportException("Instrument parameter file has {} banks, select one with instbank param."
GSASIIscriptable.G2ImportException: Instrument parameter file has 2 banks, select one with instbank param.

This was previously possible but won't be after this change - that's as expected but the error needs to be caught. I think the relevant code is here

def understand_data_structure(self) -> None:
self.x_limits.data_x_min = []
self.x_limits.data_x_max = []
number_of_regions = 0
for input_file in self.file_paths.data_files:
loop_focused_workspace = LoadGSS(Filename=input_file, OutputWorkspace="GSASII_input_data", EnableLogging=False)
for workspace_index in range(loop_focused_workspace.getNumberHistograms()):

  1. I think the unit tests in test_gsas2_model.py need to be updated to cover this new functionality.

  2. I think the manual testing insturctions need to be updated (or another test added)

  3. I think this section of the GUI docs need updating

I'm happy for 3-4 to be done as maintenance!

Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC left a comment

Choose a reason for hiding this comment

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

Thanks for this - nice idea to try call GSAS only once but not sure this is working as expected.

  1. The logic checking the .rpm and .gss files correctly errors for a for all_banks.prm files with single spectra .gss files, but it also errors for e.g. bank_1.prm and multiple bank_1.gss and bank_1.prm and a single all_banks.gss
    The latter error is not handled
GSAS-II call failed with error: Traceback (most recent call last):
  File "C:\Users\xhg73778\AppData\Local\gsas2full\GSAS-II\GSASII\GSASIIscriptable.py", line 522, in load_pwd_from_reader
    Iparm1, Iparm2 = instprm
    ^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\mantid-conda\mantid\qt\python\mantidqtinterfaces\mantidqtinterfaces\Engineering\gui\engineering_diffraction\tabs\gsas2\call_G2sc.py", line 267, in <module>
    main()
  File "C:\mantid-conda\mantid\qt\python\mantidqtinterfaces\mantidqtinterfaces\Engineering\gui\engineering_diffraction\tabs\gsas2\call_G2sc.py", line 238, in main
    add_histograms(data_files, gsas_project, instrument_files, number_of_regions, banks_per_file)
  File "C:\mantid-conda\mantid\qt\python\mantidqtinterfaces\mantidqtinterfaces\Engineering\gui\engineering_diffraction\tabs\gsas2\call_G2sc.py", line 46, in add_histograms
    project.add_powder_histogram(
  File "C:\Users\xhg73778\AppData\Local\gsas2full\GSAS-II\GSASII\GSASIIscriptable.py", line 980, in add_powder_histogram
    histname, new_names, pwdrdata = load_pwd_from_reader(r, iparams,
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xhg73778\AppData\Local\gsas2full\GSAS-II\GSASII\GSASIIscriptable.py", line 524, in load_pwd_from_reader
    Iparm1, Iparm2 = load_iprms(instprm, reader, bank=bank)
    ^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 0)
  1. It looks to me like it's only refining one set of lattice parameters over multiple runs/spectra (though it is refining instrument parameters for each spectra)
image

@MohamedAlmaki MohamedAlmaki force-pushed the 39606-enable-pawly-batch branch from 892c3f8 to ffc7320 Compare September 25, 2025 14:09
@thomashampson thomashampson changed the base branch from main to release-next September 25, 2025 15:00
Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC left a comment

Choose a reason for hiding this comment

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

Works great thanks so much - just a question about the tests but otherwise happy to approve!

Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC left a comment

Choose a reason for hiding this comment

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

Thanks - I'm approving this PR as working wonderfully!
Additional unit tests will be added as a maintenance issue #40007

@thomashampson thomashampson self-assigned this Sep 25, 2025
@thomashampson thomashampson enabled auto-merge (squash) September 25, 2025 16:32
@thomashampson thomashampson merged commit 3575ad5 into release-next Sep 25, 2025
11 checks passed
@thomashampson thomashampson deleted the 39606-enable-pawly-batch branch September 25, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Diffraction Issues and pull requests related to diffraction ISIS: Diffraction Issue and pull requests relating to Diffraction at ISIS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support batch Pawley refinements in Engineering UI GSAS tab
3 participants