pyepo.dsl.expression

Symbolic expression nodes and algebra for the PyEPO DSL.

Variables and Parameters compose through numpy-style operators into linear (Affine) and quadratic (Quadratic) nodes; comparisons produce a Constraint; a single Parameter multiplies a Variable (or slice) into a ParametricObjective objective. Each linear node carries per-Variable coefficient blocks (dict[Variable, csr_matrix]) plus a constant offset; Problem finalizes them into one global sparse matrix (see pyepo.dsl.problem).

Classes

Variable

A decision variable of a given shape and per-entry type.

Affine

Linear expression Σ_v A_v @ vec(v) + b of logical shape.

Quadratic

Scalar quadratic expression xᵀ Q x + (linear) + const.

Parameter

The runtime-bound predicted cost symbol (exactly one per Problem).

ParametricCoef

A predicted cost coefficient with a known base, base + param — the

ParametricVector

The elementwise product c * x (optionally with a known base): a vector of

ParametricObjective

The objective: cost_param predicts the cost at cost_var's selected

Constraint

A relation lhs (<= | >= | ==) rhs between an expression and a constant.

Module Contents

class pyepo.dsl.expression.Variable(shape, *, vtype=EPO.CONTINUOUS, lb=None, ub=None, name=None)

A decision variable of a given shape and per-entry type.

vtype is a scalar EPO.VarType (uniform) or a per-entry array; binary entries are forced to bounds [0, 1].

Variables:
  • shape (tuple) – logical shape

  • size (int) – number of scalar entries (prod(shape))

  • vtype (np.ndarray) – per-entry EPO.VarType, length size

  • ub (lb /) – flat C-order bounds, length size

shape
size
vtype
lb
ub
name = None
sum(axis=None)
class pyepo.dsl.expression.Affine(blocks, const, shape)

Linear expression Σ_v A_v @ vec(v) + b of logical shape.

Variables:
  • blocks (dict[Variable, csr_matrix]) – per-Variable coefficient block (size, v.size)

  • const (np.ndarray) – constant offset (size,)

  • shape (tuple) – logical shape; size == prod(shape)

shape
size
const
blocks
sum(axis=None)
finalize(flat_slice, num_vars)
class pyepo.dsl.expression.Quadratic(quad, affine)

Scalar quadratic expression xᵀ Q x + (linear) + const.

Variables:
  • quad (dict[(Variable, Variable), csr_matrix]) – symmetric-when-finalized blocks

  • affine (Affine) – scalar linear + constant part

quad
affine
finalize_Q(flat_slice, num_vars)
class pyepo.dsl.expression.Parameter(shape, *, name=None)

The runtime-bound predicted cost symbol (exactly one per Problem).

The inner product c @ x (or c @ x[:k]) pairs the predicted cost with a Variable (or a plain slice / index of one) into a scalar objective term. The elementwise product c * x is a vector of predicted terms; reduce it to the scalar objective with (c * x).sum(). A known base may be added first: (d + c) @ x predicts d + c on x. Any other use raises TypeError.

Variables:
  • shape (tuple) – logical shape

  • size (int) – number of predicted entries (prod(shape))

shape
size
name = None
class pyepo.dsl.expression.ParametricCoef(param, base)

A predicted cost coefficient with a known base, base + param — the transient result of c + d / d + c / c - d. Pairs with a Variable or selection like a Parameter: (d + c) @ x (scalar) or (d + c) * x (elementwise vector, reduce with .sum()).

param
base
class pyepo.dsl.expression.ParametricVector(param, base, sel)

The elementwise product c * x (optionally with a known base): a vector of predicted terms, one per selected position. It is not yet a scalar objective; reduce it with .sum() to form the objective term (c * x).sum().

Variables:
  • param (Parameter) – the predicted cost

  • base (np.ndarray | None) – known offset added at the predicted positions

  • sel (Variable | Affine) – the Variable / selection the cost lands on

param
base
sel
sum(axis=None)
class pyepo.dsl.expression.ParametricObjective(cost_param, cost_var, local_idx=None, base=None, fixed=None, quad=None)

The objective: cost_param predicts the cost at cost_var’s selected positions (with an optional known base), plus optional known fixed linear (fixed) and parameter-free quadratic (quad) terms.

Variables:
  • cost_param (Parameter) – the predicted cost (size == num_cost)

  • cost_var (Variable) – the Variable the prediction lands on

  • local_idx (np.ndarray | None) – predicted indices within cost_var (None = all)

  • base (np.ndarray | None) – known cost added at the predicted positions

  • fixed (Affine | None) – known linear term on other / overlapping positions

  • quad (Quadratic | None) – parameter-free quadratic term

cost_param
cost_var
local_idx = None
base = None
fixed = None
quad = None
sum(axis=None)
class pyepo.dsl.expression.Constraint(lhs, sense, rhs)

A relation lhs (<= | >= | ==) rhs between an expression and a constant.

Variables:
  • lhs (Affine | Quadratic) – left-hand side expression

  • sense (str) – one of "<=" / ">=" / "=="

  • rhs (np.ndarray) – right-hand side, broadcast over the LHS shape

lhs
sense
rhs
variables()
finalize(flat_slice, num_vars)

Assemble the global form (Q | None, A, sense, b_eff) (b_eff = rhs - const).