Skip to main content

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

Metadata

Release files for karel-for-synthesis 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for karel-for-synthesis 1.4.0
File Size Uploaded
karel-for-synthesis-1.4.0.tar.gz 40.1 kB Details

Release files / karel-for-synthesis-1.4.0.tar.gz

Download URL karel-for-synthesis-1.4.0.tar.gz
Size 40.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a536c531121f341799dd377e6214c7b4915e001eae7211352cc2d8de44ddaa19
BLAKE2b-256 checksum
How to use checksums
01b43033b3f26df178e7843ba15ff681e917d41724d29eeb49d741ce0f1eaad6
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.4.0 This release

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page