-
Notifications
You must be signed in to change notification settings - Fork 128
Correct error propagation on PolarizationEfficienciesWildes algorithm #39300
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
Correct error propagation on PolarizationEfficienciesWildes algorithm #39300
Conversation
c661b09
to
5a4dabb
Compare
…sing derived quantities
… to ensure consistent behaviour of wildes correction
89d0211
to
1482c70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm currently having a segfault when running the test code in windows, only difference wrt the code in the example is that I load the file from the data archive as i don't have it locally:
from mantid.simpleapi import *
Load(Filename='POLREF00032130', OutputWorkspace='POLREF00032130')
ConvertUnits(InputWorkspace='POLREF00032130', OutputWorkspace='POLREF00032130_y', Target='Wavelength', ConvertFromPointData=False)
Rebin(InputWorkspace='POLREF00032130_y', OutputWorkspace='POLREF00032130_y_rb', Params='0.01')
SumSpectra(InputWorkspace='POLREF00032130_y_rb', OutputWorkspace='POLREF00032130_y_rb_sum')
PolarizationEfficienciesWildes(InputNonMagWorkspace='POLREF00032130_y_rb_sum', OutputFpEfficiency='fp', OutputFaEfficiency='fa', IncludeDiagnosticOutputs=True)
Seems the segfault is happening when calling evaluate workspaces in the error propagation class.
I have added a few minor comments here and there.
...ork/Algorithms/inc/MantidAlgorithms/PolarizationCorrections/PolarizationCorrectionsHelpers.h
Show resolved
Hide resolved
...ork/Algorithms/inc/MantidAlgorithms/PolarizationCorrections/PolarizationCorrectionsHelpers.h
Show resolved
Hide resolved
} | ||
|
||
private: | ||
Func compute_func; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe camelCase is better here?
Func compute_func; | |
Func computeFunc; |
} | ||
}; | ||
|
||
template <size_t N, typename Func> auto make_error_propagation(Func &&func) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem previous camel case comment
const size_t specSize = outWs->blocksize(); | ||
|
||
// cppcheck-suppress unreadVariable | ||
const bool condition = Kernel::threadSafe((*args)..., *outWs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be renamed differently? isThreadSafe
perhaps?
} | ||
|
||
PolarizationEfficienciesWildes::FlipperWorkspaces PolarizationEfficienciesWildes::getFlipperWorkspaces(const bool mag) { | ||
if (mag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can mag
be renamed to something like isMagneticWs
or similar?
void PolarizationEfficienciesWildes::mapSpinStateWorkspaces() { | ||
const WorkspaceGroup_sptr magWsGrp = getProperty(PropNames::INPUT_MAG_WS); | ||
const WorkspaceGroup_sptr nonMagWsGrp = getProperty(PropNames::INPUT_NON_MAG_WS); | ||
if (magWsGrp != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal preference situation, you can leave it as it is if you would prefer to be more explicit.
if (magWsGrp != nullptr) { | |
if (magWsGrp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I remember spotting this but forgot to change!
Framework/Algorithms/test/PolarizationCorrections/PolarizationCorrectionsHelpersTest.h
Show resolved
Hide resolved
const double expectedTPMO = (2 * expectedPEfficiency) - 1; | ||
const double expectedAEfficiency = (EXPECTED_PHI / (2 * expectedTPMO)) + 0.5; | ||
const double expectedTAMO = (2 * expectedAEfficiency) - 1; | ||
const std::pair<double, double> expectedPEfficiency = {0.98, 0.9899494934}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another preference type situation, so feel free to leave as is, i think here compiler can infer the type without ambiguity, but as there are many const std::pair<double,double>
, perhaps it would make it a bit cleaner to use an alias?
const std::pair<double, double> expectedPEfficiency = {0.98, 0.9899494934}; | |
const std::pair expectedPEfficiency = {0.98, 0.9899494934}; |
const double expectedTPMO = (2 * expectedPEfficiency) - 1; | ||
const double expectedAEfficiency = 0.99; | ||
const double expectedTAMO = (2 * expectedAEfficiency) - 1; | ||
const std::pair<double, double> expectedPEfficiency = {0.98, 0.9899494934}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected value from the errors comes from the autodiff class? At least with the simplest error, we should add a test to compare with results taken from another method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I've taken these from the autodiff class. As I tested the errors calculated by the autodiff class against hand calculations in each of the following tests, I had confidence in these values: Framework/Algorithms/test/PolarizationCorrections/PolarizationCorrectionsHelpersTest.h
Given this, and the fact the signal remains the same as before, do you agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you ran the numbers with another method and everything agrees, then it is fine for me, perhaps we could mention it in a comment ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't run these numbers against another method, though I tested the errors calculated against hand calcs using the algorithm in general against other functions in the unit tests.
Thanks, will have to look in to this tomorrow. I seem to be able to reproduce a different seg fault, it's an access violation in a unexpected location, seemingly during
I replicated this using data stored locally. Mantid logs until fault:
EDIT: Also |
actually remove unintended change actually actually remove unintended change
54379fc
to
a62caec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All comments addressed. Code looks good to me.
Discussed offline: to avoid clogging CI, release note will be added as part of
Description of work
Summary of work
This PR corrects the error propagation for the
PolarizationEfficienciesWildes
algorithm.As part of this work a class
ErrorPropagation
has been added toPolarizationCorrectionsHelpers.h
. This generic class utilizes the eigenAutoDiff
module to automatically calculate the partials for different input variables. If there is wider interest in this class I will move it into thekernel
in a separate PR.The
PolarizationEfficienciesWildes
algorithm has been refactored slightly to enable use of theErrorPropagation
class and to remove the use of derived quantities in workspace arithmetic.The theory behind the approach to error propagation can be read: #37768
Fixes #37768
To test:
ErrorPropagation
class inPolarizationCorrectionsHelpersTest
. These include simple examplestestErrorPropagation_linear
,testErrorPropagation_quad
andtestErrorPropagation_mult_vars
that prove the function of the class. You can check these on paper/using wolfram alpha. The latter test I copied from this blog, obtaining the same results: https://michaelspieler.com/post/eigen-autodiff/PolarizationEfficienciesWildes
on some real (system test) data: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
Functional Tests
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.