Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The changes on this branch merge the old
pythoncrate into thelibcrate, so that the code that generates the Python bindings for the SDK lives alongside the code itself.The original approach to this PR was to generate a migration plan and feed it to Windsurf. That plan is the
crate-merge-plan.mdfile in this PR (which will be removed before merging). Unfortunately, applying the plan using LLMs had pretty mixed results, mostly due to the changes necessary to upgrade the PyO3 code. Regardless, the migration plan is useful for context and reference material.Currently, this PR is a work in progress; the full hierarchy from the original Python package is in place, but the following items remain to be done:
TODO)until
pyo3-opentelemetryandpyo3-tracing-subscriberhave their PyO3 code updated.#[pyclass]es fromqcs-api-client-common,and likely that package will need to update to the latest PyO3 version, too.
I'm currently wrapping these types to side-step a need to update that package as well,
which I had thought the original package was doing, until I found missing methods.
__getstate__and__setstate__that I've noted with a
TODO: picklecomment that should get the same treatment asquil-rs.Here is the "shape" of the original Python package, which this PR indends to retain:
As with the
quil-rsmerge, the Python-specific code is hidden behind apythonfeature. Whenever possible, PyO3 attributes are applied to the existing Rust code, so that it can be shared between the bindings and the main crate. When necessary, Python-specific code has been isolated to separatepythonmodules.The code in
src/python/mod.rsconfigures the package as above. The Python-specific parts of the Rust code present at the root of thesrc/directory lives in similarly-named counterparts within thesrc/python/directory, while code forqpu,qvm, etc. lives inpython.rsmodules next to the relevant submodule code. In some cases, this meant moving existing<name>.rsmodules to<name>/mod.rsto add a<name>/python.rsmodule alongside it. In most cases, the organization within the modules closely reflects to original code, which may aid in review, should you wish to compare them. I'm open to suggestions for a better organization, but this seemed most natural.Recommendations for Reviewers
You can build the install the bindings to a local virtualenv by running
maturin develop, or by usingcargo make install-python-package. I have encountered significant linking difficulties when attemptingcargo build --features=pythondirectly, butmaturin developandmaturin buildhave both worked successfully.You can also run
cargo make pytest-flow, but you should expect thepytestcommand itself to report failures, but the build should succeed. The actual failures should be due to changes in enumerations/lack of wrappers, as we had with thequil-rsmerge (There are a lot fewer of these present in this package, though!).Closes #566