Source code for qblox_scheduler.operations.statements

# Repository: https://gitlab.com/qblox/packages/software/qblox-scheduler
# Licensed according to the LICENSE file on the main branch
#
# Copyright 2025, Qblox B.V.
"""Assignment statement operation."""

from __future__ import annotations

from typing import TYPE_CHECKING

from qblox_scheduler.operations.operation import Operation
from qblox_scheduler.operations.variables import Variable

if TYPE_CHECKING:
    from qblox_scheduler.operations.expressions import Expression


[docs] class Assign(Operation): """ Assign a value to a variable. The assigned value is evaluated and stored in the target variable. For a plain variable or literal this is a direct copy; for a more complex expression it is broken down into a short sequence of arithmetic operations. Parameters ---------- variable : Variable Target variable to receive the value. Must have been declared with :meth:`~qblox_scheduler.schedules.schedule.TimeableSchedule.declare`. value : Variable or Expression or int or float Value to assign. May be another :class:`~.Variable`, an arithmetic :class:`~qblox_scheduler.operations.expressions.Expression` built from variables/literals, or a plain :class:`int` / :class:`float` literal. Examples -------- .. code-block:: from qblox_scheduler.operations.expressions import DType from qblox_scheduler.operations.statements import Assign offset = sched.declare(DType.AMPLITUDE) sched.add(Assign(offset, 0.0)) # literal sched.add(Assign(offset, start)) # variable copy sched.add(Assign(offset, offset + step)) # arithmetic expression """ def __init__( self, variable: Variable, value: Variable | Expression | int | float, ) -> None: if not isinstance(variable, Variable): raise TypeError( f"The target of Assign must be a Variable, got {type(variable).__name__}" ) super().__init__(name="Assign") self.data.update( { "statement_info": { "type": "assignment", "variable": variable, "value": value, "used_port_clocks": set(), # Filled in by compiler. "used_clocks": set(), # Filled in by compiler. } } ) @property
[docs] def variable(self) -> Variable: """Target variable.""" return self.data["statement_info"]["variable"]
@property
[docs] def value(self) -> Variable | Expression | int | float: """Value to assign.""" return self.data["statement_info"]["value"]