Skip to content

qubit_remapper

get_remapped_ir

get_remapped_ir(circuit: Circuit, mapping: Mapping) -> IR

Get replacement IR where the qubit indices are remapped according to the provided mapping.

Parameters:

Name Type Description Default
circuit Circuit

The input circuit from which the replacement IR is to be generated.

required
mapping Mapping

Mapping of virtual qubit indices to physical qubit indices.

required

Returns:

Type Description
IR

Replacement IR with remapped qubit indices.

Source code in opensquirrel/passes/mapper/qubit_remapper.py
def get_remapped_ir(circuit: Circuit, mapping: Mapping) -> IR:
    """Get replacement IR where the qubit indices are remapped according to the provided mapping.

    Args:
        circuit (Circuit): The input circuit from which the replacement IR is to be generated.
        mapping (Mapping): Mapping of virtual qubit indices to physical qubit indices.

    Returns:
        Replacement IR with remapped qubit indices.

    """
    if len(mapping) > circuit.qubit_register_size:
        msg = (
            f"size of the mapping {len(mapping)!r} is larger than the number of qubits {circuit.qubit_register_size!r}"
        )
        raise ValueError(msg)
    qubit_remapper = _QubitRemapper(mapping)
    replacement_ir = circuit.ir
    for statement in replacement_ir.statements:
        statement.accept(qubit_remapper)
    return replacement_ir

remap_ir

remap_ir(circuit: Circuit, mapping: Mapping) -> None

Remap the IR of the circuit according to the provided mapping.

Parameters:

Name Type Description Default
circuit Circuit

The input circuit whose IR is to be remapped.

required
mapping Mapping

Mapping of virtual qubit indices to physical qubit indices.

required
Source code in opensquirrel/passes/mapper/qubit_remapper.py
def remap_ir(circuit: Circuit, mapping: Mapping) -> None:
    """Remap the IR of the circuit according to the provided mapping.

    Args:
        circuit (Circuit): The input circuit whose IR is to be remapped.
        mapping (Mapping): Mapping of virtual qubit indices to physical qubit indices.

    """
    if len(mapping) > circuit.qubit_register_size:
        msg = (
            f"size of the mapping {len(mapping)!r} is larger than the number of qubits {circuit.qubit_register_size!r}"
        )
        raise ValueError(msg)
    qubit_remapper = _QubitRemapper(mapping)
    for statement in circuit.ir.statements:
        statement.accept(qubit_remapper)