Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest AS final

# Use the WSTP server as a kernel backend
ENV WSTP_SERVER="true"
FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest as base

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

ENV LOG_LEVEL="DEBUG"

# Copy the evaluation function to the app directory
COPY ./evaluation_function.wl /app/evaluation_function.wl

# Final layer for private images, which contains the wolfram licence key,
# and is started with the shimmy handle command.
FROM final AS final-private

# Copy the mathpass secret to the Wolfram Engine licensing directory.
# See https://hub.docker.com/r/wolframresearch/wolframengine for more information.
RUN --mount=type=secret,id=mathpass \
mkdir -p /tmp/home/.WolframEngine/Licensing && \
cp /run/secrets/mathpass /tmp/home/.WolframEngine/Licensing/mathpass

FROM base AS with-license
COPY ./dist/LICENCE.txt /home/wolframengine/.WolframEngine/Licensing/mathpass

RUN apt-get update && apt-get install -y \
netcat \
&& rm -rf /var/lib/apt/lists/*
FROM base AS without-license
# no COPY, no error

COPY ./entrypoint.sh /entrypoint.sh
# Choose final stage with build arg
ARG WITH_LICENSE=false
FROM ${WITH_LICENSE:+with-license}${WITH_LICENSE:-without-license}
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"EvaluationFunctionName": ""
"EvaluationFunctionName": "wolframEvaluationFunction"
}
49 changes: 40 additions & 9 deletions evaluation_function.wl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(* The basic evaluation function code*)

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

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

equalQStructure[answer_, response_, params_] := Module[{namedVariables,correctQ},
Print["Evaluating Structure"];
namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm];
correctQ = StructureMatchQ[
ToExpression[ToString[response],TraditionalForm],
ToExpression[ToString[answer],TraditionalForm],
namedVariables];

<|
"error" -> Null,
"is_correct" -> correctQ
Expand All @@ -124,9 +128,9 @@ equalQStructure[answer_, response_, params_] := Module[{namedVariables,correctQ}

(* The evaluation function itself *)

evalQ[answer_, response_, params_] := Module[{},
evalQ[type_, answer_, response_, params_] := Module[{},
Which[
Lookup[params,"equality_test","None"] == "structure",
type == "structure",
equalQStructure[answer,response,params],
NumericQ[answer],
equalQNumeric[answer, response, params],
Expand All @@ -135,14 +139,41 @@ evalQ[answer_, response_, params_] := Module[{},
]
];

EvaluationFunction[answer_, response_, params_] := Module[{tolerance, correctQ, error},
result = evalQ[answer, response, params];
<|
"is_correct" -> result["is_correct"],
"feedback" -> If[result["is_correct"],
EvaluationFunction[type_, answer_, response_, params_] := Module[{tolerance, correctQ, error},
Print["Running Evaluation Function"];
result = evalQ[type, answer, response, params];
Print["Results"];
Print[result];
feedback = If[result["is_correct"],
Lookup[params, "correct_response_feedback", "Correct!"],
Lookup[params, "incorrect_response_feedback", "Incorrect!"]
],
"error" -> result["error"]
];
<|
"command" -> "eval",
"result" -> <|
"is_correct" -> result["is_correct"],
"feedback" -> feedback,
"error" -> result["error"]
|>
|>
];

evalQuestionIO = Function[
Module[{jsonData, result},
jsonData = Import[#1, "JSON"] //. List :> Association;
requestData = jsonData["params"];
answer = requestData["answer"];
response = requestData["response"];
params = requestData["params"];
type = params["comparisonType"];
Print["Evaluating Response Against Answer"];
result = EvaluationFunction[type, answer, response, params];
Print["Response"];
Print[result];
Export[#2, result, "JSON", "Compact" -> True]
]
];

argv = Rest[$ScriptCommandLine];
evalQuestionIO[argv[[1]], argv[[2]]]

9 changes: 6 additions & 3 deletions structure_match_example1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"comparisonType":"structure",
"answerTemplate":"Sin[p x + q]",
"method": "eval",
"params": {
"answer":"Sin[p x + q]",
"response":"Sin[a x + b]",
"params":{
"comparisonType":"structure",
"named_variables":"{x}",
"correct_response_feedback":"Your answer is correct!",
"incorrect_response_feedback":"Your answer is incorrect!"
}
}
}
}
Loading