You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recodex-wiki/Assignments-overview.md

320 lines
17 KiB
Markdown

# Assignments overview
Assignments are programming tasks that can be tested by a worker after a user
submits their solution. An assignment is described by a YAML file that contains information on how to
build, run and test it.
### Terminology
Following text requires knowledge of basic terminology used by ReCodEx. Please, check [separate page](Terminology).
### Basics
Job is a set/list of tasks (it is generally a set, but order of tasks have some meaning). These tasks may have dependencies (arbitrary number), which needs to be observed. When recodex-worker processes job, it creates a task graph, where tasks are vertices and dependencies are edges (A -> B means that the task A is on the dependency list of task B) and creates its linear ordering. The graph must be acyclic (otherwise linear ordering will not exist) and the recodex-worker attempts to execute maximal number of tasks possible. Tasks without dependencies can be executed directly, other tasks are executed when all their dependencies have been successfully completed.
Tasks are executed sequentially -- by the linear ordering of the task graph. Parallel tasks (tasks, which are not directly dependent and thus their linear ordering may be arbitrary) are ordered first by their priority (higher number => higher priority) and second by their order in the configuration file. Priority is important for specifying evaluation flow. See sample picture for better understanding.
![Picture of task serialization](https://github.com/ReCodEx/GlobalWiki/raw/master/images/Assignment_overview.png)
Each task has a unique ID (alphanum string like _CompileA_, _RunAA_, or _JudgeAB_ in the picture). These IDs are used to identify tasks (for dependency references, in the log, ...). Numbers in bottom right corner are priorities of each task. Higher number is greater priority. It means, that if task _RunAA_ is done, next must be _JudgeAA_ and not _RunAB_ (that will be also valid linear ordering, but _RunAB_ has lower priority).
### Task
Task is an atomic piece of work executed by recodex-worker. There are two basic types of tasks:
- **Execute external process** (optionally inside Isolate). Linux default will be mandatory in Isolate, this option is here because of Windows.
- **Perform internal operation**. External processes are meant for compilation, testing, or execution of external judges. Internal operations comprise commands, which are typically related to file/directory maintenance and other evaluation management stuff. Few important examples:
- Create/delete/move/rename file/directory
- (un)zip/tar/gzip/bzip file(s)
- fetch a file from the file repository (either from worker cache or download it by HTTP GET or through SFTP).
Even though the internal operations may be handled by external executables (`mv`, `tar`, `pkzip`, `wget`, ...), it might be better to keep them inside the recodex-worker as it would simplify these operations and their portability among platforms. Furthermore, it is quite easy to implement them using common libraries (e.g., _zlib_, _curl_).
**External Tasks**
These tasks are typically executed in isolate (with given parameters) and the recodex-worker waits until they finish. The exit code determines, whether the task succeeded (0) or failed (anything else). A task may be marked as essential; in such case, failure will immediately cause termination of the whole job.
- **stdin** - can be configured to read from existing file or from /dev/null.
- **stdout** and **stderr** - can be individually redirected to a file or discarded. If this output options are specified, than it is possible to upload output files with results by copying them in result directory.
- **limits** - task have time and memory limits; if these limits are exceeded, the task also fails.
The task results (exit code, time, and memory consumption, etc.) are saved into result yaml file and eventually sent back to frontend application to address which was specified on input.
### Directories and Files
For each job execution unique directory structure is created. Job is not restricted to specified directories (tasks can do whatever is allowed on system), but it is advised to use them inside job. In recodex-worker configuration one can specify worker default directory, this is base of every file which is produced by recodex-worker.
Inside this directory temporary files for job execution are created:
- **${DEFAULT}/downloads/${WORKER_ID}/${JOB_ID}** - where the downloaded archive is saved
- **${DEFAULT}/submission/${WORKER_ID}/${JOB_ID}** - decompressed submission is stored here
- **${DEFAULT}/eval/${WORKER_ID}/${JOB_ID}** - this directory is accessible in job configuration using variables and all execution should happen here
- **${DEFAULT}/temp/${WORKER_ID}/${JOB_ID}** - directory where all sort of temporary files can be stored
- **${DEFAULT}/results/${WORKER_ID}/${JOB_ID}** - again accessible directory from job configuration which is used to store all files which will be upload on fileserver, usually there will be only yaml result file and optionally log, every other file has to be copied here explicitly from job
### Configuration
Configuration of the job which is passed to worker is generated from two parts:
- **template** - Common template for similar kinds of tasks. Contains allmost all instructions - when fetch, move, rename files, run commands, judges, ..., task dependencies and priorities. This template can be shared by more problem assignments or every problem (probably in compiller class) can have different one.
- **recodex-worker config** - includes data for instancioning the template, e.q. input file names, ...
Final configuration for worker is computer generated from those two configs.
Job configuration consist of some general information and then from list of tasks (one or more)
#### Configuration items
If not specified otherwise than its mandatory item! Mandatory items are bold, optional italic.
- **submission** - information about this particular submission
- **job-id** - textual ID which should unique in whole recodex
- **language** - no specific function, just for debugging and clarity
- **file-collector** - address from which fetch tasks will download data
- _log_ - default is false, can be omitted, determines whether job execution will be logged into one shared log
- **tasks** - list (not map) of individual tasks
- **task-id** - unique indetifier of task in scope of one submission
- **priority** - higher number, higher priority
- **fatal-failure** - if true, than execution of whole job will be stopped after failing of this one
- **dependencies** - list of dependencies which have to be fulfilled before this task, can be omitted if there is no dependencies
- **cmd** - description of command which will be executed
- **bin** - the binary itself
- _args_ - list of arguments which will be sent into execution unit
- _sandbox_ - wrapper for external tasks which will run in sandbox, if defined task is automatically external
- **name** - name of used sandbox
- _stdin_ - file to which standard input will be redirected, can be omitted
- _stdout_ - file to which standard output will be redirected, can be omitted
- _stderr_ - file to which error output will be redirected, can be omitted
- **limits** - list of limits which can be passed to sandbox
- **hw-group-id** - determines specific limits for specific machines
- _time_ - time of execution in second
- _wall-time_ - wall time in seconds
- _extra-time_ - extra time which will be added to execution
- _stack-size_ - size of stack of executed program in kilobytes
- _memory_ - overall memory limit for application in kilobytes
- _parallel_ - integral number of processes which can run simultaneously, time and memory limits are merged from all potential processes/threads
- _disk-size_ - size of all io operations from/to files in kilobytes
- _disk-files_ - number of files which can be opened
- _environ-variable_ - wrapper for map of environmental variables, union with default worker configuration
- _chdir_ - this will be working directory of executed application
- _bound-directories_ - list of structures reprezenting directories which will be visible inside sandbox, union with default worker configuration
- **src** - source pointing to actual system directory
- **dst** - destination inside sandbox which can have its own filesystem binding
- **mode** - determines connection mode of specified directory, one of values: RW, NOEXEC, FS, MAYBE, DEV
#### Configuration example
This configuration example is written in YAML and serves only for demostration purposes. Therefore it is not working example which can be used in real traffic. Some items can be omitted and defaults will be used.
```{.yml}
--- # only one document which contains job, aka. list of tasks and some general infos
submission: # happy hippoes fence
job-id: hippoes
language: c
file-collector: http://localhost:9999/tasks
log: true
tasks:
- task-id: "compilation"
priority: 2
fatal-failure: true
cmd:
bin: "/usr/bin/gcc"
args:
- "solution.c"
- "-o"
- "a.out"
sandbox:
name: "isolate"
limits:
- hw-group-id: group1
parallel: 0
chdir: ${EVAL_DIR}
bound-directories:
- src: ${SOURCE_DIR}
dst: ${EVAL_DIR}
mode: RW
- task-id: "fetch_test_1"
priority: 4
fatal-failure: false
dependencies:
- compilation
cmd:
bin: "fetch"
args:
- "1.in"
- "${SOURCE_DIR}/kuly.in"
- task-id: "evaluation_test_1"
priority: 5
fatal-failure: false
dependencies:
- fetch_test_1
cmd:
bin: "a.out"
sandbox:
name: "isolate"
limits:
- hw-group-id: group1
time: 0.5
memory: 8192
chdir: ${EVAL_DIR}
bound-directories:
- src: ${SOURCE_DIR}
dst: ${EVAL_DIR}
mode: RW
- task-id: "fetch_test_solution_1"
priority: 6
fatal-failure: false
dependencies:
- evaluation_test_1
cmd:
bin: "fetch"
args:
- "1.out"
- "${SOURCE_DIR}/1.out"
- task-id: "judging_test_1"
priority: 7
fatal-failure: false
dependencies:
- fetch_test_solution_1
cmd:
bin: "${JUDGES_DIR}/recodex-judge-normal"
args:
- "1.out"
- "plot.out"
sandbox:
name: "isolate"
limits:
- hw-group-id: group1
parallel: 0
chdir: ${EVAL_DIR}
bound-directories:
- src: ${SOURCE_DIR}
dst: ${EVAL_DIR}
mode: RW
- task-id: "rm_junk_test_1"
priority: 8
fatal-failure: false
dependencies:
- judging_test_1
cmd:
bin: "rm"
args:
- "${SOURCE_DIR}/kuly.in"
- "${SOURCE_DIR}/plot.out"
- "${SOURCE_DIR}/1.out"
...
```
### Job variables
Because frontend does not know which worker gets the job, its necessary to be a little general in configuration file. This means that some worker specific things has to be transparent. Good example of this is directories, which can be placed whenever worker wants. In case of this variables were established. There are of course some restrictions where variables can be used. Basically whenever filesystem paths can be used, variables can be used.
Usage of variables in configuration is then simple and kind of shell-like. Name of variable is put inside braces which are preceded with dollar sign. Real usage is than something like this: ${VAR}. There should be no quotes or apostrophies around variable name, just simple text in braces. Parsing is simple and whenever there is dollar sign with braces job execution unit automatically assumes that this is a variable, so there is no chance to have this kind of substring.
List of usable variables in job configuration:
- **WORKER_ID** - integral identification of worker, unique on server
- **JOB_ID** - identification of this job
- **SOURCE_DIR** - directory where source codes of job are stored
- **EVAL_DIR** - evaluation directory which should point inside sandbox. Note, that some existing directory must be bound inside sanbox under **EVAL_DIR** name using _bound-directories_ directive inside limits section.
- **RESULT_DIR** - results from job can be copied here, but only with internal task
- **TEMP_DIR** - general temp directory which is not dependent on operating system
- **JUDGES_DIR** - directory in which judges are stored (outside sandbox)
## Results
Results of tasks are sent back in YAML format compressed into archive. This archive can contain further files, such as job logging information and files which were explicitly copied into results directory.
Results file contains job identification and results of individual tasks.
### Results items
Mandatory items are bold, optional italic.
- **job-id** - identification of job to which this results belongs
- **results** - list of tasks results
- **task-id** - unique identification of task in scope of this job
- **status** - three states: OK, FAILED, SKIPPED
- _error_message_ - defined only in internal tasks on failure
- _sandbox_results_ - if defined than this task was external and was run in sandbox
- **exitcode** - integer which executed program gave on exit
- **time** - time in seconds in which program exited
- **wall-time** - wall time in seconds
- **memory** - how much memory program used in kilobytes
- **max-rss** - maximum resident set size used in kilobytes
- **status** - two letter status code: OK, RE, SG, TO, XX
- **exitsig** - description of exit signal
- **killed** - boolean determining if program exited correctly or was killed
- **message** - status message on failure
### Example result file
```{.yml}
--- # only one document which contains list of results
job-id: 5
results:
- task-id: compile1
status: OK # OK, FAILED, SKIPPED
sandbox_results:
exitcode: 0
time: 5 # in seconds
wall-time: 5 # in seconds
memory: 50000 # in KB
max-rss: 50000
status: RE # two letter status code: OK, RE, SG, TO, XX
exitsig: 1
killed: true
message: "Time limit exceeded" # status message
- task-id: eval1
status: FAILED
error_message: "Task failed, something very bad happend!"
.
.
.
...
```
### Logs
During execution tasks can use only one shared log. There is no use for multiple logs which will be used in all tasks, because of pretty small amount of information which is loged. Log is in default disabled and can be enabled in job configuration, then all logged actions in tasks will be visible here.
After execution is log packed and sent back to fileserver where can be further processed.
## Case study
We present some of the courses that might use ReCodEx to evaluate homework
assignments and outline the setup of the evaluation with respect to the concept
of stages.
### Simple programming exercises
For example introductory programming courses such as Programming I or Java
programming.
In the simplest case we only need one stage that builds the program and passes
the test inputs to its standard input. We will use the C language for this
example. The build command is `gcc source.c`, the test command is `./a.out`.
### Compiler principles
This course uses multiple tools in a pipeline-like fashion - for example `flex`
and `bison`.
We create a stage for each of the steps of this pipeline - we run flex and test
the output, then we run bison and do the same.
### XML technologies
In this course, students choose a topic they model using XML - for example a
library or a bulletin board. During the semester, they expand this project by
adding XSLT transformations, XQuery scripts, XPath queries, etc. These are
tested against fixed requirements (e.g. using some particular language
constructs).
This course already has a rather sophisticated application for testing homework
assignments, so we only include it for demonstration purposes.
Because every assignment focuses on a different technology, we would need a new
type of stage for each one. These stages would only run some checker programs
against the submitted sources (and possibly try to check their syntax etc.).
### Non-procedural programming
This course is different from other programming courses, because it only teaches
input/output manipulation by the end of the semester. In their assignments,
students are mostly required to write a function/predicate that behaves
according to a specification (e.g. appends an item at the end of a list).
Due to this, we need to take the function submitted by a student and combine it
with a snippet of code that reads the standard input and calls the submitted
function. This could be achieved by setting the build command.
### Operating systems
The operating systems course requires students to work on a simple OS kernel
that is then run in a MIPS simulator called `msim`. There are various tests that
check if the student's implementation of core OS mechanisms is correct. These
tests are compiled into the kernel.
Each of these tests could be represented by a stage that compiles the kernel
with the test and then runs it against different configurations of `msim`.