4
$\begingroup$

This is the strangest bug I've encountered. In my experience, variations in the code will unexpectedly crash the kernel, give inconsistent output, or produce expected results with no problems.

1) Code-Quits-Kernel Version

Warning: this will crash your kernel.

To reproduce this bug, follow the steps below.

  1. Copy the following code as is into a notebook. (It is all one cell.)
ClearAll[compbbbeven]

compbbbeven = 
  Compile[{{filled, _Integer, 2}, {prohibited, _Integer, 
     2}, {col, _Integer}}, 
   Union[
    Join[prohibited, 
     Flatten[
      MapIndexed[
       Function[{r, c}, Join[{{1, 1}, {2, 2}}]][First[#2], #1] &, 
       filled[[All, 1]]], 1]]], RuntimeAttributes -> {Listable}, 
   Parallelization -> True];

filled = {{1, 0}, {5, 0}};
prohibited = {{4, 4}, {5, 2}, {3, 3}, {6, 3}};
col = {1, 2};

Array[compbbbeven[filled, prohibited, col] &, 50] // Column
  1. Quite your kernel.
  2. Start your kernel.
  3. Run the code from step 1.

2) No problems Version

This is the same code as in version 1 above except the 50 is changed to a 1 in the call to Array. Notice there is no kernel crash and output is produced with no error.

ClearAll[compbbbeven]

compbbbeven = 
  Compile[{{filled, _Integer, 2}, {prohibited, _Integer, 
     2}, {col, _Integer}}, 
   Union[
    Union[prohibited, 
     Flatten[
      MapIndexed[
       Function[{r, c}, Join[{{1, 1}, {2, 2}}]][First[#2], #1] &, 
       filled[[All, 1]]], 1]]], RuntimeAttributes -> {Listable}, 
   Parallelization -> True];

filled = {{1, 0}, {5, 0}};
prohibited = {{4, 4}, {5, 2}, {3, 3}, {6, 3}};
col = {1, 2};

Array[compbbbeven[filled, prohibited, col] &, 1] // Column

(*output is {{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 2}, {6, 3}}, {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 2}, {6, 3}}}*)

3) Inconsistent Output Version

Running the following code produces inconsistent output.

n = 6;
row = 3;
filled = {{1, 0}, {5, 0}};
prohibited = {{4, 4}, {5, 2}, {3, 3}, {6, 3}};

ClearAll[compbbbeven]

compbbbeven = 
  Compile[{{n, _Integer}, {row, _Integer}, {filled, _Integer, 
     2}, {prohibited, _Integer, 2}, {col, _Integer}},
   
   {Join[filled, {{col, 0}}, 
       Array[{0, 0} &, Length[#] - 1 - Length[filled]]], #} &[
    IntegerPart@Union[Join[prohibited,
       
       {{Mod[row + n/2, n, 1], Mod[col + n/2, n, 1]}},
       
       DeleteCases[
        Flatten[
         MapIndexed[
          Function[{r, c}, Join[{{1, 1}, {2, 2}}]][First[#2], #1] &, 
          DeleteCases[filled[[All, 1]], 0]], 1], {0., 0.}]
       
       ]]], RuntimeAttributes -> {Listable}, CompilationTarget -> "C",
    Parallelization -> True];

col = {1, 2};
Equal @@ Array[compbbbeven[n, row, filled, prohibited, col] &, 50]
Equal @@ Array[compbbbeven[n, row, filled, prohibited, col] &, 50]
Equal @@ Array[compbbbeven[n, row, filled, prohibited, col] &, 50]
Equal @@ Array[compbbbeven[n, row, filled, prohibited, col] &, 50]
Equal @@ Array[compbbbeven[n, row, filled, prohibited, col] &, 50]

The output I received from running the code in one trial was as follows, but it changes from trial to trial.

trial


The original code was bigger, but I was able to reproduce the problems with the above shorter code segments many times. If the bug can be reproduced, I can update my question with shorter code exhibiting the same behavior found by others.

What is going on here?

Notes

  • My Mathematica is version 12.3.1.0 and my OS is macOS Big Sur Version 11.6
  • The code quits kernel behavior was reproduced with Mathematica 12.3.0.0 on Windows 10 and with Mathematica version 12.3.1 on macOS 10.15.7 (Catalina). (see comments)
  • There is a report the version 1 code runs fine with Mathematica 12.0 on macOS 10.15.7 (Catalina). (see comments)
$\endgroup$
9
  • $\begingroup$ Please give an example of the inconsistent output. When I run this I get a "beep" with a message that states "The kernel Local has quit (exited) during the course of an evaluation." If you get an error message, that should be added to your question (as opposed to stating that the kernel crashed). $\endgroup$
    – JimB
    Sep 15, 2021 at 3:52
  • $\begingroup$ @JimB No, I don’t get an error message. What happens to me is what happened to you. The inconsistent output comes from minor variations to the code, not the code as listed. I’ll try to reproduce that. Could you share your OS and Mathematica version? Thank you. $\endgroup$ Sep 15, 2021 at 3:54
  • 2
    $\begingroup$ Please file a detailed bug report at Wolfram Support. It may be a good idea to collect some more user experiences here in order to narrow down the error. $\endgroup$ Sep 15, 2021 at 6:34
  • 1
    $\begingroup$ please report this at [email protected] $\endgroup$
    – Ali Hashmi
    Sep 15, 2021 at 10:19
  • 1
    $\begingroup$ @JimB I have updated my post with a version that gives inconsistent output. $\endgroup$ Sep 16, 2021 at 3:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.