-
Notifications
You must be signed in to change notification settings - Fork 34
Qiskit gates: Support PermutationGate #443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…permutation decomposition
…ing for applying permutations
|
PermutationGate now uses one pass occupation relabeling and does not call swap or fswap gates. |
python/ffsim/qiskit/sim.py
Outdated
| for src, dest in zip(qs, dests): | ||
| if (src < norb) != (dest < norb): | ||
| raise ValueError( | ||
| f"Gate of type '{op.__class__.__name__}' must be applied on " | ||
| "orbitals of the same spin." | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for src, dest in zip(qs, dests): | |
| if (src < norb) != (dest < norb): | |
| raise ValueError( | |
| f"Gate of type '{op.__class__.__name__}' must be applied on " | |
| "orbitals of the same spin." | |
| ) | |
| if any( | |
| (src < norb) != (dest < norb) for src, dest in zip(qubit_indices, dests) | |
| ): | |
| raise ValueError( | |
| f"Gate of type '{op.__class__.__name__}' must be applied on " | |
| "orbitals of the same spin." | |
| ) |
removes one level of indentation.
Also, do you mind adding a test that triggers this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test_permutation_gate_cross_spin_error to exercise the PermutationGate spin sector guard.
The test prepares a spinful Hartree–Fock state with norb=1, nelec=(1, 0), applies PermutationGate([1, 0]) to swap the alpha/beta qubits, and asserts final_state_vector raises the expected “same spin” ValueError. This directly triggers the (src < norb) != (dest < norb) condition.
However, I have concern that I created this standlone test function, and wonder whether I have better way to merge this test with other test functions.
…l spin compatibility
Co-authored-by: Kevin J. Sung <[email protected]>
… consistency in function naming
…cupations to prevent creating integers greater than 64 bits
…mutation in `_apply_permutation_gate`
|
This is the bit manipulation routine for propsoed Permutation gate implementation. Given an
then clear those bits in one shot by
which is equivalent to shift it to its destination, and accumulate by This is responsible for clear then fill to avoids write hazards and handles any pattern of For spinful case, we treat the This ensures it preserves I will summarize this explanation into docstring of |
python/ffsim/qiskit/sim.py
Outdated
| permuted_alpha = _permute_bitstrings(alpha_bits, alpha_pairs) | ||
| permuted_beta = _permute_bitstrings(beta_bits, beta_pairs) | ||
|
|
||
| combined = permuted_alpha + (permuted_beta << norb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this create integers greater than 64 bits? Either way, please add a test for a large number of bits. For example, you could create a circuit with 64 orbitals but only two electrons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this part. Thanks. However defining norb >= 64 raise PySCF's cistring NotImplementedError.
I made safer implementation that it rank the permuted alpha and beta strings separately via strings_to_addresses and recombine the sector addresses.
Also I added the test for largest bit. By defining norb=63 and nelec=(1,1), it test with 126 qubits total, split into 63-qubit spin sectors with preparing a state with one lectron in alpha and beta.
That sounds good. I some comments in the code would be helpful too. |
…pin check into the helper function
…for alpha and beta, preventing overflow in large spinful cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Part of #369
Summary
This PR add support Qiskit’s
PermutationGateand adds tests accordingly.Spinless Case
For a permutation $\pi$ acting on spinless orbitals, the simulator decomposes$\pi$ into fermionic swaps and applies them sequentially.$|n_0 n_1 \dots n_{m-1} \rangle$ with occupations $n_i \in \lbrace 0 , 1 \rbrace$ , the gate implements
On a computational‑basis state
where$T_\pi$ is any sequence of transpositions generating $\pi$ and $\hat{S}_{k,j}$ is the fermionic swap exchanging orbitals $k$ and $j$ .
Spinful Case
With spinful orbitals split into$\alpha$ and $\beta$ sectors, the simulator enforces that a permutation never mixes spins.$\pi$ separates into permutations $\pi_\alpha$ and $\pi_\beta$ acting within the $\alpha$ and $\beta$ sectors, then for a basis state $|n^\alpha; n^\beta\rangle = |n_0^\alpha \dots n_{n-1}^\alpha; n_0^\beta \dots n_{n-1}^\beta\rangle$
If