Python interface for cpp-pd-code-simplify with runtime C++ compilation.
Project description
cpp-pd-code-simplify-interface
cpp-pd-code-simplify-interface is a Python package for calling the
cpp-pd-code-simplify C++ implementation from Python.
The package is designed for PyPI distribution:
pip install cpp-pd-code-simplify-interface
It ships the C++ source code inside the wheel and source distribution. On first
use, the package compiles a cached local dynamic library through
cpp-simple-interface; later calls reuse that library through ctypes. A C++14
compiler compatible with g++ must be available at runtime.
Runtime dependencies are handled per platform. On Windows, the interface uses
objdump -p or dumpbin /DEPENDENTS when available, then caches MinGW runtime
DLLs such as libstdc++-6.dll, libgcc_s_*.dll, and libwinpthread-1.dll
next to the generated DLL. On Linux it adds $ORIGIN rpath and can inspect
ldd; on macOS it adds @loader_path rpath and can inspect otool -L. Load
failures are wrapped with platform-specific dependency hints.
The core C++ source and header are not stored as permanent generated copies in
this subproject. The custom Poetry build backend syncs them from the repository
root during poetry build, embeds them in the wheel and sdist, then removes the
temporary copies from the working tree.
Calls use the C++ library's default preprocessing pipeline: R1-move removal followed by nugatory-crossing removal, then iterative mid-simplification.
Example
import cpp_pd_code_simplify_interface as simplify
pd_code = "PD[X[1,5,2,4],X[3,1,4,6],X[5,3,6,2]]"
result = simplify.simplify(pd_code)
print(result["final_pd_code"])
Returned final_pd_code strings are normalized for display: each crossing is
written from the under-incoming edge, labels are renumbered along oriented
components from 1, and crossing rows are sorted lexicographically. This is
applied only at the final JSON boundary; the C++ backend keeps its internal
numbering unchanged while simplifying.
The default max_paths=-1 uses deterministic heuristic green-path sampling in
the C++ backend. Use ban_heuristic=True to request exhaustive green-path
enumeration for a manageable input. Use reduction_round=K to cap applied
mid-simplification rounds; the default -1 runs until stable. Use
timeout=K to cap a call at K seconds; the default -1 has no timeout. Use
verbose=True to forward timestamped C++ progress logs to stderr. If a call
times out, the returned dictionary still contains the best PD code found so far
and sets timed_out to True. Verbose log lines use local wall-clock time in
YYYY-MM-DD HH:MM:SS format. When max_thread=-1 reaches a brute-force search
phase, verbose logs also include actual_threads, the worker count selected by
the C++ backend for that phase. The backend call runs in a helper process, so
Ctrl+C can terminate active C++ work and its worker threads cleanly.
Use show_step_pd=True, or CLI flag --show-step-pd, to print
step_pd_code[ROUND]: PD[...] to stdout after each mid-simplification witness
is applied and before that round's automatic R1/nugatory cleanup.
Batch use:
results = simplify.simplify_many([pd_code, "PD[]"])
To select a compiler:
CXX=clang++ python your_script.py
Windows PowerShell:
$env:CXX = "C:\path\to\g++.exe"
python your_script.py
On Windows, use a compiler whose target architecture matches Python. A 64-bit Python process needs a 64-bit compiler target.
Command-line use also supports multi-line PD-code files:
python -m cpp_pd_code_simplify_interface --pd-file inputs.pd --max-paths -1 --verbose
Build And Publish
From this directory:
poetry build
poetry publish
Use poetry publish --build to build and upload in one command.
For local testing:
poetry run python -m cpp_pd_code_simplify_interface "PD[]"
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cpp_pd_code_simplify_interface-0.1.15.tar.gz.
File metadata
- Download URL: cpp_pd_code_simplify_interface-0.1.15.tar.gz
- Upload date:
- Size: 33.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a09ce7eb27f7933b16e9ddf0670dba386a0546a2e929238bf398f497394be6d
|
|
| MD5 |
9c9ca762a679b48dd33000cfa5c1253d
|
|
| BLAKE2b-256 |
d9fea4427a5989cace02c8d19323897cd96fdf1e2fcd14ee5a00ee2e943c0cbf
|
File details
Details for the file cpp_pd_code_simplify_interface-0.1.15-py3-none-any.whl.
File metadata
- Download URL: cpp_pd_code_simplify_interface-0.1.15-py3-none-any.whl
- Upload date:
- Size: 35.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e33a8796a470ff75947c23f8d43838bdcc5475f39ac64ad1671b02bef9ee4595
|
|
| MD5 |
01c04e83f2d2bc039269cdb7d1ecd4f4
|
|
| BLAKE2b-256 |
186fed8f1d5b96e34571c0d89795f52680c0421aac4d11d562249c222cdcc514
|