WeBWorK Main Forum

Issue with Answer selection errors after upgrade to 2.19

Issue with Answer selection errors after upgrade to 2.19

by Bianca Sosnovski -
Number of replies: 2

Hi everyone,

We are encountering the following error in several problems where answers must be selected from a radio button or a popup menu:

----------------

PG question processing error messages

PG warning messages

Error in Translator.pm::process_answers: Answer AnSwEr0001: Unrecognized evaluator type |HASH|
Answer evaluator AnSwEr0001 was not executed due to errors.

----------------

Since upgrading our server to version 2.19, we’ve been facing several issues that were not present prior to the upgrade. We may need to rebuild the server to resolve these issues.

Below is a sample code for a problem that triggers this error. 

Thanks in advance.

DOCUMENT();

loadMacros(

  "PGgraphmacros.pl",

  "PGstandard.pl",

  "MathObjects.pl",

  "PGML.pl",

  "parserRadioButtons.pl",

  "contextFraction.pl",

  "PCCgraphMacros.pl",

  "pccTables.pl",

  "PGcourse.pl",

);

 

##############################################

 

Context("Point");

$refreshCachedImages=1;

 

#These two arrays store the coordinates of the intersections.

#(x[0],y[0]) is the correct solution in the correct graph.

#(x[1],y[1]), (x[2],y[2]), (x[3],y[3]) are incorrect solutions.

#(x[4],y[4]) is used in the solution.

@x=();

@y=();

 

# This array stores the y-intercepts of lines.

# b[0][0] and b[0][1] are y-intercepts of lines in the correct graph.

# b[i][0] and b[i][1] are y-intercepts of lines in wrong graphs.

# b[i][2] stores whether the second line is vertical or horizontal (used

# in graph's alt and title.

# b[4][0] and b[4][1] are used in solution.

@b=([],[],[],[],[]); 

 

#Set the correct solution.

$x[0] = non_zero_random(-3,3,1);

do {$y[0] = non_zero_random(-3,3,1);} until ($y[0]!=$x[0]);

$intersection = Compute("($x[0],$y[0])");

 

Context("Fraction");

Context()->noreduce("(-x)-y","(-x)+y");

 

#Set both lines in the correct solution graph

do {$b[0][0]=$y[0]+non_zero_random(2,4,1)*random(-1,1,2);}

  until ($y[0] != (($y[0]-$b[0][0])/$x[0]*$y[0]+$b[0][0])); #prevents duplicate graphs

$b[0][1]=$y[0];

$b[0][2]="horizontal";

 

#Set wrong solutions

do {$x[1] = $x[0]+random(-1,1,2);} until ($x[1]!=0);

$y[1] = $y[0];

$b[1][0]=$b[0][0];

$b[1][1]=$b[0][1];

$b[1][2]="horizontal";

 

$b[2][0]=$b[0][0];

$x[2] = $y[0];

$y[2] = ($y[0]-$b[0][0])/$x[0]*$y[0] + $b[0][0];

$b[2][2]="vertical";

 

$b[3][0]=$b[0][0];

$x[3] = $x[0];

$y[3] = $y[0];

$b[3][2]="vertical";

 

#$x[4] and $y[4] are used in solution.

$x[4] = $x[0];

$y[4] = $y[0];

$b[4][0]=$b[0][0];

$b[4][1]=$b[0][1];

$b[4][2]=$b[0][2];

 

#Dump out the correct answer's slope's rise and run. 

#These will be used in the solution.

$m0Correct = Fraction($y[0]-$b[0][0],$x[0])->reduce;

@temp = $m0Correct->value;

$m0Rise = @temp[0];

$m0Run = @temp[1];

 

$m1Correct = 0;

 

#Create a hash and its inverse that randomizes the order of the four graphs.

%scramble = ();

%inverse = ();

for my $i (0..3) {

  do {$temp = list_random(0..3)} until !(grep(/^$temp$/,values %scramble) );

  $scramble{$i} = $temp;

  $inverse{$temp} = $i;

};

 

$scramble{4} = 4;

$inverse{4} = 4;

 

$xmin = -10;

$xmax = -$xmin;

$ymin = -10;

