Skip to main content

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, or None if there was an error
    • .trace: the output trace. None if record_trace=False is passed
      • .grids: the grids at every timestep in the execution of the program
      • .events: a series of KarelEvent objects
        • .timestep: grids[timestep] corresponds to the grid after this timestep
        • type: the token being executed
        • span: (i, j) for the first and last tokens corresponding to this block
        • cond_span: (i, j) for the first and last tokens contained in the conditional expression if one exists or None otherwise
        • cond_value: the value of the conditional expression or number of remaining iterations
        • success: False if the action failed or the loop repeats forever

Errors

  • ExecutorSyntaxException: occurs if the program passed in has invalid syntax
  • ExecutorRuntimeException: occurs if the program passed in has an error in executing and record_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)

Uploaded Source

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

Hashes for karel-for-synthesis-1.4.0.tar.gz
Algorithm Hash digest
SHA256 a536c531121f341799dd377e6214c7b4915e001eae7211352cc2d8de44ddaa19
MD5 209710d85ab9f427647489d70da85d1a
BLAKE2b-256 01b43033b3f26df178e7843ba15ff681e917d41724d29eeb49d741ce0f1eaad6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page