Skip to content

check_mapper

This module contains checks for the Mapper pass.

check_mapper(mapper)

Check if the mapper complies with the OpenSquirrel requirements.

If a Mapper implementation passes these checks, it should be compatible with the Circuit.map method.

Parameters:

Name Type Description Default
mapper Mapper

Mapper to check.

required
Source code in opensquirrel/passes/mapper/check_mapper.py
def check_mapper(mapper: Mapper) -> None:
    """Check if the `mapper` complies with the OpenSquirrel requirements.

    If a ``Mapper`` implementation passes these checks, it should be compatible with the ``Circuit.map`` method.

    Args:
        mapper: Mapper to check.
    """
    assert isinstance(mapper, Mapper)

    register_manager = RegisterManager(
        OrderedDict({DEFAULT_QUBIT_REGISTER_NAME: QubitRegister(10)}),
        OrderedDict({DEFAULT_BIT_REGISTER_NAME: BitRegister(10)}),
    )
    ir = IR()
    circuit = Circuit(register_manager, ir)
    _check_scenario(circuit, mapper)

    ir = IR()
    ir.add_gate(SingleQubitGate(qubit=42, gate_semantic=BlochSphereRotation((1, 0, 0), 1, 2)))
    ir.add_gate(TwoQubitGate(42, 100, gate_semantic=ControlledGateSemantic(I(100))))
    ir.add_non_unitary(Measure(42, 42, (0, 0, 1)))
    Circuit(register_manager, ir)
    _check_scenario(circuit, mapper)