QuizGenerator 0.6.3__py3-none-any.whl → 0.7.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- QuizGenerator/contentast.py +2191 -2193
- QuizGenerator/misc.py +1 -1
- QuizGenerator/mixins.py +64 -64
- QuizGenerator/premade_questions/basic.py +16 -16
- QuizGenerator/premade_questions/cst334/languages.py +26 -26
- QuizGenerator/premade_questions/cst334/math_questions.py +42 -42
- QuizGenerator/premade_questions/cst334/memory_questions.py +124 -124
- QuizGenerator/premade_questions/cst334/persistence_questions.py +48 -48
- QuizGenerator/premade_questions/cst334/process.py +38 -38
- QuizGenerator/premade_questions/cst463/gradient_descent/gradient_calculation.py +45 -45
- QuizGenerator/premade_questions/cst463/gradient_descent/gradient_descent_questions.py +34 -34
- QuizGenerator/premade_questions/cst463/gradient_descent/loss_calculations.py +53 -53
- QuizGenerator/premade_questions/cst463/gradient_descent/misc.py +2 -2
- QuizGenerator/premade_questions/cst463/math_and_data/matrix_questions.py +65 -65
- QuizGenerator/premade_questions/cst463/math_and_data/vector_questions.py +39 -39
- QuizGenerator/premade_questions/cst463/models/attention.py +36 -36
- QuizGenerator/premade_questions/cst463/models/cnns.py +26 -26
- QuizGenerator/premade_questions/cst463/models/rnns.py +36 -36
- QuizGenerator/premade_questions/cst463/models/text.py +32 -32
- QuizGenerator/premade_questions/cst463/models/weight_counting.py +15 -15
- QuizGenerator/premade_questions/cst463/neural-network-basics/neural_network_questions.py +124 -124
- QuizGenerator/premade_questions/cst463/tensorflow-intro/tensorflow_questions.py +161 -161
- QuizGenerator/question.py +41 -41
- QuizGenerator/quiz.py +7 -7
- QuizGenerator/regenerate.py +114 -13
- QuizGenerator/typst_utils.py +2 -2
- {quizgenerator-0.6.3.dist-info → quizgenerator-0.7.1.dist-info}/METADATA +1 -1
- {quizgenerator-0.6.3.dist-info → quizgenerator-0.7.1.dist-info}/RECORD +31 -31
- {quizgenerator-0.6.3.dist-info → quizgenerator-0.7.1.dist-info}/WHEEL +0 -0
- {quizgenerator-0.6.3.dist-info → quizgenerator-0.7.1.dist-info}/entry_points.txt +0 -0
- {quizgenerator-0.6.3.dist-info → quizgenerator-0.7.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -4,7 +4,7 @@ import logging
|
|
|
4
4
|
import math
|
|
5
5
|
|
|
6
6
|
from QuizGenerator.question import Question, QuestionRegistry
|
|
7
|
-
|
|
7
|
+
import QuizGenerator.contentast as ca
|
|
8
8
|
from QuizGenerator.constants import MathRanges
|
|
9
9
|
|
|
10
10
|
log = logging.getLogger(__name__)
|
|
@@ -31,19 +31,19 @@ class BitsAndBytes(MathQuestion):
|
|
|
31
31
|
self.num_bytes = int(math.pow(2, self.num_bits))
|
|
32
32
|
|
|
33
33
|
if self.from_binary:
|
|
34
|
-
self.answers = {"answer": AnswerTypes.Int(self.num_bytes,
|
|
34
|
+
self.answers = {"answer": ca.AnswerTypes.Int(self.num_bytes,
|
|
35
35
|
label="Address space size", unit="Bytes")}
|
|
36
36
|
else:
|
|
37
|
-
self.answers = {"answer": AnswerTypes.Int(self.num_bits,
|
|
37
|
+
self.answers = {"answer": ca.AnswerTypes.Int(self.num_bits,
|
|
38
38
|
label="Number of bits in address", unit="bits")}
|
|
39
39
|
|
|
40
40
|
def _get_body(self, **kwargs):
|
|
41
41
|
"""Build question body and collect answers."""
|
|
42
42
|
answers = [self.answers['answer']]
|
|
43
43
|
|
|
44
|
-
body =
|
|
44
|
+
body = ca.Section()
|
|
45
45
|
body.add_element(
|
|
46
|
-
|
|
46
|
+
ca.Paragraph([
|
|
47
47
|
f"Given that we have "
|
|
48
48
|
f"{self.num_bits if self.from_binary else self.num_bytes} {'bits' if self.from_binary else 'bytes'}, "
|
|
49
49
|
f"how many {'bits' if not self.from_binary else 'bytes'} "
|
|
@@ -51,44 +51,44 @@ class BitsAndBytes(MathQuestion):
|
|
|
51
51
|
])
|
|
52
52
|
)
|
|
53
53
|
|
|
54
|
-
body.add_element(
|
|
54
|
+
body.add_element(ca.AnswerBlock(self.answers['answer']))
|
|
55
55
|
|
|
56
56
|
return body, answers
|
|
57
57
|
|
|
58
|
-
def get_body(self, **kwargs) ->
|
|
58
|
+
def get_body(self, **kwargs) -> ca.Section:
|
|
59
59
|
"""Build question body (backward compatible interface)."""
|
|
60
60
|
body, _ = self._get_body(**kwargs)
|
|
61
61
|
return body
|
|
62
62
|
|
|
63
63
|
def _get_explanation(self, **kwargs):
|
|
64
|
-
explanation =
|
|
64
|
+
explanation = ca.Section()
|
|
65
65
|
|
|
66
66
|
explanation.add_element(
|
|
67
|
-
|
|
67
|
+
ca.Paragraph([
|
|
68
68
|
"Remember that for these problems we use one of these two equations (which are equivalent)"
|
|
69
69
|
])
|
|
70
70
|
)
|
|
71
71
|
explanation.add_elements([
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
ca.Equation(r"log_{2}(\text{#bytes}) = \text{#bits}"),
|
|
73
|
+
ca.Equation(r"2^{(\text{#bits})} = \text{#bytes}")
|
|
74
74
|
])
|
|
75
75
|
|
|
76
76
|
explanation.add_element(
|
|
77
|
-
|
|
77
|
+
ca.Paragraph(["Therefore, we calculate:"])
|
|
78
78
|
)
|
|
79
79
|
|
|
80
80
|
if self.from_binary:
|
|
81
81
|
explanation.add_element(
|
|
82
|
-
|
|
82
|
+
ca.Equation(f"2 ^ {{{self.num_bits}bits}} = \\textbf{{{self.num_bytes}}}\\text{{bytes}}")
|
|
83
83
|
)
|
|
84
84
|
else:
|
|
85
85
|
explanation.add_element(
|
|
86
|
-
|
|
86
|
+
ca.Equation(f"log_{{2}}({self.num_bytes} \\text{{bytes}}) = \\textbf{{{self.num_bits}}}\\text{{bits}}")
|
|
87
87
|
)
|
|
88
88
|
|
|
89
89
|
return explanation, []
|
|
90
90
|
|
|
91
|
-
def get_explanation(self, **kwargs) ->
|
|
91
|
+
def get_explanation(self, **kwargs) -> ca.Section:
|
|
92
92
|
"""Build question explanation (backward compatible interface)."""
|
|
93
93
|
explanation, _ = self._get_explanation(**kwargs)
|
|
94
94
|
return explanation
|
|
@@ -111,39 +111,39 @@ class HexAndBinary(MathQuestion):
|
|
|
111
111
|
self.binary_val = f"0b{self.value:0{4*self.number_of_hexits}b}"
|
|
112
112
|
|
|
113
113
|
if self.from_binary:
|
|
114
|
-
self.answers['answer'] = AnswerTypes.String(self.hex_val,
|
|
114
|
+
self.answers['answer'] = ca.AnswerTypes.String(self.hex_val,
|
|
115
115
|
label="Value in hex")
|
|
116
116
|
else:
|
|
117
|
-
self.answers['answer'] = AnswerTypes.String(self.binary_val,
|
|
117
|
+
self.answers['answer'] = ca.AnswerTypes.String(self.binary_val,
|
|
118
118
|
label="Value in binary")
|
|
119
119
|
|
|
120
120
|
def _get_body(self, **kwargs):
|
|
121
121
|
"""Build question body and collect answers."""
|
|
122
122
|
answers = [self.answers['answer']]
|
|
123
123
|
|
|
124
|
-
body =
|
|
124
|
+
body = ca.Section()
|
|
125
125
|
|
|
126
126
|
body.add_element(
|
|
127
|
-
|
|
127
|
+
ca.Paragraph([
|
|
128
128
|
f"Given the number {self.hex_val if not self.from_binary else self.binary_val} "
|
|
129
129
|
f"please convert it to {'hex' if self.from_binary else 'binary'}.",
|
|
130
130
|
"Please include base indicator all padding zeros as appropriate (e.g. 0x01 should be 0b00000001)",
|
|
131
131
|
])
|
|
132
132
|
)
|
|
133
133
|
|
|
134
|
-
body.add_element(
|
|
134
|
+
body.add_element(ca.AnswerBlock(self.answers['answer']))
|
|
135
135
|
|
|
136
136
|
return body, answers
|
|
137
137
|
|
|
138
|
-
def get_body(self, **kwargs) ->
|
|
138
|
+
def get_body(self, **kwargs) -> ca.Section:
|
|
139
139
|
"""Build question body (backward compatible interface)."""
|
|
140
140
|
body, _ = self._get_body(**kwargs)
|
|
141
141
|
return body
|
|
142
142
|
|
|
143
143
|
def _get_explanation(self, **kwargs):
|
|
144
|
-
explanation =
|
|
144
|
+
explanation = ca.Section()
|
|
145
145
|
|
|
146
|
-
paragraph =
|
|
146
|
+
paragraph = ca.Paragraph([
|
|
147
147
|
"The core idea for converting between binary and hex is to divide and conquer. "
|
|
148
148
|
"Specifically, each hexit (hexadecimal digit) is equivalent to 4 bits. "
|
|
149
149
|
])
|
|
@@ -164,7 +164,7 @@ class HexAndBinary(MathQuestion):
|
|
|
164
164
|
hex_str = f"{self.value:0{self.number_of_hexits}X}"
|
|
165
165
|
|
|
166
166
|
explanation.add_element(
|
|
167
|
-
|
|
167
|
+
ca.Table(
|
|
168
168
|
data=[
|
|
169
169
|
["0b"] + [binary_str[i:i+4] for i in range(0, len(binary_str), 4)],
|
|
170
170
|
["0x"] + list(hex_str)
|
|
@@ -177,20 +177,20 @@ class HexAndBinary(MathQuestion):
|
|
|
177
177
|
|
|
178
178
|
if self.from_binary:
|
|
179
179
|
explanation.add_element(
|
|
180
|
-
|
|
180
|
+
ca.Paragraph([
|
|
181
181
|
f"Which gives us our hex value of: 0x{hex_str}"
|
|
182
182
|
])
|
|
183
183
|
)
|
|
184
184
|
else:
|
|
185
185
|
explanation.add_element(
|
|
186
|
-
|
|
186
|
+
ca.Paragraph([
|
|
187
187
|
f"Which gives us our binary value of: 0b{binary_str}"
|
|
188
188
|
])
|
|
189
189
|
)
|
|
190
190
|
|
|
191
191
|
return explanation, []
|
|
192
192
|
|
|
193
|
-
def get_explanation(self, **kwargs) ->
|
|
193
|
+
def get_explanation(self, **kwargs) -> ca.Section:
|
|
194
194
|
"""Build question explanation (backward compatible interface)."""
|
|
195
195
|
explanation, _ = self._get_explanation(**kwargs)
|
|
196
196
|
return explanation
|
|
@@ -223,7 +223,7 @@ class AverageMemoryAccessTime(MathQuestion):
|
|
|
223
223
|
self.amat = self.hit_rate * self.hit_latency + (1 - self.hit_rate) * self.miss_latency
|
|
224
224
|
|
|
225
225
|
self.answers = {
|
|
226
|
-
"amat": AnswerTypes.Float(self.amat, label="Average Memory Access Time", unit="cycles")
|
|
226
|
+
"amat": ca.AnswerTypes.Float(self.amat, label="Average Memory Access Time", unit="cycles")
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
# Finally, do the self.rngizing of the question, to avoid these being non-deterministic
|
|
@@ -236,14 +236,14 @@ class AverageMemoryAccessTime(MathQuestion):
|
|
|
236
236
|
"""Build question body and collect answers."""
|
|
237
237
|
answers = [self.answers["amat"]]
|
|
238
238
|
|
|
239
|
-
body =
|
|
239
|
+
body = ca.Section()
|
|
240
240
|
|
|
241
241
|
# Add in background information
|
|
242
242
|
body.add_element(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
f"Please round your answer to {
|
|
243
|
+
ca.Paragraph([
|
|
244
|
+
ca.Text("Please calculate the Average Memory Access Time given the below information. "),
|
|
245
|
+
ca.Text(
|
|
246
|
+
f"Please round your answer to {ca.Answer.DEFAULT_ROUNDING_DIGITS} decimal points. ",
|
|
247
247
|
hide_from_latex=True
|
|
248
248
|
)
|
|
249
249
|
])
|
|
@@ -260,28 +260,28 @@ class AverageMemoryAccessTime(MathQuestion):
|
|
|
260
260
|
table_data.append(["Hit Rate", f"{100 * self.hit_rate: 0.2f}%"])
|
|
261
261
|
|
|
262
262
|
body.add_element(
|
|
263
|
-
|
|
263
|
+
ca.Table(
|
|
264
264
|
data=table_data
|
|
265
265
|
)
|
|
266
266
|
)
|
|
267
267
|
|
|
268
|
-
body.add_element(
|
|
268
|
+
body.add_element(ca.LineBreak())
|
|
269
269
|
|
|
270
|
-
body.add_element(
|
|
270
|
+
body.add_element(ca.AnswerBlock(self.answers["amat"]))
|
|
271
271
|
|
|
272
272
|
return body, answers
|
|
273
273
|
|
|
274
|
-
def get_body(self, **kwargs) ->
|
|
274
|
+
def get_body(self, **kwargs) -> ca.Section:
|
|
275
275
|
"""Build question body (backward compatible interface)."""
|
|
276
276
|
body, _ = self._get_body(**kwargs)
|
|
277
277
|
return body
|
|
278
278
|
|
|
279
279
|
def _get_explanation(self, **kwargs):
|
|
280
|
-
explanation =
|
|
280
|
+
explanation = ca.Section()
|
|
281
281
|
|
|
282
282
|
# Add in General explanation
|
|
283
283
|
explanation.add_element(
|
|
284
|
-
|
|
284
|
+
ca.Paragraph([
|
|
285
285
|
"Remember that to calculate the Average Memory Access Time "
|
|
286
286
|
"we weight both the hit and miss times by their relative likelihood.",
|
|
287
287
|
"That is, we calculate:"
|
|
@@ -290,18 +290,18 @@ class AverageMemoryAccessTime(MathQuestion):
|
|
|
290
290
|
|
|
291
291
|
# Add in equations
|
|
292
292
|
explanation.add_element(
|
|
293
|
-
|
|
293
|
+
ca.Equation.make_block_equation__multiline_equals(
|
|
294
294
|
lhs="AMAT",
|
|
295
295
|
rhs=[
|
|
296
296
|
r"(hit\_rate)*(hit\_cost) + (1 - hit\_rate)*(miss\_cost)",
|
|
297
|
-
f"({self.hit_rate: 0.{
|
|
297
|
+
f"({self.hit_rate: 0.{ca.Answer.DEFAULT_ROUNDING_DIGITS}f})*({self.hit_latency}) + ({1 - self.hit_rate: 0.{ca.Answer.DEFAULT_ROUNDING_DIGITS}f})*({self.miss_latency}) = {self.amat: 0.{ca.Answer.DEFAULT_ROUNDING_DIGITS}f}\\text{{cycles}}"
|
|
298
298
|
]
|
|
299
299
|
)
|
|
300
300
|
)
|
|
301
301
|
|
|
302
302
|
return explanation, []
|
|
303
303
|
|
|
304
|
-
def get_explanation(self, **kwargs) ->
|
|
304
|
+
def get_explanation(self, **kwargs) -> ca.Section:
|
|
305
305
|
"""Build question explanation (backward compatible interface)."""
|
|
306
306
|
explanation, _ = self._get_explanation(**kwargs)
|
|
307
307
|
return explanation
|