warnings.filterwarnings("ignore", message='Using `tqdm.autonotebook.tqdm` in notebook mode')Questions’ generators
In order to avoid tqdm’s experimental warning
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.
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
tun-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_fullFalse
Calling the final property without properly filling the wildcards raises an error
# t.finalAfter 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_fullTrue
In such a case, evaluating the object returns the same thing (the final text)
tCompute 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_fullTrue
tfoo 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: list | numpy.ndarray, float_point_precision: int = 3) -> str>,
list: <function py2gift.tex.from_matrix(m: list | numpy.ndarray, float_point_precision: int = 3) -> str>,
int: <function py2gift.tex.from_number(n: int | float, prefix: str | None = '', precision: int | None = 3, fixed_point_format: bool | None = False) -> str>,
float: <function py2gift.tex.from_number(n: int | float, prefix: str | None = '', precision: int | None = 3, fixed_point_format: bool | None = False) -> str>,
numpy.int64: <function py2gift.tex.from_number(n: int | float, prefix: str | None = '', precision: int | None = 3, fixed_point_format: bool | None = False) -> str>,
numpy.float64: <function py2gift.tex.from_number(n: int | float, prefix: str | None = '', precision: int | None = 3, fixed_point_format: bool | None = 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.
QuestionGenerator
QuestionGenerator (statement:__main__.TemplatedLatexText, feedback:__main__.TemplatedLatexText, time:Optional[int]=None, prng:numpy.random.mtrand.Rand omState=RandomState(MT19937) at 0x7FF4E156F740)
Initialize self. See help(type(self)) for accurate signature.
Numerical question
NumericalQuestionGenerator
NumericalQuestionGenerator (statement:__main__.TemplatedLatexText, feedback:__main__.TemplatedLatexText, time:Optional[int]=None, prng:numpy.random.mt rand.RandomState=RandomState(MT19937) at 0x7FF4E156F840)
Initialize self. See help(type(self)) for accurate signature.
Multiple choice
MultipleChoiceQuestionGenerator
MultipleChoiceQuestionGenerator (statement:__main__.TemplatedLatexText, feedback:__main__.TemplatedLatexText, time:Optional[int]=None, prng:numpy.rand om.mtrand.RandomState=RandomState(MT1993 7) at 0x7FF4E156F940)
Initialize self. See help(type(self)) for accurate signature.
Theoretical
MultipleChoiceTheoreticalQuestionGenerator
MultipleChoiceTheoreticalQuestionGenerator (statement:__main__.Templated LatexText, feedback:__main__. TemplatedLatexText, time:Optional[int]=None, prng :numpy.random.mtrand.RandomSt ate=RandomState(MT19937) at 0x7FF4E156F940)
Initialize self. See help(type(self)) for accurate signature.