Skip to content

QUAM Macro API

Welcome to the QUAM Macro API Documentation. The QUAM Macro module provides pre-built macro operations for common quantum gate sequences on qubits and qubit pairs. Information can be found in QUAM Gate-Level Operations Documentation in the User Guide.

This section provides detailed API references for macro operations—high-level functions that encapsulate common quantum operations and gate sequences—simplifying the implementation of complex quantum experiments.

!!! note "Advanced: Core Macro Infrastructure" For creating custom macro types or understanding the underlying macro system, see the core macro classes:

- [BaseMacro][quam.core.macro.BaseMacro] - Base class for all macros
- [QuamMacro][quam.core.macro.QuamMacro] - Base class for QUAM component macros
- [method_macro][quam.core.macro.method_macro] - Decorator for exposing methods as macros

PulseMacro

Bases: QubitMacro

Single-qubit gate for a qubit consisting of a single pulse

Parameters:

Name Type Description Default
pulse

Name of pulse to be played on qubit. Should be a key in channel.operations for one of the qubit's channels

required
Source code in quam/components/macro/qubit_macros.py
25
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
@quam_dataclass
class PulseMacro(QubitMacro):
    """Single-qubit gate for a qubit consisting of a single pulse

    Args:
        pulse: Name of pulse to be played on qubit. Should be a key in
            `channel.operations` for one of the qubit's channels
    """

    pulse: Union[Pulse, str]  # type: ignore

    def apply(self, *, amplitude_scale=None, duration=None, **kwargs):
        if isinstance(self.pulse, Pulse):
            pulse = self.pulse
        else:
            pulse = self.qubit.get_pulse(self.pulse)
        pulse.play(
            amplitude_scale=amplitude_scale, duration=duration, **kwargs  # type: ignore
        )

    @property
    def inferred_duration(self) -> float:
        if isinstance(self.pulse, Pulse):
            return self.pulse.length * 1e-9
        else:
            return self.qubit.get_pulse(self.pulse).length * 1e-9

QubitMacro

Bases: QuamMacro, ABC

Source code in quam/components/macro/qubit_macros.py
11
12
13
14
15
16
17
18
19
20
21
22
@quam_dataclass
class QubitMacro(QuamMacro, ABC):
    @property
    def qubit(self):
        from quam.components.quantum_components.qubit import Qubit

        if isinstance(self.parent, Qubit):
            return self.parent
        elif hasattr(self.parent, "parent") and isinstance(self.parent.parent, Qubit):
            return self.parent.parent
        else:
            raise AttributeError("QubitOperation is not attached to a qubit: {self}")

QubitPairMacro

Bases: QuamMacro, ABC

Source code in quam/components/macro/qubit_pair_macros.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@quam_dataclass
class QubitPairMacro(QuamMacro, ABC):
    @property
    def qubit_pair(self):  # TODO Add QubitPair return type
        from quam.components.quantum_components.qubit_pair import QubitPair

        if isinstance(self.parent, QubitPair):
            return self.parent
        elif hasattr(self.parent, "parent") and isinstance(
            self.parent.parent, QubitPair
        ):
            return self.parent.parent
        else:
            raise AttributeError(
                "TwoQubitGate is not attached to a QubitPair. 2Q_gate: {self}"
            )

    @property
    def qubit_control(self) -> Qubit:
        return self.qubit_pair.qubit_control

    @property
    def qubit_target(self) -> Qubit:
        return self.qubit_pair.qubit_target