pyepo.dsl.problem

The DSL Problem: collects variables, finalizes the symbolic IR into global sparse matrices, validates PyEPO scope, and compiles to a backend.

At construction every referenced Variable is assigned a contiguous slice of a global flat index (encounter order: objective first, then each constraint in list order). Constraints finalize to (Q | None, A, sense, b_eff); the objective finalizes to the predicted c_pred_index, a known fixed_cost linear part, and an optional parameter-free quadratic term obj_Q.

Classes

Problem

A symbolic predict-then-optimize problem.

Module Contents

class pyepo.dsl.problem.Problem(objective, constraints=None)

A symbolic predict-then-optimize problem.

Variables:
  • objective (Minimize | Maximize) – the objective

  • constraints (list[Constraint]) – the constraints

  • cost_param (Parameter) – the unique predicted-cost Parameter

  • cost_var (Variable) – the Variable the predicted cost lands on

  • num_cost (int) – predicted dimension (cost_param.size)

  • flat_slice (dict[Variable, slice]) – global flat slice per Variable

  • num_vars (int) – total decision-variable count

  • c_pred_index (np.ndarray) – flat indices the predicted cost lands on

  • fixed_cost (np.ndarray) – known linear objective coefficients (num_vars,)

  • constrs (list[tuple]) – finalized (Q, A, sense, b_eff) per constraint

  • obj_Q (csr_matrix | None) – finalized parameter-free quadratic objective term

objective
constraints
cost_param
cost_var
modelSense
cost_var_name
property num_cost: int
relax() Problem

Return a new Problem with all integer / binary variables continuous (bounds preserved: binary ⇒ [0, 1]); objective and constraints unchanged.

compile(backend, **kwargs)

Compile to a solver backend, returning an optModel.

A solver with a native backend ("gurobi" / "copt") is reached through it directly — the most efficient path. The generic backends ("pyomo", "ortools") are only for solvers without a native one (HiGHS, GLPK, CBC, SCIP, Ipopt); routing a native solver through them is wasteful indirection.

Parameters:
  • backend – solver backend name ("gurobi", "copt", "pyomo", "ortools", "mpax").

  • **kwargs – backend options – solver= (generic backends), timelimit= (seconds), or native solver parameters.