Repository navigation
ENH: Check the C-Axis Reference Misalignments inputs only in preflight - #1975
joeykleingers wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
IFilter::execute() always runs preflight before executeImpl(), so the input checks that ComputeCAxisReferenceMisalignments::operator()() repeated through the static ValidateInputs() only checked the same inputs a second time on every run. This change applies the knowledge-base rule "Run a filter, not its algorithm" to this filter. * The input checks move into the filter. Preflight keeps only the checks that the parameters cannot make: the reference direction is finite and not near zero, each selected array is a DataArray of the required type (ArraySelectionParameter does not stop a StringArray), Phases and the enabled mask have one tuple per quaternion, and the output path is not an input path. * The algorithm no longer checks its inputs or the output array that preflight creates. It keeps the phase range check (-98712) and the non-hexagonal warning (-98713). Its @pre lines give its preconditions. * Error codes -98714, -98716, -98718, -98720 and -98722 to -98725 are removed, because no path through the filter can return them. The remaining preflight codes move to the filter class. * The tests that called the algorithm directly are removed. The StringArray preflight test now reaches the type checks of all four selected arrays (-98715, -98717, -98719, -98721) through the filter. Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
d45c7ec to
ea9b052
Compare
imikejackson
left a comment
There was a problem hiding this comment.
Review of PR #1975 at ea9b052
Verdict: REQUEST CHANGES. One Critical finding (2.1): some preflight code repeats checks that ArraySelectionParameter already makes. Everything else is Minor or Nit.
The PR does what #1966 asks. Each claim in the description holds against the code:
VectorParameterrejects a wrong-size vector, so -98714 could never be returned.- The
AllowedComponentShapesof each selection reject a wrong shape, so -98716, -98718, -98720 and -98722 could never be returned. - The preflight
CreateArrayActionfixes the output type, shape and tuple count, so -98723, -98724 and -98725 could never be returned.
Validation: I built OrientationAnalysisUnitTest in an in-core Release DREAM3D-NX build on macOS arm64 with no warnings. All 19 ComputeCAxisReferenceMisalignments tests pass with ctest -j 1. clang-format 19.1.1 is clean on all 5 files. I did not run clang-tidy or an out-of-core build.
1. Solves the issue with good design
- 1.1 The algorithm no longer repeats any input check. It keeps only the checks that need array values: the phase index (-98712) and the non-hexagonal warning (-98713). The
@prelines document the preconditions. - 1.2 The tuple-count check between sibling arrays in preflight has not changed, so this PR adds no new rejection of placeholder counts.
- 1.3 [Nit]
ComputeCAxisReferenceMisalignments.hpp:74: the@pretext hard-codes1.0e-12. Name the constant instead:ComputeCAxisReferenceMisalignmentsFilter::k_MinReferenceDirectionNorm.
2. Error handling and defensive programming
-
2.1 [Critical]
ComputeCAxisReferenceMisalignmentsFilter.cpp: the preflight helpers repeat checks thatArraySelectionParameter::validatePathalready makes beforepreflightImpl()runs:MakeArrayTypeError(line 71) has a "path does not exist" branch. The parameter already rejects a missing path (k_Validate_Does_Not_Exist).DescribeObjectType(line 50) has anIDataArraybranch. It and the mask conditiongetDataType() != DataType::boolean && != DataType::uint8(line 181) check the element type of a DataArray. The parameter'sAllowedTypesalready rejects a DataArray of the wrong type (k_Validate_AllowedType_Error).
No path through the filter can reach these branches. The tests that covered their messages were deleted in this PR. Removing this kind of repeated check is the point of #1966.
Fix: keep a single check that does not throw, and that fails only for a selected
IArraythat is not anIDataArray. Message: " path '' has type '<getTypeName()>', but a DataArray of type is required." Then:- remove the null branch and the
IDataArraybranch ofDescribeObjectType; - reduce the mask check to
getDataAs<IDataArray>(maskPath) == nullptr; - remove the
TypesUtility.hppinclude if it is no longer used.
-
2.2 [Minor] A
NeighborListreaches the same checks:INeighborListderives fromIArray, not fromIDataArray. The comment at line 82, the PR description and the test atComputeCAxisReferenceMisalignmentsTest.cpp:712name onlyStringArray. Fix: add aNeighborList<float32>row to that test, or change the wording to "an array that is not a DataArray (StringArray, NeighborList)". -
2.3 [Nit] The type checks that remain (-98715, -98717, -98719, -98721) are temporary guards. They exist because
ArraySelectionParameterdoes not yet enforce the array kind. That parameter fix is tracked in #1833, which follows #1821; the summary issue #1869 also points to it. #1869 asks that each such local guard link #1833 in a code comment, so it can be removed when the parameter takes over. Fix: add a comment such as// Temporary guard until #1833 makes ArraySelectionParameter enforce the array kind.aboveValidateArrayTypeand in the doc comment ofValidateInputs. -
2.4 [Minor] The merge order matters with #1991, which moves NaN and infinity rejection into
VectorParameter. After #1991 merges:- the
isfinitepart of -98710 can no longer be reached. Under the same rule as 2.1, it then repeats a parameter check; - the NaN and infinity rows of the
invalid referencetest (...Test.cpp:608) will get a parameter error code instead.
Whichever of the two PRs merges second removes the
isfinitepart, keeps the length check, and updates that test. - the
-
2.5 [Nit] The filter's error codes are now declared in two classes: -98712 and -98713 in the algorithm, the rest in the filter. That split is correct. Add a one-line comment in each header that points to the other.
3. Work beyond the issue
- 3.1 Nothing goes beyond the issue. Moving the codes and
k_MinReferenceDirectionNorminto the filter follows directly from the rule.
4. Documentation and tests
- 4.1
ComputeCAxisReferenceMisalignmentsFilter.mdlists no error codes. Its description of the behavior is still accurate, so it needs no change. - 4.2 Deleting the direct-algorithm test loses no coverage of code the filter can reach. These are all still exercised through the filter:
- uint8 and bool masks;
- valid inputs (the oracle tests);
- phase out of range (-1, 5 and INT32_MAX);
- Phases and Mask tuple-count mismatch;
- all 7 preflight codes, each asserted.
- 4.3 [Nit] The test plan says the out-of-core run used
DREAM3DNX_ENABLE_OOC=ON. #1995 and DREAM3DNX#1255 rename that option toDREAM3D_ENABLE_OOC. Consider writing "DREAM3D-NX out-of-core build" so the description stays correct after the rename. This does not affect the C-Axis tests, whichOrientationAnalysisOocStoreContractsdoes not include.
Summary
The Compute C-Axis Reference Misalignments filter now checks each input one time, in preflight. This applies the knowledge-base rule "Run a filter, not its algorithm" (PR #1959) to the only filter that still followed the previous rule.
IFilter::execute()always runs preflight beforeexecuteImpl(). Thus the input checks that the algorithm repeated through its staticComputeCAxisReferenceMisalignments::ValidateInputs()checked the same inputs a second time on every run. 5 files changed, +213 / −470 lines.1. Input checks in the filter
src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/ComputeCAxisReferenceMisalignmentsFilter.cpp: the preflight input checks.src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/ComputeCAxisReferenceMisalignmentsFilter.hpp: the preflight error codes andk_MinReferenceDirectionNorm.preflightImpl()keeps only the checks that the parameters cannot make:ArraySelectionParameterapplies its type list only to anIDataArray, so aStringArrayselection gets topreflightImpl().These codes now belong to
ComputeCAxisReferenceMisalignmentsFilter. Their values do not change.2. The algorithm relies on preflight
src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/ComputeCAxisReferenceMisalignments.{hpp,cpp}The algorithm no longer checks its inputs or the output array that the preflight
CreateArrayActioncreates. Its@prelines give the preconditions. It keeps the checks that preflight cannot make: a phase value that is not an index into Crystal Structures (-98712), the non-hexagonal warning (-98713), and the result of each read and write.3. Removed error codes
No path through the filter can return these codes, so they are removed:
VectorParameterrejects this before preflight.AllowedComponentShapesof eachArraySelectionParameterreject this before preflight.CreateArrayActioncreates the output asfloat32with component shape {1} and the quaternion tuple shape.The filter was added after the DREAM3D-NX 7.4.2 release, so no released error code changes. The filter documentation lists no error codes and does not change.
4. Tests
src/Plugins/OrientationAnalysis/test/ComputeCAxisReferenceMisalignmentsTest.cppThe tests that called the algorithm directly are removed. Each input check is reached through the filter. The
StringArraypreflight test now selects aStringArrayfor each of the four arrays and asserts the type error code of that array.Test plan
ComputeCAxisReferenceMisalignmentstests pass in an in-core Release build (SIMPLNX_TEST_ALGORITHM_PATH=0) on macOS arm64.ComputeCAxisReferenceMisalignmentstests pass in an out-of-core Release build (DREAM3DNX_ENABLE_OOC=ON,SIMPLNX_TEST_ALGORITHM_PATH=1) on macOS arm64.Related Issue
Closes #1966