Skip to content

Msparse everywhere - #217

Merged
MIWdlB merged 3 commits into
mainfrom
msparse-everywhere
Aug 10, 2026
Merged

Msparse everywhere#217
MIWdlB merged 3 commits into
mainfrom
msparse-everywhere

Conversation

@MIWdlB

@MIWdlB MIWdlB commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Some functions forgotten in #216 , and deleting a confusingly similar to_sparse_majorana which I had forgotten about .

MIWdlB and others added 2 commits August 10, 2026 14:01
Remove the duplicate `to_sparse_majorana()` method and add `to_dict()` to
`PyMajoranaSparse` to provide the same dict-like functionality. This simplifies
the API by having a single conversion method that can return either the
structured `PyMajoranaSparse` object or a dict via `.to_dict()`.

- Remove `to_sparse_majorana()` from FermionHamiltonian
- Add `to_dict()` method to PyMajoranaSparse that returns simplified terms
- Update test callers to use `to_majorana_sparse().to_dict()`
- Update comment in functions.rs to reference new method

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…ethods

Widens MajoranaEncoding.encode_annealed, .anneal_enumeration,
.batch_pauli_weights, the hatt and encode_topphatt module functions, and
their Python wrappers (TernaryTree.encode_annealed/.topphatt/.encode,
hamiltonian_adaptive_ternary_tree) to accept a MajoranaSparse directly,
matching the pattern already used by MajoranaEncoding.encode (#216).

Also fixes TernaryTree.encode, whose type hint already claimed to accept
MajoranaSparse but would raise a TypeError at the pyo3 boundary since
encode_topphatt only accepted FermionHamiltonian.

PyMajoranaSparse now carries the source Hamiltonian's n_modes, since the
core MajoranaSparse type has no mode count of its own and several of these
methods need one to compute defaults (temperature, n_modes). This also lets
the ad-hoc index-range scan in MajoranaEncoding.encode be replaced with a
direct mode-count comparison, mirroring the check already used for
FermionHamiltonian inputs.

Also removes the to_sparse_majorana stub left behind in core.pyi from the
prior consolidation onto to_majorana_sparse, and adds the missing to_dict
stub for MajoranaSparse.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@codspeed-hq

codspeed-hq Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 56 untouched benchmarks
⏩ 100 skipped benchmarks1


Comparing msparse-everywhere (bfad5f2) with main (b6bc7ef)2

Open in CodSpeed

Footnotes

  1. 100 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (28c8c0b) during the generation of this report, so b6bc7ef was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@MIWdlB
MIWdlB merged commit 58977b1 into main Aug 10, 2026
3 of 4 checks passed
@MIWdlB
MIWdlB deleted the msparse-everywhere branch August 10, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant