Fix: Dim 1 not calculating properly#3057
Conversation
Fixed an issue with sum, product, ... where an argument of dim=1 would break and show the wrong answer repeating the first calculations.
|
Hi @heidthecamp -- This change looks good to me. (The outer loop now has the same general structure as the inner loops.). It is unlikely that customers have decades of archived trees that now rely on the original wrong behavior. Thus, the risk of this fix breaking existing archives is likely very low. Nonetheless, a major benefit of MDSplus is that trees written decades ago can still be read today. Which means that TDI changes must be scrutinized. So, I will ponder the matter on Monday before submitting an official review / approval. |
|
Hi @heidthecamp -- This fix is definitely correct. However, because it affects 8 TDI functions, I am doing some additional spot-checks of the 8 functions using some trees from the C-Mod archive. (It is highly unlikely that anything will go awry with this fix, but it is prudent to confirm all is well.) |
|
Hi @heidthecamp -- The loops in the The original table (contains tabs, which should probably be replaced with spaces). Unfortunately, GitHub doesn't preserve the column alignment in the above table. Looking at the "outer" row and expressing it as a Python dictionary: |
|
Hi @heidthecamp -- As you mentioned during today's software team meeting, this problem is not limited to two-dimensional arrays with the specified DIM=1. If a multi-dimensional array contains N dimensions, then the user can choose to slice the array along any of those dimensions. Meaning that the |
|
Tested the fix by creating these three arrays. Then applied the 8 functions:
Output for Output for The other functions also worked correctly. A minor surprise is that |
|
To evaluate the potential impact of this change on historical trees, scanned the entire tree for C-Mod shot 1160930043 for node expressions that used any of the 8 functions, and then evaluated some of those nodes using two versions of MDSplus: unfixed and fixed. The results were the same (because the C-Mod expressions didn't specify a dimension argument). Of course, there was one exception to the rule. Namely, the following node did specify a dimension. However, the referenced nodes didn't contain any data, so it is a moot issue for this shot. Nonetheless, there is a chance that it might affect other trees, such as the HXR data generated at DIII-D. This is the list of nodes spot-checked for each function: |
mwinkel-dev
left a comment
There was a problem hiding this comment.
This PR has also been tested by @heidthecamp and @WhoBrokeTheBuild. They too evaluated the potential impact of the PR on historical trees. They said that they did not find any problems.
Their results, plus the testing described in the previous two posts, indicates that this PR is very low risk to historical trees. Meaning that it is unlikely that any researchers at C-Mod were relying on the incorrect results of the 8 functions. It is thus probable that other research institutions also did not use the 8 functions with a dimension argument, thus did not rely on the incorrect results.
Because the new fix works well, and has no obvious impact on the historical C-Mod trees, this PR is now approved.
Fixed an issue that was noticed with sum and product, where an argument of dim=1 would break and show the wrong answer repeating the first calculations. It, however, affected several other opcodes.
List all affected opcodes:
MAXLOCMINLOCMAXVALMINVALMEANPRODUCTSUMACCUMULATEWhen doing
sumorproductin tdi with multidimensional arrays using the argument dim = 1 would result in an error, doubling the inner array twice.simply:
[[3], [3]]summing 1 and 2 twice, when it should produce the sum of 1 and 2 then 3 and 4.
[[3], [7]]this would even happen with
A more robust example:
[[15,18,21,24], [15,18,21,24]]After applying the fix it is no longer doubling first inner array.
[[15,18,21,24], [51,54,57,60]]This was easiest to reproduce with a dim of one but if you could contrive of an example where a higher dimension would need to be duplicated you would be able to get those values to repeat as well.
[[[3], [5]], [[3], [5]], [[3], [5]]][[[3], [5]], [[7], [9]], [[11], [13]]]The issue stems from the outer most for loop having a ';' in the wrong location causing the set up for several values to be reset every time the loop was evaluated.