qiskit-nature
qiskit-nature copied to clipboard
Relabel indices of FermionicOp
What should we add?
FermionicOp should support relabeling its indices according to a permutation. This is useful for performing fermionic swaps virtually.
I believe this would be a useful operation to be implemented on #665
Do you agree, @kevinsung?
Sure, it could be useful on any class used to represent fermionic operators.
In order to start planning the implementation of this feature, it would be good to obtain a few usage example/suggestions.
@kevinsung how would you envision this to be used? Are you thinking of something along the lines of what np.transpose can do:
>>> x = np.ones((1, 2, 3))
>>> np.transpose(x, (1, 0, 2)).shape
(2, 1, 3)
Or something entirely different?
Yes, something like that is good. It could be a standalone function or a method. Example: function:
permuted = permute_indices(op, (1, 0, 3, 2))
method:
permuted = op.permute_indices((1, 0, 3, 2))
We need to pick a convention for the permutation ordering, I think whatever np.transpose uses is fine.
I think having this implemented as class methods is preferable as it will need operator-type specific handling unless we only want to (e.g.) support SpinOp labels without exponents. Also the handling in the case of VibrationalOp will need special care as I would expect this to permute modes and not their modals.
So I would go with your second suggestion: op.permute_indices(...). I agree that the ordering can be done the same way as np.transpose does it.
Since this is again a comparatively small feature, I will rename the issue to reflect that any SparseLabelOp subclass should support this in order to ensure feature parity.