Questions’ generators

Implementation of the different kinds of questions’ generators.

In order to avoid tqdm’s experimental warning

warnings.filterwarnings("ignore", message='Using `tqdm.autonotebook.tqdm` in notebook mode')

Text with formulas and wildcards

A class to contain text that might include wildcards (“!”) and \(\LaTeX\) formulas. It is ultimately a wrapper around Python’s string.Template.


source

TemplatedLatexText

 TemplatedLatexText (raw_text:str)

Initialize self. See help(type(self)) for accurate signature.

t = TemplatedLatexText('''Compute the probability of error when !element_transmitted is transmitted and the power of thermal noise is $\frac{N_0}{2}=!noise_variance$.''')

Just evaluating the object shows the un-filled text

t
un-filled template:
Compute the probability of error when $element_transmitted is transmitted and the power of thermal noise is $$
rac{N_0}{2}=$noise_variance$$.
t.is_full
False

Calling the final property without properly filling the wildcards raises an error

# t.final

After filling the slots,

t.fill(element_transmitted='A', noise_variance='2')

calling final is fine

t.final
'Compute the probability of error when A is transmitted and the power of thermal noise is $\x0crac{N_0}{2}=2$.'
t.is_full
True

In such a case, evaluating the object returns the same thing (the final text)

t
Compute the probability of error when A is transmitted and the power of thermal noise is $
rac{N_0}{2}=2$.

If the wrapped text does not contain any wildcard, !, then there is no need to call fill to get the final text.

t = TemplatedLatexText('foo foo $A$')
t.is_full
True
t
foo foo $A$

For automatic conversion of different types to string

TemplatedLatexText.type_to_processing_function
{str: <function __main__.TemplatedLatexText.<lambda>(x)>,
 pathlib.PosixPath: <function __main__.TemplatedLatexText.<lambda>(x)>,
 numpy.ndarray: <function py2gift.tex.from_matrix(m: Union[list, numpy.ndarray], float_point_precision: int = 3) -> str>,
 list: <function py2gift.tex.from_matrix(m: Union[list, numpy.ndarray], float_point_precision: int = 3) -> str>,
 int: <function py2gift.tex.from_number(n: Union[int, float], prefix: str = '', precision: int = 3, fixed_point_format: bool = False) -> str>,
 float: <function py2gift.tex.from_number(n: Union[int, float], prefix: str = '', precision: int = 3, fixed_point_format: bool = False) -> str>,
 numpy.int64: <function py2gift.tex.from_number(n: Union[int, float], prefix: str = '', precision: int = 3, fixed_point_format: bool = False) -> str>,
 numpy.float64: <function py2gift.tex.from_number(n: Union[int, float], prefix: str = '', precision: int = 3, fixed_point_format: bool = False) -> str>}
var = 'hola'
tex = TemplatedLatexText.type_to_processing_function[type(var)](var)
py2gift.util.render_latex(tex)

hola

var = 4
tex = TemplatedLatexText.type_to_processing_function[type(var)](var)
py2gift.util.render_latex(tex)

4

var = 4.2
tex = TemplatedLatexText.type_to_processing_function[type(var)](var)
py2gift.util.render_latex(tex)

4.2

var = np.arange(3)
tex = TemplatedLatexText.type_to_processing_function[type(var)](var, to_formula=True)
py2gift.util.render_latex(tex)

\(\Large \begin{bmatrix}0 & 1 & 2\end{bmatrix}\)

var = [4,5]
tex = TemplatedLatexText.type_to_processing_function[type(var)](var, to_formula=True)
py2gift.util.render_latex(tex)

\(\Large \begin{bmatrix}4 & 5\end{bmatrix}\)

Generators

A class implementing a generic question.


source

QuestionGenerator

 QuestionGenerator (statement:__main__.TemplatedLatexText,
                    feedback:__main__.TemplatedLatexText,
                    time:Optional[int]=None, prng:numpy.random.mtrand.Rand
                    omState=RandomState(MT19937) at 0x7F45F92D2A40)

Initialize self. See help(type(self)) for accurate signature.

Numerical question


source

NumericalQuestionGenerator

 NumericalQuestionGenerator (statement:__main__.TemplatedLatexText,
                             feedback:__main__.TemplatedLatexText,
                             time:Optional[int]=None, prng:numpy.random.mt
                             rand.RandomState=RandomState(MT19937) at
                             0x7F45F92D2B40)

Initialize self. See help(type(self)) for accurate signature.

Multiple choice


source

MultipleChoiceQuestionGenerator

 MultipleChoiceQuestionGenerator (statement:__main__.TemplatedLatexText,
                                  feedback:__main__.TemplatedLatexText,
                                  time:Optional[int]=None, prng:numpy.rand
                                  om.mtrand.RandomState=RandomState(MT1993
                                  7) at 0x7F45F92D2840)

Initialize self. See help(type(self)) for accurate signature.

Theoretical


source

MultipleChoiceTheoreticalQuestionGenerator

 MultipleChoiceTheoreticalQuestionGenerator
                                             (statement:__main__.Templated
                                             LatexText, feedback:__main__.
                                             TemplatedLatexText,
                                             time:Optional[int]=None, prng
                                             :numpy.random.mtrand.RandomSt
                                             ate=RandomState(MT19937) at
                                             0x7F45F92D2840)

Initialize self. See help(type(self)) for accurate signature.