"ignore", message='Using `tqdm.autonotebook.tqdm` in notebook mode') warnings.filterwarnings(
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.
= TemplatedLatexText('''Compute the probability of error when !element_transmitted is transmitted and the power of thermal noise is $\frac{N_0}{2}=!noise_variance$.''') t
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 fill
ing the slots,
='A', noise_variance='2') t.fill(element_transmitted
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.
= TemplatedLatexText('foo foo $A$') t
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>}
= 'hola'
var = TemplatedLatexText.type_to_processing_function[type(var)](var)
tex py2gift.util.render_latex(tex)
hola
= 4
var = TemplatedLatexText.type_to_processing_function[type(var)](var)
tex py2gift.util.render_latex(tex)
4
= 4.2
var = TemplatedLatexText.type_to_processing_function[type(var)](var)
tex py2gift.util.render_latex(tex)
4.2
= np.arange(3)
var = TemplatedLatexText.type_to_processing_function[type(var)](var, to_formula=True)
tex py2gift.util.render_latex(tex)
\(\Large \begin{bmatrix}0 & 1 & 2\end{bmatrix}\)
= [4,5]
var = TemplatedLatexText.type_to_processing_function[type(var)](var, to_formula=True)
tex 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 0x7F45F92D2A40)
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 0x7F45F92D2B40)
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 0x7F45F92D2840)
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 0x7F45F92D2840)
Initialize self. See help(type(self)) for accurate signature.