Karel Parser and Executor useful for program synthesis.
Project description
Karel For Synthesis
Parser and executor for Karel. Based almost entirely on Nearai's code with some modifications.
Usage
To use the executor, run
from karel_for_synthesis import execute
result = execute(program, input_grid, record_trace=True)
You can also parse and unparse programs by using the parse
and unparse
commands.
Outputs
This will give you an ExecutionResult
object, with the following structure
ExecutionResult
.result
: the output grid, orNone
if there was an error.trace
: the output trace.None
ifrecord_trace=False
is passed.grids
: the grids at every timestep in the execution of the program.events
: a series ofKarelEvent
objects.timestep
:grids[timestep]
corresponds to the grid after this timesteptype
: the token being executedspan
:(i, j)
for the first and last tokens corresponding to this blockcond_span
:(i, j)
for the first and last tokens contained in the conditional expression if one exists orNone
otherwisecond_value
: the value of the conditional expression or number of remaining iterationssuccess
: False if the action failed or the loop repeats forever
Errors
ExecutorSyntaxException
: occurs if the program passed in has invalid syntaxExecutorRuntimeException
: occurs if the program passed in has an error in executing andrecord_trace=False
is passed
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
karel-for-synthesis-1.4.0.tar.gz
(40.1 kB
view details)
File details
Details for the file karel-for-synthesis-1.4.0.tar.gz
.
File metadata
- Download URL: karel-for-synthesis-1.4.0.tar.gz
- Upload date:
- Size: 40.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a536c531121f341799dd377e6214c7b4915e001eae7211352cc2d8de44ddaa19 |
|
MD5 | 209710d85ab9f427647489d70da85d1a |
|
BLAKE2b-256 | 01b43033b3f26df178e7843ba15ff681e917d41724d29eeb49d741ce0f1eaad6 |