$ymax = -$ymin;

 

#These two variables decide how many labels are on each axis.

$xmark = ceil($xmax/10);

$ymark = ceil($ymax/10);

 

@gr=();

 

#$gr[0] through $gr[3] are options; $gr[4] is used in solution.

for ($i=0;$i<=4;$i++) {

   $gr[$i] = init_graph($xmin,$ymin,$xmax,$ymax,

   axes=>[0,0],

   grid=>[$xmax-$xmin,$ymax-$ymin],

   size=>[xPixels(),yPixels()]

   );

   $gr[$i]->lb('reset');

   for ($j=-$xmax+$xmark;$j<$xmax;$j=$j+$xmark) {

      $gr[$i]->lb( new Label($j,  -0.1, $j,'black','center','top'));

   }

   for ($j=-$ymax+$ymark;$j<$ymax;$j=$j+$ymark) {

      if (Real($j) == 0) {next;}

      $gr[$i]->lb( new Label(0,  $j,' '.$j,'black','left','middle'));

   }

   $gr[$i]->lb( new Label($xmin, $ymax, ' '.$ALPHABET[$inverse{$i}], 'black', 'left', 'top')) unless ($i==4);

   $m1 = ($y[$i]-$b[$i][0])/$x[$i];

   add_functions($gr[$i], "$m1*x+$b[$i][0] for x in <$xmin,$xmax> using color:red and weight:1");

 

   if (($i==0) || ($i==1) || ($i==4)) {

      $m2 = ($y[$i]-$b[$i][1])/$x[$i];

      add_functions($gr[$i], "$m2*x+$b[$i][1] for x in <$xmin,$xmax> using color:blue and weight:1");

   }

 

   if ($i==2) {

      $gr[$i]->moveTo($y[0],$ymin);

      $gr[$i]->lineTo($y[0],$ymax,'blue',2);

   }

 

   if ($i==3) {

      $gr[$i]->moveTo($x[0],$ymin);

      $gr[$i]->lineTo($x[0],$ymax,'blue',2);

   }

 

   $ALTtags[$i]="Graph $ALPHABET[$inverse{$i}]: This is a graph of two lines intersecting at ($x[$i],$y[$i]). One line is $b[$i][2].";

}

 

pop(@ALTtags);

push(@ALTtags,"This is a graph of two lines intersecting at ($x[4],$y[4]). One line is $b[4][2].");

 

 

$radio = RadioButtons(

  ["A","B","C","D"],

  $ALPHABET[$inverse{0}], # correct answer

  order => ["A","B","C","D"],

);

 

#for display purposes

$func0 = Compute("$m0Correct*x+ $b[0][0]")->reduce;

$horiY = $y[0];

 

##############################################

 

TEXT(beginproblem());

 

BEGIN_PGML

 

