Remap: unused qubits remover

Remap class is used to remove usused qubits from circuit. Unused but measured qubits are also removed, this plugin will remove these qubits and post-process the result (the post processing step will assign the state \(|0\rangle\) for these qubits).

This plugins has two mode:
  • Default mode: All unused qubits are removed

  • Keep topology mode: Qubits on which a gate is applied are preserved. For instance, a qubit applied on qubit of index \(j\) before the plugin will still be applied on the qubit of index \(j\) after the compilation, even if qubit of index \(j - 1\) is unused (then, qubit of index \(j - 1\) is not removed neither)

from qat.plugins import Display, Remap
from qat.qpus import get_default_qpu
from qat.lang.AQASM import Program, H

# Creates a circuit having an unused qubits
prog = Program()
_, qbit, _ = prog.qalloc(3)
prog.apply(H, qbit)
job = prog.to_circ().to_job()

# Builds a stack
qpu = Remap() | Display(batchmode=True) | get_default_qpu()
print("Circuit after compilation (1 qbit circuit):")
result = qpu.submit(job)

# Prints result
print("Result:")
for sample in result:
    print(f"{sample.state}: {sample.probability}")
Circuit after compilation (1 qbit circuit):
 ┌─┐
─┤H├
 └─┘
    

Result:
|000>: 0.4999999999999999
|010>: 0.4999999999999999
from qat.plugins import Display, Remap
from qat.qpus import get_default_qpu
from qat.lang.AQASM import Program, H

# Creates a circuit having an unused qubits
prog = Program()
_, qbit, _ = prog.qalloc(3)
prog.apply(H, qbit)
job = prog.to_circ().to_job()

# Builds a stack
qpu = Remap(keep_topology=True) | Display(batchmode=True) | get_default_qpu()
print("Circuit after compilation (2 qbits circuit):")
result = qpu.submit(job)

# Prints result
print("Result:")
for sample in result:
    print(f"{sample.state}: {sample.probability}")
Circuit after compilation (2 qbits circuit):
    
────
    
    
 ┌─┐
─┤H├
 └─┘
    

Result:
|000>: 0.4999999999999999
|010>: 0.4999999999999999
class qat.plugins.Remap(keep_topology=False)

Remaps the used qubits of each circuit onto an initial segment of the integers (i.e. [0..N-1] for some N). Unused qubits are removed from the circuit (compiling a circuit could insert unused additional qubits - to match the QPU topology - this plugin can be used to improve the emulation of a compiled circuit)

Note

Classical bits are not remapped in any way!

This plugin will also post-process the result. In sample mode, measured unused qubits are set to zero (each sample is fixed to consider unused measured qubits)

Warning

If the result returned by the QPU contains a statevector, the post-processing step will remove the statevector attribute (each sample composing the result should be fixed)

Parameters

keep_topology (boolean, optional) – keep the topology. If this argument is set to True, a gate applied between qubits q1 and q2 will still be applied between those two qubits, otherwise, this gate can be applied on another pair of qubits. Default: False