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

Allow Determination of Workspace Order from Output of PolarizationCorrectionWildes #37643

Merged
merged 23 commits into from
Aug 22, 2024

Conversation

cailafinn
Copy link
Contributor

Description of work

Summary of work

Adds a new SpinStates property to the algorithm that allows the user to select the order that the spin state (++, -+, etc.) workspaces appear in the output WorkspaceGroup.

Fixes #35067

Further detail of work

  • Adds the new property to the algorithm, ensuring that they appear in the right order when it has been set.
  • Adds validation to ensure that the correct number of states is provided for a given correction.
  • Amends the SpinStateValidator to handle SpinStates (++) and FlipperConfigurations (00).
  • Updates the documentation to account for the new functionality

To test:

  1. Run the test from this documentation
  2. Take note of the order of the workspaces in the output WorkspaceGroup.
  3. Add a line under Flippers='00, 11' and add SpinStates=--,++,-+,+-`.
  4. Run the script again.
  5. Check the output workspace group is in the order you selected.

Reviewer

Please comment on the points listed below (full description).
Your comments will be used as part of the gatekeeper process, so please comment clearly on what you have checked during your review. If changes are made to the PR during the review process then your final comment will be the most important for gatekeepers. In this comment you should make it clear why any earlier review is still valid, or confirm that all requested changes have been addressed.

Code Review

  • Is the code of an acceptable quality?
  • Does the code conform to the coding standards?
  • Are the unit tests small and test the class in isolation?
  • If there is GUI work does it follow the GUI standards?
  • If there are changes in the release notes then do they describe the changes appropriately?
  • Do the release notes conform to the release notes guide?

Functional Tests

  • Do changes function as described? Add comments below that describe the tests performed?
  • Do the changes handle unexpected situations, e.g. bad input?
  • Has the relevant (user and developer) documentation been added/updated?

Does everything look good? Mark the review as Approve. A member of @mantidproject/gatekeepers will take care of it.

Gatekeeper

If you need to request changes to a PR then please add a comment and set the review status to "Request changes". This will stop the PR from showing up in the list for other gatekeepers.

@cailafinn cailafinn added Reflectometry Issues and pull requests related to reflectometry SANS Issues and pull requests related to SANS Framework Issues and pull requests related to components in the Framework ISIS Team: LSS Issue and pull requests managed by the LSS subteam at ISIS labels Jul 8, 2024
@cailafinn cailafinn added this to the Release 6.11 milestone Jul 8, 2024
@cailafinn cailafinn marked this pull request as ready for review July 29, 2024 14:39
@yusufjimoh yusufjimoh self-assigned this Aug 9, 2024
return c * static_cast<double>(wsIndex + 1);
},
[&](size_t wsIndex, double c) {
if (pols[wsIndex] == "_++")
Copy link
Contributor

Choose a reason for hiding this comment

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

The code is well-structured, with a clear structure and effective use of lambda functions, which greatly enhance readability. The overall implementation is commendable and aligns with good coding practices.

One minor consideration might be to refactor the repeated if-else blocks into a dedicated function, possibly leveraging an std::unordered_map. This adjustment could reduce redundancy, and make it easier to manage the polarization strings if they need to be modified in the future.

Just a small thought that might be worth exploring:

  size_t getPolIndex(const std::string &pol) {
    static const std::unordered_map<std::string, size_t> polMap = {
        {"_++", 0}, {"_+-", 1}, {"_-+", 2}, {"_--", 3}
    };
    
    auto it = polMap.find(pol);
    if (it != polMap.end()) {
        return it->second;
    } else {
        throw std::invalid_argument("Unknown polarization string: " + pol);
    }
} 

names.emplace_back(baseName + "_" + spinState);
API::AnalysisDataService::Instance().addOrReplace(names.back(), ws);
} else {
auto const &i = PolarizationCorrectionsHelpers::indexOfWorkspaceForSpinState(spinStateOrder, spinState);
Copy link
Contributor

Choose a reason for hiding this comment

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

I encountered a build issue on line 559 that seems to stem from a type mismatch in the call to indexOfWorkspaceForSpinState. The function is expecting a const std::vector<std::string>& as its first argument, but it appears that a std::string is being passed instead

@yusufjimoh
Copy link
Contributor

I've noticed both const auto and auto const being used in the code. Just wanted to understand if there's a difference between the two or if there's a particular reason for using them in those specific instances.

@cailafinn
Copy link
Contributor Author

cailafinn commented Aug 15, 2024

I've noticed both const auto and auto const being used in the code. Just wanted to understand if there's a difference between the two or if there's a particular reason for using them in those specific instances.

No, not functionally. This is the east const vs const west debate that has been going around in C++ circles for years. It's mostly stylistic in nature. I usually use east const by default as it's more consistent for what the const is referring to, but it's usually just best to keep to whatever convention is being used in the file you're editing.

I'll have a second look over the changes and make sure they're being consistent with the file.

@yusufjimoh
Copy link
Contributor

yusufjimoh commented Aug 15, 2024

That's interesting to know, Thanks for the explanation.

cailafinn and others added 14 commits August 16, 2024 08:46
There are a few different ways to represent the spin states of your
flipper configurations (usually in inputs) and spin states (usually in
outputs). Most notably between Wildes' method (+/-) and Fredrikze'
method (p/a). The change allows the spin state validator to be
initialised with any character to represent the on/off state of flippers
or the parallel/antiparallel state of outputs.

RE mantidproject#35067
The way that the index finder helper works was changed in another PR.
This accounts for that by handling the optional.

The optional currently throws an error if it does not return an index,
this is not testable as the validation currently prevents providing the
spin states in such a way that this would be reached. But is implemented to
result in a helpful error rather than a segfault should code changes
result in problematic spin state strings getting through.

RE mantidproject#35067
@cailafinn cailafinn force-pushed the 35067_wildes_flipper_config branch from 338435d to 7de1a34 Compare August 16, 2024 11:23
@cailafinn cailafinn requested a review from yusufjimoh August 19, 2024 08:25
@yusufjimoh
Copy link
Contributor

yusufjimoh commented Aug 19, 2024

The build issues have been resolved. I tested the code with and without the new spin states configuration, and it functions well in both scenarios for the PolarizationCorrectionWildes and PolarizationEfficiencyCor algorithms, respectively. The output workspace group was returned in the correct order. The tests added for the new spin states functionality are thorough.

  • Code is well-written
  • Functions correctly
  • Tests for the spin states are comprehensive
  • Documentation is updated

Everything appears to be in order.

Copy link
Contributor

@yusufjimoh yusufjimoh left a comment

Choose a reason for hiding this comment

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

I happened to notice that lines 559 and 132 might still be using auto const. not certain if that's intentional

@cailafinn cailafinn force-pushed the 35067_wildes_flipper_config branch from 7de1a34 to 7557939 Compare August 19, 2024 16:46
@cailafinn
Copy link
Contributor Author

I happened to notice that lines 559 and 132 might still be using auto const. not certain if that's intentional

Good catch on 559. 132 matches the rest of the file.

@yusufjimoh
Copy link
Contributor

Thanks for clarifying

@sf1919
Copy link
Contributor

sf1919 commented Aug 20, 2024

Tests have now passed so reviewing can continue on this one.

@cailafinn cailafinn requested a review from yusufjimoh August 20, 2024 12:18
yusufjimoh
yusufjimoh previously approved these changes Aug 20, 2024
@yusufjimoh
Copy link
Contributor

All checks have been completed, and all tests are passing. Pull request approved

@rbauststfc rbauststfc self-assigned this Aug 20, 2024
Copy link
Contributor

@rbauststfc rbauststfc left a comment

Choose a reason for hiding this comment

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

Changes look really good and thanks very much for putting in the effort to make the spin state validator more generic, that will be extremely helpful for future work!

I noticed one or two minor things that I thought might be worth mentioning, although not all necessarily need changing if they were deliberate choices so feel free to go with your preference on those.

I can't seem to see any release notes on this PR, though, so it would be good to add some before merging this in.

Copy link
Contributor

@rbauststfc rbauststfc left a comment

Choose a reason for hiding this comment

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

Sorry, I realise as this is at gatekeeper stage I'd better set to request changes to prevent merging before we have a release note.

@github-actions github-actions bot added the Has Conflicts Used by the bot to label pull requests that have conflicts label Aug 21, 2024
Copy link

👋 Hi, @cailafinn,

Conflicts have been detected against the base branch. Please rebase your branch against the base branch.

@rbauststfc rbauststfc removed the Has Conflicts Used by the bot to label pull requests that have conflicts label Aug 22, 2024
The flipper configuration constants have been moved from the
SpinValidator to the PolarizationCorrectionsHelpers file,
so new algorithm PolarizationEfficienciesWildes needs to be updated to use these.
@rbauststfc rbauststfc dismissed their stale review August 22, 2024 10:33

Changes have been made since the original review

@rbauststfc
Copy link
Contributor

@cailafinn, the changes on this are looking really good, I've tested the changes to the validation and that's all working well. Thanks for adding a release note too. I'm afraid this PR of mine that was merged in yesterday caused some conflicting changes and I thought it seemed a bit unfair for you to have to sort those out when you got back, so I've resolved them, I hope that's OK.

@yusufjimoh, would you be happy to do a quick re-review (i.e. look through the code to confirm you're happy with the changes since your last review, but no need to re-do manual testing at this stage)? If you're happy then you can approve the PR as normal and I will gatekeeper it.

yusuphjoluwasen
yusuphjoluwasen approved these changes Aug 22, 2024
@rbauststfc rbauststfc merged commit e7c101c into mantidproject:main Aug 22, 2024
10 checks passed
@cailafinn cailafinn deleted the 35067_wildes_flipper_config branch August 28, 2024 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues and pull requests related to components in the Framework ISIS Team: LSS Issue and pull requests managed by the LSS subteam at ISIS Reflectometry Issues and pull requests related to reflectometry SANS Issues and pull requests related to SANS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow bespoke flipper configurations and output spin state in PolarizationCorrectionWildes
5 participants