No project description provided
Project description
Stitch Bindings
Dec 6: Bindings are being renovated for useability and will be available within a week!
This repo provides Python bindings to stitch. At some point, stitch bindings will be published to pip, but in the mean time the instructions below allow for building the latest version of stitch from the GitHub repo (or any desired branch/commit). The goal for the stitch interface is to be nearly identical to running stitch in the commandline with cargo run --release --bin=compress
, by exposing the function stitch.compression(programs,args)
where programs
is a list of programs (as strings) and args
is a string containing commandline arguments, like "--max-arity=3 --iterations=3"
.
Using a specific version of stitch
By default, the following instructions will build the latest version of stitch on the main
branch of the stitch repo. To build the bindings for a specific commit, replace the following line in Cargo.toml
:
stitch_core = { git = "https://github.com/mlb2251/stitch", branch = "main"}
with the following (replacing the SHA with the desired commit SHA):
stitch_core = { git = "https://github.com/mlb2251/stitch", rev = "058890ecc3c3137c5105d673979304edfb0ab333"}
Building the bindings
PYO3_PYTHON=python3.8 make osx
make linux
is also supported. Adjust the PYO3_PYTHON
variable to be whichever python interpreter you would like to compile for. It will default to python3
if you don't set it.
To use the bindings, open a new python interpreter and run the following:
import sys, os, json
# First add the bindings to your PYTHONPATH - you can do this by adding `export PYTHONPATH="$PYTHONPATH:path/to/stitch_bindings/bindings/"`
# to your `~/.bashrc`, `~/.zshrc`, and/or `~/.bash_profile`, or just for the current session through sys.path.append() as below:
sys.path.append(os.getcwd() + '/bindings')
# Now the following import should succeed
import stitch
# define a list of programs as a list of strings - see the stitch documentation for supported program formats
programs = ["(a a a)", "(b b b)"]
# define the arguments to stitch - these are identical to the arguments to `cargo run --release --bin=compress`
args = "--max-arity=2 --iterations=1 --silent"
# stitch.compression() will return a json-parseable string with contents identical to out/out.json that the `--bin=compress`
# usually produces. In this case, we'd expect it to find the `(#0 #0 #0)` abstraction
out_json = json.loads(stitch.compression(programs, args))
print(out_json['rewritten'])
print(out_json['abstractions'][0])
Troubleshooting
If import stitch
fails, create an issue on GitHub including your python version and OS.
Sometimes changing to a different PYO3_PYTHON
can be helpful as well.
Adding to PYTHONPATH
You can add the bindings to your PYTHONPATH by adding export PYTHONPATH="$PYTHONPATH:path/to/stitch_bindings/bindings/"
to your ~/.bashrc
, ~/.zshrc
, and/or ~/.bash_profile
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for stitch_core-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2d0a2f30f3bcdf22d8568ecf103d83c9ae9923a62b8c3d41e973c1c878967ea |
|
MD5 | 457f4a7ed2f2eba0fb08dd21351403ee |
|
BLAKE2b-256 | 1766cf0fdb157ea9f4d977082c9eaa364f58b1d266df5a7a58420dc1706bf410 |