Skip to content

quicopt.ir

ir

quicopt.ir — the structured Program IR.

Front-end-agnostic data: a front-end (quicopt.pyomo, quicopt.mathopt) builds a Program; quicopt.wire serializes it to the versioned wire bytes. The IR/wire is the service's contract — these types track it, they never fork it. Index tuple entries are int (a concrete coordinate) or str (a bound index symbol); the IR never uses a bare string for data, so the mapping is total.

Domain

Bases: IntEnum

The domain a variable ranges over. Values are the wire enum codes.

Expression

Base of the expression grammar.

Const dataclass

Const(value: float)

Bases: Expression

A literal numeric constant.

Param dataclass

Param(name: str, index: tuple = ())

Bases: Expression

A reference to a parameter-table entry — data bound at instance time, by name and an index tuple (() for a scalar).

Var dataclass

Var(name: str, index: tuple = ())

Bases: Expression

A reference to a decision variable, by name and an index tuple (() for a scalar).

Apply dataclass

Apply(op: str, args: list)

Bases: Expression

A catalog operator op applied to its argument subexpressions.

SetRef dataclass

SetRef(name: str, args: tuple = ())

A reference to an index set: args=() is the flat set; args=("i",) references the set indexed by enclosing bound indices.

Reduce dataclass

Reduce(
    op: str,
    idx: str,
    over: SetRef,
    body: Expression,
    cond: "Expression | None" = None,
)

Bases: Expression

A fold of body over idx ranging across over — e.g. a Σ or Π — keeping a term only where cond is non-zero (None ⇒ keep every term).

Zero dataclass

Zero()

f = 0

Nonneg dataclass

Nonneg()

f ≥ 0

Indicator dataclass

Indicator(bin: Var, inner: object)

bin active (= 1) implies the body satisfies the inner ConSet.

VarDecl dataclass

VarDecl(
    name: str,
    axes: list,
    domain: Domain,
    lower: object,
    upper: object,
    start: float,
)

A variable declaration: name over the product of the index sets in axes ([] ⇒ scalar), ranging over domain, with lower/upper bounds and an initial start. A bound is a float, or the str name of a Param table when it varies by index.

IndexSet dataclass

IndexSet(name: str, elements: list)

A named index set with concrete elements (each int or str).

Constraint dataclass

Constraint(f: Expression, set: object, over: list = list())

A constraint row: the expression f lies in the ConSet set, for every binding in over ([(dummy, SetRef)]; empty ⇒ a single scalar row).

Program dataclass

Program(
    sets: list = list(),
    indexed_sets: dict = dict(),
    params: dict = dict(),
    vars: list = list(),
    objective: Expression = None,
    sense: str = "min",
    constraints: list = list(),
    fix: dict = dict(),
)

A complete optimization model: index sets and data tables, variable declarations, the objective and its sense, the constraint rows, and any per-index variable pins (fix).