-
Notifications
You must be signed in to change notification settings - Fork 24
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
DiagonalGate, | ||
GlobalPhaseGate, | ||
Measure, | ||
PermutationGate, | ||
PhaseGate, | ||
RZGate, | ||
RZZGate, | ||
|
@@ -379,6 +380,19 @@ def _evolve_state_vector_spinless( | |
vec = _apply_iswap(vec, (i, j), norb=norb, nelec=nelec, copy=False) | ||
return states.StateVector(vec=vec, norb=norb, nelec=nelec) | ||
|
||
if isinstance(op, PermutationGate): | ||
perm = list(op.pattern) | ||
qs = qubit_indices.copy() | ||
for k in range(len(perm)): | ||
while perm[k] != k: | ||
j = perm[k] | ||
vec = _apply_swap( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for pointing this out! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
vec, (qs[k], qs[j]), norb=norb, nelec=nelec, copy=False | ||
) | ||
perm[k], perm[j] = perm[j], perm[k] | ||
qs[k], qs[j] = qs[j], qs[k] | ||
return states.StateVector(vec=vec, norb=norb, nelec=nelec) | ||
|
||
if isinstance(op, XXPlusYYGate): | ||
i, j = qubit_indices | ||
theta, beta = op.params | ||
|
@@ -715,6 +729,30 @@ def _evolve_state_vector_spinful( | |
) | ||
return states.StateVector(vec=vec, norb=norb, nelec=nelec) | ||
|
||
if isinstance(op, PermutationGate): | ||
perm = list(op.pattern) | ||
qs = qubit_indices.copy() | ||
for k in range(len(perm)): | ||
while perm[k] != k: | ||
j = perm[k] | ||
if (qs[k] < norb) != (qs[j] < norb): | ||
raise ValueError( | ||
f"Gate of type '{op.__class__.__name__}' must be applied on " | ||
"orbitals of the same spin." | ||
) | ||
spin = Spin.ALPHA if qs[k] < norb else Spin.BETA | ||
vec = _apply_swap( | ||
vec, | ||
(qs[k] % norb, qs[j] % norb), | ||
norb=norb, | ||
nelec=nelec, | ||
spin=spin, | ||
copy=False, | ||
) | ||
perm[k], perm[j] = perm[j], perm[k] | ||
qs[k], qs[j] = qs[j], qs[k] | ||
return states.StateVector(vec=vec, norb=norb, nelec=nelec) | ||
|
||
if isinstance(op, XXPlusYYGate): | ||
i, j = qubit_indices | ||
if (i < norb) != (j < 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.
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