Skip to content

Conversation

q-inho
Copy link
Contributor

@q-inho q-inho commented Aug 7, 2025

Part of #369

Summary

This PR add support Qiskit’s PermutationGate and adds tests accordingly.

Spinless Case

For a permutation $\pi$ acting on spinless orbitals, the simulator decomposes $\pi$ into fermionic swaps and applies them sequentially.
On a computational‑basis state $|n_0 n_1 \dots n_{m-1} \rangle$ with occupations $n_i \in \lbrace 0 , 1 \rbrace$, the gate implements

$$ \hat P_{\pi}=\left(\prod_{(k,j)\in T_\pi}\hat S_{k,j}\right) $$

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.
If $\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$

$$ \hat P_{\pi} = \left(\prod_{(k,j)\in T_{\pi_alpha}}\hat S_{k,j}^\alpha\right)\left(\prod_{(k,j)\in T_{\pi_\beta}}\hat S_{k,j}^\beta\right) $$

if isinstance(op, PermutationGate):
perm = list(op.pattern)
qs = qubit_indices.copy()
for k in range(len(perm)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be improved by factoring out a generator function that yields the swap pairs of the permutation decomposition. Then this can look something like

for i, j in _decompose_permutation(perm):
    vec = _apply_swap(vec, (qs[i], qs[j]), ... )

for k in range(len(perm)):
while perm[k] != k:
j = perm[k]
vec = _apply_swap(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will introduce many "swap defect" sign fixing operations. I wonder if we can use FSWAPS instead of SWAPS, and then only fix the signs a single time at the end. Or maybe it is not straightforward ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing this out!
I have to switch the implementation to use FSWAPs for each transposition so the $−1$ on $|11\rangle$ is handled locally. So it can removes those repeated sign corrections.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's possible to use FSWAPs instead of SWAPs, then the entire permutation can actually be performed as a single orbital rotation.

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.

2 participants