Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create log file vesuvio #153

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

GuiMacielPereira
Copy link
Collaborator

@GuiMacielPereira GuiMacielPereira commented Jan 7, 2025

Description of work:

  • Set Mantid.properties file with logging properties when mvesuvio config is run
  • Summarised log file is produced automatically for every script run - includes only important information
  • Improved output to log by including a function that prints TableWorkspaces in a pretty format

IMPORTANT NOTE: Because Windows has a file lock that prevents a file from being written to when its open by another process, it's not as simple as doing open() in line https://github.com/mantidproject/vesuvio/pull/153/files#diff-04c5f47f75adcdbf7d20a33e3fc04fe2a2d231e11f9a843feb830375222c19c4R89, so I talked we Anna and we decided to go ahead with this PR and fix the functunality on Windows later.

To test:

Code review
+
Due to the differences in behaviour depending on the OS, manual testing should be done on IDAaaS and on Windows:

IDAaaS:
Create and sctivate a test environment with mantidworkbench installed:

  • Checkout this branch and install with pip install -e .
  • Run mvesuvio config
  • Open Mantid workbench and open file ~/.mvesuvio/analysis_inputs.py
  • In the class BackwardAnalysisInputs change the field run_this_scattering_type = True
  • In the class FowardAnalysisInputs change the field number_of_iterations_for_corrections = 1
  • Click Run and wait for it to finish (might take a minute or two)
  • Go back to the terminal and check that a file mantid.log file was created in the working directory.
  • Open this file and check that this is the same log you see in the workbench log console
  • Go to file ~/.mvesuvio/analysis_inputs/bckwd_fwd_gauss.log and check that this is the same log but only containing the relevant information (fit of each spectra and tables)
  • Go to mantid workbench and Click Run again to run the same routine
  • You should notice that ~/.mvesuvio/analysis_inputs/bckwd_fwd_gauss.log contains only the last routine that was run (look at the times of the output lines to check this)

Windows:
Create and activate a test environment with mantidworkbench installed:

  • Repeat the same steps as before
  • You should notice that when you re-run the routine, ~/.mvesuvio/analysis_inputs/bckwd_fwd_gauss.log contains the logs of both routines, and the file is not reset to include only the very last routine that was run.

Fixes #145 .

@GuiMacielPereira GuiMacielPereira force-pushed the create-log-file-vesuvio branch from eccffe0 to f04ec1d Compare January 7, 2025 14:46
Logging settings are added during config command.
Current downside is that if logging settings are set to
mantid properties when mantid is open, mantid needs to be
closed and opened again for changes to take place.
Added function that takes in existing mantid log file and
produces a clean version with only the important information.
Replaced print statements in fitting with logger.notice().
Added these statements to log file.
Changed the name of the log file to account for the fact that one
of the routines is joint, so hte name cannot depend on the spectra being
fitted (well it could, but that would be unecessary and more complex).

I also noticed that no information about the initial parameters was being
outputed so I created a new function for printing tables and used that to
show the tables for the initial parameters.
Convert to integers where possible so that priting of zeros is avoided.
Changed names of columns of fit parameters because they were taking too
much space when the table got print, which made it very difficult to read.
Now table occupies much less space and is much clearer to read.
Previous notices were not very clear and made the code more
confusing, replaced them with printing tables that are already
bring created anyway.
Log output is much easier to follow this way
@GuiMacielPereira GuiMacielPereira force-pushed the create-log-file-vesuvio branch from f04ec1d to 73bc753 Compare January 7, 2025 14:54
@GuiMacielPereira GuiMacielPereira linked an issue Jan 7, 2025 that may be closed by this pull request
7 tasks
@GuiMacielPereira GuiMacielPereira marked this pull request as ready for review January 8, 2025 16:12
@GuiMacielPereira GuiMacielPereira self-assigned this Jan 8, 2025
@SilkeSchomann SilkeSchomann self-assigned this Jan 9, 2025
@SilkeSchomann
Copy link
Collaborator

I am getting a permission error when I click on Run:

PermissionError: [Errno 13] Permission denied: 'mantid.log'
  File "C:/Users/eoc57742/.mvesuvio/analysis_inputs.py", line 118, in <module>
    mvesuvio.run()
  File "C:\Users\eoc57742\vesuvio2024\vesuvio\src\mvesuvio\__init__.py", line 53, in run
    main(run_args)
  File "C:\Users\eoc57742\vesuvio2024\vesuvio\src\mvesuvio\main\__init__.py", line 16, in main
    __run_analysis()
  File "C:\Users\eoc57742\vesuvio2024\vesuvio\src\mvesuvio\main\__init__.py", line 105, in __run_analysis
    Runner().run()
  File "C:\Users\eoc57742\vesuvio2024\vesuvio\src\mvesuvio\main\run_routine.py", line 86, in run
    with open(self.mantid_log_file, 'w') as file:

The log file cannot be cleaned when on Windows, because due
to file locks, cannot open file when it is being used by Mantid
to write to it.

The best solution for now is to clean the file when on Unix system.
On windows the log file will still be produced, but will contain the logs
of all times the routines were run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve user experience
2 participants