Generic Encode and API Update - #194
Merged
Merged
Conversation
- New ferrmion_core::hamiltonians::FermionHamiltonian aggregating FermionMatrix terms with a constant energy offset, converting to MajoranaSparse via the existing FermionSparse chain. - FermionMatrix gains Clone/Debug/PartialEq and signature/action/ coefficients/n_modes accessors. - MajoranaEncoding gains Clone and PartialEq for use in pyclass wrappers. - SymplecticMatrix::to_concatenated() for the [x|z] numpy layout. - Fix missing Clifford import in pauli.rs (pre-existing build breakage). https://claude.ai/code/session_01NYJx6y4n3rdbAgjEuVmM56
Replace the duplicated Python type layer with PyO3 pyclass wrappers over the ferrmion-core types: - New QubitHamiltonian pyclass (mapping protocol, pauli weights, clifford_heuristic / randomised_subsystem_descent methods, pickling). - New FermionHamiltonian pyclass (fluent builder, terms dict, sparse Majorana conversion, pickling). - New frozen MajoranaEncoding pyclass with factory staticmethods (jordan_wigner/bravyi_kitaev/parity/jkmn/maxnto/from_flatpack/from_json) and encode/encode_annealed/anneal_enumeration/decode/hartree_fock_state/ operator-construction/batch_pauli_weights/apply_mode_enumeration methods. - src/lib.rs split into error.rs, hamiltonians.rs, encoding.rs and functions.rs; module registration only in lib.rs. - Superseded loose core functions removed; hatt/topphatt/encode_topphatt now take FermionHamiltonian and return encoding pyclasses. - Python package migrated: encode/base.py and encode/maxnto.py deleted, TernaryTree is now a pure builder with build_encoding(), factories return MajoranaEncoding, qiskit/visualise/optimize consumers updated, core.pyi stubs rewritten. https://claude.ai/code/session_01NYJx6y4n3rdbAgjEuVmM56
- tests/test_base_encoding.py replaced by tests/test_majorana_encoding.py exercising the MajoranaEncoding/QubitHamiltonian/FermionHamiltonian pyclasses directly (constructor validation, JSON and pickle round-trips, mapping protocol, operator construction, mode-enumeration permutations). - Remaining test files migrated off the removed core functions: encode/batch_pauli_weights/anneal_enumerations/encode_standard/ maxnto_symplectic_matrix/flatpack_symplectic_matrix/ fermionic_to_sparse_majorana all replaced by class methods; tree-based tests use the TernaryTree classmethod constructors. - CHANGELOG.md documents the new classes and all breaking changes. - Fix pre-existing clippy/bench breakage (module_inception allow, double unwrap in decode bench) and apply cargo fmt/ruff format. https://claude.ai/code/session_01NYJx6y4n3rdbAgjEuVmM56
Update the tutorial notebooks and nbutils.py helper for the new Rust-backed classes (code cells only; notebooks are not re-executed and stored outputs are kept, as docs builds use nb_execution_mode='off'): - Tree-building call sites switch from the encoding factories to the TernaryTree classmethods (jordan_wigner/bravyi_kitaev/parity/jkmn) wherever the object is drawn, given an enumeration scheme, or run through TOPP-HATT. - encode_annealed/encode_topphatt results unpacked as (QubitHamiltonian, MajoranaEncoding) tuples; clifford_heuristic's get_ch_results threads the TOPP-HATT-optimised encoding through the downstream comparisons instead of relying on in-place mutation. - MajoranaStringEncoding JSON round-trip replaced with MajoranaEncoding.to_json/from_json, saving the annealed encoding that is actually compared (fixes the stored-error cell, output cleared). - fermionic_to_sparse_majorana calls replaced with FermionHamiltonian(...).to_sparse_majorana(); _terms -> terms; private _build_symplectic_matrix/_batch_pauli_weights/ _encode_fermion_product usages replaced with the public equivalents, generating explicit random permutations for batch weights. https://claude.ai/code/session_01NYJx6y4n3rdbAgjEuVmM56
PyO3 converts Vec<u8> to Python bytes, so the ipowers entry was not a list and the dict was not JSON-serialisable. Widen to u32 before conversion so a list of ints is produced, and extend the round-trip test to assert list types and a full json.dumps/json.loads cycle. https://claude.ai/code/session_01NYJx6y4n3rdbAgjEuVmM56
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
MIWdlB
force-pushed
the
python-api
branch
2 times, most recently
from
June 11, 2026 12:52
4b9f12a to
ec0a929
Compare
Contributor
MIWdlB
force-pushed
the
python-api
branch
2 times, most recently
from
June 11, 2026 13:46
85f649b to
b3c769f
Compare
This was referenced Jun 11, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Update to the python and rust APIs. Diff looks big but it's mostly moving and deleting files, creating wrappers and re-running notebooks.
Makes the
Encodetrait generic over output type by introducing the idea of spaces as marker traits. This should make it possible to generically define encodings from fermionic inputs to qubit outputs.Moves
QubitHamiltonian,FermionHamiltonianandMajoranaEncodingto bepyclasspyo3 wrappers.The significant difference in terms of user experience, is that TernaryTree is now a builder for MajoranaEncoding rather than a subclass, which was an early choice to simplify things for myself and not the best model.