Solve the system of equations by graphing. Choose the graph that represents the two given line equations, and then enter the solution. 

 

    [``

  \left\{\begin{aligned}

  y &=  [$func0] \\

  y &=  [$horiY] \\

\end{aligned}

  \right.

    ``]

 

[@EnlargeImageStatementPGML()@]** 

 

    The correct graph is graph    

    [@$radio->buttons()@]*

 

The solution of this system, written as an ordered pair, is [_______________].

 

END_PGML

 

Context()->texStrings;

BEGIN_TEXT

$PAR

$BCENTER

\{ 

LayoutTable([[image( insertGraph($gr[$scramble{0}]), width=>xScreen(), height=>yScreen(), tex_size=>TeXscalar(), extra_html_tags=>'alt = "$ALTtags[$scramble{0}]" title = "$ALTtags[$scramble{0}]"'  ),

image( insertGraph($gr[$scramble{1}]), width=>xScreen(), height=>yScreen(), tex_size=>TeXscalar(), extra_html_tags=>'alt = "$ALTtags[$scramble{1}]" title = "$ALTtags[$scramble{1}]"'  ),

],

[image( insertGraph($gr[$scramble{2}]), width=>xScreen(), height=>yScreen(), tex_size=>TeXscalar(), extra_html_tags=>'alt = "$ALTtags[$scramble{2}]" title = "$ALTtags[$scramble{2}]"'  ),

image( insertGraph($gr[$scramble{3}]), width=>xScreen(), height=>yScreen(), tex_size=>TeXscalar(), extra_html_tags=>'alt = "$ALTtags[$scramble{3}]" title = "$ALTtags[$scramble{3}]"'  )

]], allcellcss => "padding:20pt;")

 

\}

$ECENTER

$PAR

 

 

END_TEXT

 

Context()->normalStrings;

 

##############################################

 

ANS( $radio->cmp() );

ANS( $intersection->cmp() );

 

#Graph the intersection in solution.

$gr[4]->stamps( closed_circle($x[0],$y[0],'black') );

$gr[4]->lb( new Label($x[0],$y[0]," ($x[0],$y[0])",'black','left','top'));

 

#Graph slope triangle in the first line.

$gr[4]->moveTo(0,$b[0][0]);

$xCor=0;

$yCor=$b[0][0];

$xStep = $x[0]>0 ? $m0Run : -$m0Run;

$yStep = ($y[0]-$yCor)>0 ? abs($m0Rise) : -abs($m0Rise);

do {

   $xCor += $xStep;

   $gr[4]->lineTo($xCor,$yCor,'red',2);

   $yCor += $yStep;

   $gr[4]->lineTo($xCor,$yCor,'red',2);

} until ($xCor==$x[0]);

 

 

Context()->texStrings;

BEGIN_SOLUTION

$PAR

To solve a system of linear equations by graphing, one way is to first graph each line's \(y\)-intercept, and then draw slope triangles until we find the intersection. If we use a method where we connect two points using a straightedge, slight inaccuracies in the placement of the straightedge can lead to very inaccurate solutions.$PAR

For this problem, the first equation is given in slope-intercept form. We can graph its \(y\)-intercept, and then draw slope triangles. 

$PAR

The second line is horizontal.

$PAR

See solution in the graph:

$PAR

$BCENTER

\{ image( insertGraph($gr[4]), width=>xScreen(), height=>yScreen(), tex_size=>TeXscalar(), extra_html_tags=>'alt = "$ALTtags[$scramble{4}]" title = "$ALTtags[$scramble{4}]"'  ) \}

$ECENTER

$PAR

The solution to this system of equations is \( ($x[0],$y[0]) \). \{ $radio->correct_ans() \} is the correct answer.

$PAR

 

END_SOLUTION

Context()->normalStrings;

 

ENDDOCUMENT();

 

 


In reply to Bianca Sosnovski

Re: Issue with Answer selection errors after upgrade to 2.19

by Alex Jordan -
I do not get an issue like that when I copy this problem and use it on a 2.19 server. (I did need to remove blank lines in between the [`` and ``] though. But I think those blank lines are just an artifact from when you pasted the problem code here.)

Can you check that your webwork2 and pg repositories are where they should be? What do you get from:

cd /opt/webwork/webwork2
git status
and from:

cd /opt/webwork/pg
git status
and then have you rebuilt dependencies and restarted both webwork2 and webwork2-job-queue?

cd /opt/webwork/webwork2/htdocs
npm ci
cd /opt/webwork/pg/htdocs
npm ci
sudo systemctl restart webwork2
sudo systemctl restart webwork2-job-queue




In reply to Alex Jordan

Re: Issue with Answer selection errors after upgrade to 2.19

by Bianca Sosnovski -
Hi Alex,

Thanks for your help!

As you suggested, I ran "git status" and discovered that some files in the macros folder had been modified.

Here’s what happened: When we built WeBWorK 2.19 from scratch, many macros used for the college’s problem bank were missing. To restore them, we copied the necessary files from the older server (2.16) to the new one. However, this led to some duplicates, which caused rendering issues. After reviewing the macros, we deleted the redundant files.

Unfortunately, in the process, PG.pl and a couple of parser files were mistakenly replaced with the older 2.16 versions. 🤦‍♀️ Since these files differ from those in 2.19, this caused the issue.

Thankfully, after checking "git status", I was able to identify the affected files and restore them to their correct 2.19 versions. This also resolved other issues which I posted here (https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8651).

Now our Webwork server is running perfectly! I love it!!

Thanks again!