When a FormulaGrader with numbered_vars is used inside a ListGrader, things can break. For example:
from pprint import pprint as pp
from mitxgraders import *
grader = ListGrader(
answers=[
['lambda*hbar*omega', '(ket_{1}-i*ket_{3})/sqrt(2)'],
['0', 'ket_{2}'],
['-lambda*hbar*omega', '(ket_{1}+i*ket_{3})/sqrt(2)'],
],
subgraders=ListGrader(
subgraders=FormulaGrader(
variables=['lambda', 'hbar', 'omega'],
numbered_vars=['ket']
),
ordered=True
),
grouping=[1, 1, 2, 2, 3, 3],
debug=True
)
answers = [
# First pair
'lambda*hbar*omega',
'(ket_{1}-i*ket_{3})/sqrt(2)',
# Second pair
'0',
'ket_{2}',
# Third pair
'-lambda*hbar*omega',
'(ket_{1}+i*ket_{3})/sqrt(2)']
pp(grader(None, answers))
When the first input 'lambda*hbar*omega' is evaluated, it also tries to evaluate sibling inputs and pass the values to its comparer function. But when FormulaGrader tries to evaluate the sibling, none of the numbered_vars are defined (since neither the input nor the answer contained any), so an error is thrown.
It's also kind of silly that FormulaGrader is even trying to calculate its sibling values, since none of the comparer_params use the sibling values in this example.
Suggested Fix:
[ ] Only try to evaluate siblings if the comparer_params use sibling values
[ ] Use sibling values to generate numbered variables, too.
When a FormulaGrader with numbered_vars is used inside a ListGrader, things can break. For example:
When the first input
'lambda*hbar*omega'
is evaluated, it also tries to evaluate sibling inputs and pass the values to its comparer function. But when FormulaGrader tries to evaluate the sibling, none of the numbered_vars are defined (since neither the input nor the answer contained any), so an error is thrown.It's also kind of silly that FormulaGrader is even trying to calculate its sibling values, since none of the
comparer_params
use the sibling values in this example.Suggested Fix: