mitodl / mitx-grading-library

The MITx Grading Library, a python grading library for edX
https://edge.edx.org/courses/course-v1:MITx+grading-library+examples/
BSD 3-Clause "New" or "Revised" License
14 stars 9 forks source link

Sibling values and numbered variables #99

Closed ChristopherChudzicki closed 6 years ago

ChristopherChudzicki commented 6 years ago

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:

jolyonb commented 6 years ago

Addressed by #100.