Added an additional text box to input the model description for ORSO file formats#41025
Added an additional text box to input the model description for ORSO file formats#41025RabiyaF wants to merge 10 commits intomantidproject:mainfrom
Conversation
9d54d65 to
e09f6a0
Compare
jhaigh0
left a comment
There was a problem hiding this comment.
This works as described and the code is sensible and tested 👍
My only question is, does the model string need to be validated at all? At the moment it will just write what ever string you enter to the file, if you enter an invalid model or maybe a string with : in it (or any other special character for the ORSO format) would it stop the saved file from being read back in? (to Mantid or any other program reading ORSO files)
If there is a strict format for this model string then I think it should be checked, but I'm not familiar with the ORSO format
The rules governing the simple single line model as implemented here are detailed: As you can see, there is scope for increased complexity over multiple lines but this requirement has not yet been expressed by our users. Validation would be great; but we should avoid implementing ourselves. The Tests for this validation would also be good. |
ade5a90 to
3bf0bf3
Compare
|
I spoke with Stephen (The RasCAL team lead) and he said that they use the method |
4a5496b to
2fb7040
Compare
jhaigh0
left a comment
There was a problem hiding this comment.
Thanks for adding the validation. I think given the warning we've been given we need to be more careful about the validation method.
If, in the case where the database fails to connect, that method raises an exception, then we can simply catch it as I described in my comment.
If, when it fails, the method just hangs, then I think we need to guard against this.
Here is some copilot code showing how to use concurrent.futures to run something for a maximum of n seconds before quitting and continuing.
import concurrent.futures
from typing import Callable, Any
def run_with_timeout(func: Callable, timeout: float, *args, **kwargs) -> Any:
"""
Run `func` with the given timeout.
If `func` does not return within `timeout`, return None
and print a warning.
"""
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
future = executor.submit(func, *args, **kwargs)
try:
return future.result(timeout=timeout)
except concurrent.futures.TimeoutError:
print(f"⚠️ Function '{func.__name__}' timed out after {timeout} seconds")
return None
| try: | ||
| SampleModel(stack=model).resolve_to_layers() | ||
| except: | ||
| raise ValueError( | ||
| f"The provided model description {model} contains an error. " | ||
| "Please check that the string follows the correct ORSO format.\n" | ||
| ) |
There was a problem hiding this comment.
Since you mentioned this method can fail if it fails to connect to the database, if in that case it throws an exception, it will be caught here and prevent the save. That might be annoying if someone's computer is failing to connect.
I think you should catch the specific exception raised for a connection failure (hopefully that is documented somewhere) and in that case just log a warning saying that the validation wasn't available.
I also think it would be neater if you could just print an error message to the log (and then exit early) rather than raise an exception which fills the log with a trace back. Maybe whoever calls this method could catch a ValueError?
Description of work
Closes #40954.
Adds an additional textbox in the Save tab of the
ISIS ReflectometryInterface so that the user can provide a custom model description.To test:
ISIS Reflectometryinterface and navigate to theSavetab.air | Ni 100 | SiO2 0.5 | Siinto the model description textbox.air | Ni 100 | SiO2 0.5 | Sifrom the textbox and click Save.air | Ni 100 | SiO2 0.5 | 02orair | 25 [Si 7 | Fe 7 ] | Siand click Save.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:
mantid-developersormantid-contributorsteams, add a review commentrerun cito authorize/rerun the CIGatekeeper
As per the gatekeeping guidelines: