openwebwork / pg

Problem rendering engine for WeBWorK
http://webwork.maa.org/wiki/Category:Authors
Other
45 stars 76 forks source link

Error with Matrix answer checkers #612

Open dlglin opened 3 years ago

dlglin commented 3 years ago

Copied from https://webwork.maa.org/moodle/mod/forum/discuss.php?d=6553 When using the cmp method for a Matrix MathObject, if a student enters a list that is not a matrix, then they get an error like the following:

Error messages

'require' trapped by operation mask at /usr/lib64/perl5/vendor_perl/Encode.pm line 5. Compilation failed in require at /usr/lib64/perl5/vendor_perl/Encode/Alias.pm line 22.

Call stack

The following information can help locate the source of the problem.

in WeBWorK::PG::Local::new called at line 51 of /opt/webwork/webwork2/lib/WeBWorK/PG.pm in WeBWorK::PG::new called at line 738 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm in WeBWorK::ContentGenerator::Problem::pre_header_initialize called at line 213 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm in WeBWorK::ContentGenerator::go called at line 386 of /opt/webwork/webwork2/lib/WeBWorK.pm

The one exception is if they enter the correct answer without the outer brackets.

A MWE is quoted at the end of this message. For that MWE, if a student enters a valid matrix, it is graded properly. If they enter a matrix with a syntax error, they get an appropriate message. If they enter a list that is not a matrix (e.g. "1,2", or "[1,2],[3,5]"), they get the error quoted above. The one exception is if they enter "[1,2],[3,4]", which is marked correct (and shouldn't be IMO, since that is a list of 1x2 matrices, and not a 2x2 matrix).

DOCUMENT();        # This should be the first executable line in the problem.

loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"MathObjects.pl",
);

TEXT(&beginproblem);
$showPartialCorrectAnswers = 1;

Context("Matrix");

$B = Matrix([[1,2],[3,4]]);

BEGIN_TEXT
Enter \(\{$B->TeX\}\)$PAR
\{ans_rule(50)\}
END_TEXT

ANS($B->cmp());

ENDDOCUMENT();
taniwallach commented 2 years ago

The issue about a list of vectors being turned into a matrix is probably something @dpvc can help us examine and determine whether that behavior can be fixed without breaking something else.

The error message looks like something related to WWSafe and a failure to be able to use Encode fully inside a safe compartment. See https://github.com/openwebwork/webwork2/issues/982 . Parts of pg do not use Encode and instead use alternate UTF-8 support approaches due to problems getting Encode to work inside WWSafe. Upgrading to depend on a more modern version of Safe might help overcome some of these problems. However, even @mgage approaches Safe/WWSafe with great caution - so such work has not been a top priority.