Skip to content

Commit 9466061

Browse files
authored
Merge pull request #1 from lambda-feedback/fix/IO-and-structure
Fix/io and structure
2 parents f52ed0d + 719ab52 commit 9466061

File tree

4 files changed

+57
-31
lines changed

4 files changed

+57
-31
lines changed

Dockerfile

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest AS final
2-
3-
# Use the WSTP server as a kernel backend
4-
ENV WSTP_SERVER="true"
1+
FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest as base
52

63
# Command to start the evaluation function with
74
ENV FUNCTION_COMMAND="wolframscript"
@@ -12,22 +9,17 @@ ENV FUNCTION_ARGS="-f,/app/evaluation_function.wl"
129
# Interface to use for the evaluation function
1310
ENV FUNCTION_INTERFACE="file"
1411

12+
ENV LOG_LEVEL="DEBUG"
13+
1514
# Copy the evaluation function to the app directory
1615
COPY ./evaluation_function.wl /app/evaluation_function.wl
1716

18-
# Final layer for private images, which contains the wolfram licence key,
19-
# and is started with the shimmy handle command.
20-
FROM final AS final-private
21-
22-
# Copy the mathpass secret to the Wolfram Engine licensing directory.
23-
# See https://hub.docker.com/r/wolframresearch/wolframengine for more information.
24-
RUN --mount=type=secret,id=mathpass \
25-
mkdir -p /tmp/home/.WolframEngine/Licensing && \
26-
cp /run/secrets/mathpass /tmp/home/.WolframEngine/Licensing/mathpass
27-
17+
FROM base AS with-license
18+
COPY ./dist/LICENCE.txt /home/wolframengine/.WolframEngine/Licensing/mathpass
2819

29-
RUN apt-get update && apt-get install -y \
30-
netcat \
31-
&& rm -rf /var/lib/apt/lists/*
20+
FROM base AS without-license
21+
# no COPY, no error
3222

33-
COPY ./entrypoint.sh /entrypoint.sh
23+
# Choose final stage with build arg
24+
ARG WITH_LICENSE=false
25+
FROM ${WITH_LICENSE:+with-license}${WITH_LICENSE:-without-license}

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"EvaluationFunctionName": ""
2+
"EvaluationFunctionName": "wolframEvaluationFunction"
33
}

evaluation_function.wl

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(* The basic evaluation function code*)
44

55
equalQNumeric[answer_, response_, params_] := Module[{tolerance},
6+
Print["Evaluating Equal Numeric"];
67
tolerance = If[Lookup[params, "tolerance_is_absolute", False],
78
Lookup[params, "tolerance", 0],
89
Lookup[params, "tolerance", 0] * answer
@@ -15,6 +16,7 @@ equalQNumeric[answer_, response_, params_] := Module[{tolerance},
1516
]
1617

1718
equalQOther[answer_, response_, params_] := Module[{correctQ},
19+
Print["Evaluating Equal Other"];
1820
<|
1921
"error" -> Null,
2022
"is_correct" -> TrueQ[answer == response]
@@ -111,11 +113,13 @@ StructureMatchQ[response_, answerTemplate_, namedVariables_,
111113
Atomic -> OptionValue[Atomic]]]]
112114

113115
equalQStructure[answer_, response_, params_] := Module[{namedVariables,correctQ},
116+
Print["Evaluating Structure"];
114117
namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm];
115118
correctQ = StructureMatchQ[
116119
ToExpression[ToString[response],TraditionalForm],
117120
ToExpression[ToString[answer],TraditionalForm],
118121
namedVariables];
122+
119123
<|
120124
"error" -> Null,
121125
"is_correct" -> correctQ
@@ -124,9 +128,9 @@ equalQStructure[answer_, response_, params_] := Module[{namedVariables,correctQ}
124128

125129
(* The evaluation function itself *)
126130

127-
evalQ[answer_, response_, params_] := Module[{},
131+
evalQ[type_, answer_, response_, params_] := Module[{},
128132
Which[
129-
Lookup[params,"equality_test","None"] == "structure",
133+
type == "structure",
130134
equalQStructure[answer,response,params],
131135
NumericQ[answer],
132136
equalQNumeric[answer, response, params],
@@ -135,14 +139,41 @@ evalQ[answer_, response_, params_] := Module[{},
135139
]
136140
];
137141

138-
EvaluationFunction[answer_, response_, params_] := Module[{tolerance, correctQ, error},
139-
result = evalQ[answer, response, params];
140-
<|
141-
"is_correct" -> result["is_correct"],
142-
"feedback" -> If[result["is_correct"],
142+
EvaluationFunction[type_, answer_, response_, params_] := Module[{tolerance, correctQ, error},
143+
Print["Running Evaluation Function"];
144+
result = evalQ[type, answer, response, params];
145+
Print["Results"];
146+
Print[result];
147+
feedback = If[result["is_correct"],
143148
Lookup[params, "correct_response_feedback", "Correct!"],
144149
Lookup[params, "incorrect_response_feedback", "Incorrect!"]
145-
],
146-
"error" -> result["error"]
150+
];
151+
<|
152+
"command" -> "eval",
153+
"result" -> <|
154+
"is_correct" -> result["is_correct"],
155+
"feedback" -> feedback,
156+
"error" -> result["error"]
157+
|>
147158
|>
148159
];
160+
161+
evalQuestionIO = Function[
162+
Module[{jsonData, result},
163+
jsonData = Import[#1, "JSON"] //. List :> Association;
164+
requestData = jsonData["params"];
165+
answer = requestData["answer"];
166+
response = requestData["response"];
167+
params = requestData["params"];
168+
type = params["comparisonType"];
169+
Print["Evaluating Response Against Answer"];
170+
result = EvaluationFunction[type, answer, response, params];
171+
Print["Response"];
172+
Print[result];
173+
Export[#2, result, "JSON", "Compact" -> True]
174+
]
175+
];
176+
177+
argv = Rest[$ScriptCommandLine];
178+
evalQuestionIO[argv[[1]], argv[[2]]]
179+

structure_match_example1.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
2-
"comparisonType":"structure",
3-
"answerTemplate":"Sin[p x + q]",
2+
"method": "eval",
3+
"params": {
4+
"answer":"Sin[p x + q]",
45
"response":"Sin[a x + b]",
56
"params":{
7+
"comparisonType":"structure",
68
"named_variables":"{x}",
79
"correct_response_feedback":"Your answer is correct!",
810
"incorrect_response_feedback":"Your answer is incorrect!"
911
}
10-
}
12+
}
13+
}

0 commit comments

Comments
 (0)