Skip to content

quast_decisiontree.nodes.qrisp_mixer

quast_decisiontree.nodes.qrisp_mixer

Node for selecting Qrisp-compatible QAOA mixers.

logger module-attribute

logger = logging.getLogger('dt_logger')

QrispMixerNode

Bases: Node

Selects a Qrisp-compatible mixer for QAOA.

Produces a callable mixer(qv, beta) suitable for Qrisp's QAOAProblem.

Parameters

children : list Child node names. mixer_modules : str or list of str, optional One or more fully qualified module paths containing additional mixer registrations. Modules are imported at node construction time, allowing them to call register_mixer() to extend the available choices.

Example YAML::

    QrispMixerNode:
      children: ["SelectOptimizerNode"]
      mixer_modules:
        - "my_project.constrained_mixers"
        - "my_project.experimental_mixers"
Modifications at runtime
  • mixer_type : str Name of the selected mixer (e.g., 'RX', 'XY', 'Ring').
Source code in src/quast_decisiontree/nodes/qrisp_mixer.py
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
class QrispMixerNode(Node):
    """Selects a Qrisp-compatible mixer for QAOA.

    Produces a callable ``mixer(qv, beta)`` suitable for Qrisp's QAOAProblem.

    Parameters
    ----------
    children : list
        Child node names.
    mixer_modules : str or list of str, optional
        One or more fully qualified module paths containing additional mixer
        registrations. Modules are imported at node construction time, allowing
        them to call ``register_mixer()`` to extend the available choices.

        Example YAML::

            QrispMixerNode:
              children: ["SelectOptimizerNode"]
              mixer_modules:
                - "my_project.constrained_mixers"
                - "my_project.experimental_mixers"

    Modifications at runtime
    ------------------------
    - mixer_type : str
        Name of the selected mixer (e.g., 'RX', 'XY', 'Ring').
    """

    _known_children = ["SelectOptimizerNode"]
    _path_keys = dict(mixer_type=PathKey(str))

    def __init__(
        self,
        children: list,
        mixer_modules: Sequence[str] | None = None,
    ) -> None:
        super().__init__(
            requires=["algorithm"],
            creates=["mixer_type", "mixer"],
            children=children,
        )

        if mixer_modules is not None:
            if isinstance(mixer_modules, str):
                mixer_modules = [mixer_modules]
            load_mixer_modules(mixer_modules)

        self.mixer_options = get_registry_descriptions()
        self.query = MultiChoiceQuery(
            question="Choose a Qrisp-compatible mixer:",
            answers=self.mixer_options,
            default="RX",
            name="mixer_type",
        )

    def execute(self, problem_data: dict, path_info: dict) -> dict:
        mixer_type = path_info.get("mixer_type")

        if problem_data.get("algorithm") == "BaseQAOA":
            if mixer_type is not None and mixer_type != "RX":
                logger.warning(
                    "Mixer type RX is fixed for algorithm BaseQAOA. "
                    "Ignoring configured mixer_type=%r.",
                    mixer_type,
                )
            mixer_type = "RX"
        elif mixer_type is None:
            mixer_type = self.query.input()

        path_info["mixer_type"] = mixer_type
        problem_data["mixer_type"] = mixer_type

        problem_data["mixer"] = get_mixer(
            mixer_type,
            num_qubits=problem_data.get("num_qubits"),
        )

        return dict(mixer_type=mixer_type)

mixer_options instance-attribute

mixer_options = get_registry_descriptions()

query instance-attribute

query = MultiChoiceQuery(
    question="Choose a Qrisp-compatible mixer:",
    answers=self.mixer_options,
    default="RX",
    name="mixer_type",
)

__init__

__init__(children, mixer_modules=None)
Source code in src/quast_decisiontree/nodes/qrisp_mixer.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def __init__(
    self,
    children: list,
    mixer_modules: Sequence[str] | None = None,
) -> None:
    super().__init__(
        requires=["algorithm"],
        creates=["mixer_type", "mixer"],
        children=children,
    )

    if mixer_modules is not None:
        if isinstance(mixer_modules, str):
            mixer_modules = [mixer_modules]
        load_mixer_modules(mixer_modules)

    self.mixer_options = get_registry_descriptions()
    self.query = MultiChoiceQuery(
        question="Choose a Qrisp-compatible mixer:",
        answers=self.mixer_options,
        default="RX",
        name="mixer_type",
    )

execute

execute(problem_data, path_info)
Source code in src/quast_decisiontree/nodes/qrisp_mixer.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def execute(self, problem_data: dict, path_info: dict) -> dict:
    mixer_type = path_info.get("mixer_type")

    if problem_data.get("algorithm") == "BaseQAOA":
        if mixer_type is not None and mixer_type != "RX":
            logger.warning(
                "Mixer type RX is fixed for algorithm BaseQAOA. "
                "Ignoring configured mixer_type=%r.",
                mixer_type,
            )
        mixer_type = "RX"
    elif mixer_type is None:
        mixer_type = self.query.input()

    path_info["mixer_type"] = mixer_type
    problem_data["mixer_type"] = mixer_type

    problem_data["mixer"] = get_mixer(
        mixer_type,
        num_qubits=problem_data.get("num_qubits"),
    )

    return dict(mixer_type=mixer_type)