Allow generate_xyz_hamiltonian to accept arbitrary coefficient values - #208
Open
phalakbh wants to merge 6 commits into
Open
Allow generate_xyz_hamiltonian to accept arbitrary coefficient values#208phalakbh wants to merge 6 commits into
generate_xyz_hamiltonian to accept arbitrary coefficient values#208phalakbh wants to merge 6 commits into
Conversation
…r coupling constants and external magnetic fields; add corresponding tests.
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.
Summary
This PR extends
generate_xyz_hamiltonianto accept arbitrary per-edge and per-site coefficients, replacing the previous restriction to a single uniform scalar or length-3 sequence.What changed
coupling_constantsnow accepts adict[tuple[int, int], float | Sequence[float]], mapping individual graph edges to their own(Jxx, Jyy, Jzz)triplet. Edges not present in the dict default to(0.0, 0.0, 0.0).ext_magnetic_fieldnow accepts adict[int, float | Sequence[float]], mapping individual qubit indices to their own(hx, hy, hz)triplet. Qubits not present in the dict default to(0.0, 0.0, 0.0).Both parameters remain fully backward-compatible — scalar and length-3 sequence inputs continue to work as before (uniform application across all edges/qubits).
Validation added
_validate_xyz_input— rejects non-dict sequences whose length ≠ 3 before normalization_validate_edge_dict_keys— rejects dict keys that are not (int, int) tuples_normalize_edge_key— canonicalises (i, j) / (j, i) so both orderings resolve to the same edge; raises on malformed keys_normalize_coupling_constants— raises on conflicting values for the same canonical edge (e.g. both (0, 1) and (1, 0) supplied with different coefficients)_normalize_ext_magnetic_field— raises if dict keys are not integersAll reachable
ValueErrorpaths are documented in the Raises section of the public docstring.Tests
Unit tests cover:
Fixes #34