qiskit-community / qiskit-nature

Qiskit Nature is an open-source, quantum computing, framework for solving quantum mechanical natural science problems.
https://qiskit-community.github.io/qiskit-nature/
Apache License 2.0
301 stars 205 forks source link

Support interleaved qubit ordering #918

Closed mrossinek closed 1 year ago

mrossinek commented 2 years ago

What should we add?

Currently, all methods which map from spin orbitals to qubits assume a block-ordered arrangement of the qubit register. That means that the first half of the qubits encodes the alpha- and second half the beta-spin orbitals.

It can make sense to specifically want to use an interleaved ordering where odd indices encode alpha- and even indices encode the beta-spin registers. Supporting this via a global configuration setting would be ideal since this can ensure consistent behavior across the various components affected by this (mappers, circuits, etc.)

Alternatively, it may be possible to centralize this configuration via the mappers (since our initial state and ansatz circuits also use mappers). If doing this, the 2-qubit reduction in the case of the ParityMapper would also need to be able to handle this, giving another argument for extracting this qubit reduction functionality out of Terra and back into Nature (see also this comment).

jlapeyre commented 2 years ago

Julia code for doing this is in this file. I may also have python code for this, but I am unable to find it at the moment.

mrossinek commented 1 year ago

I think that indeed the last suggestion in the issue description seems like the most feasible approach for this. Especially now that QubitMapper objects can be used by themselves (i.e. without being wrapped into a QubitConverter; see also #967). On top of that, the planned TaperedQubitMapper (see #974) already proposes the idea of a "wrapped mapper" in the sense that any mapper can be taken and wrapped to apply the tapering as a secondary step. This kind of "mapper chaining" could also be used to implement an interleaved ordering, for example along the lines of this:

class InterleavedMapper:

    def __init__(self, mapper: QubitMapper):
        self.mapper = mapper

    def map(self, operator: SparseLabelOp) -> SparsePauliOp:
        block_ordered_op = self.mapper.map(operator)

        # perform operations to convert the block-ordered qubit operator into interleaved
        # maybe Terra has some utilities for qubit-reordering?
        # Otherwise some sort of string-translation could be used
        interleaved_op = ...

        return interleaved_op

This would allow seamless integration into the existing workflow. Furthermore, this automatically deals with cases like our classically-inspired ansatze (UCC, UVCC) since these first build second-quantized operators and then subsequently map them into qubit space, before evolving them to yield the actual QuantumCircuit building blocks.