pyepo.model.mpax.mpaxmodel ========================== .. py:module:: pyepo.model.mpax.mpaxmodel .. autoapi-nested-parse:: Abstract optimization model based on MPAX Attributes ---------- .. autoapisummary:: pyepo.model.mpax.mpaxmodel.logger Classes ------- .. autoapisummary:: pyepo.model.mpax.mpaxmodel.optMpaxModel Module Contents --------------- .. py:data:: logger .. py:class:: optMpaxModel Bases: :py:obj:`pyepo.model.opt.optModel` Abstract base class for MPAX-backed (JAX) linear / quadratic program models. MPAX is a JAX implementation of the PDHG (Primal-Dual Hybrid Gradient) first-order solver, designed for large-scale continuous programs that benefit from GPU acceleration and vmap-batched solving. Unlike the Gurobi / COPT / Pyomo / OR-Tools backends, an MPAX model has **no explicit solver model object** -- the constraint matrices and bounds *are* the model. Subclasses populate them inside ``_getModel`` and return ``(None, [])``:: def _getModel(self): self.A = jnp.array(...) # equality A x = b self.b = jnp.array(...) self.G = jnp.array(...) # inequality G x >= h self.h = jnp.array(...) self.l = jnp.array(...) # variable lower bound self.u = jnp.array(...) # variable upper bound # optional: leave None for LP, set for convex QP self.Q = jnp.array(...) # PSD; objective is 0.5 xᵀQx + cᵀx return None, [] LP vs QP is selected automatically from ``self.Q``: ``None`` (default) keeps the LP code path via ``create_lp``, any other value routes through ``create_qp``. ``Q`` must be PSD; MPAX supports quadratic *objective only* -- constraints stay linear (this is a hard MPAX limit; e.g. a quadratic risk-budget constraint cannot be expressed). Objective sense follows ``self.modelSense`` (set by a problem-level base such as ``knapsackBase`` or directly in ``_getModel``; defaults to minimization). Dense vs sparse matrices can be toggled by overriding the class attribute ``use_sparse_matrix`` (default ``True``). A jitted single-instance solver and a ``vmap``-batched solver (``batch_optimize``) are pre-compiled on construction, so ``optDataset`` can solve every training instance in a single dispatch. :ivar A: equality-constraint matrix (Ax = b) :vartype A: jnp.ndarray :ivar b: equality-constraint right-hand side :vartype b: jnp.ndarray :ivar G: inequality-constraint matrix (Gx >= h) :vartype G: jnp.ndarray :ivar h: inequality-constraint right-hand side :vartype h: jnp.ndarray :ivar l: variable lower bounds :vartype l: jnp.ndarray :ivar u: variable upper bounds :vartype u: jnp.ndarray :ivar Q: PSD quadratic-objective matrix; ``None`` ⇒ LP :vartype Q: jnp.ndarray | None :ivar use_sparse_matrix: whether to use sparse matrices :vartype use_sparse_matrix: bool .. py:attribute:: use_sparse_matrix :type: bool :value: True .. py:attribute:: Q :value: None .. py:attribute:: device :value: None .. py:property:: num_cost :type: int number of costs to be predicted .. py:method:: setObj(c: numpy.ndarray | torch.Tensor | list) -> None A method to set the objective function :param c: cost of objective function .. py:method:: solve() -> tuple[torch.Tensor, float] A method to solve the model :returns: optimal solution (torch.Tensor) and objective value (float) :rtype: tuple .. py:method:: copy() -> Self A method to copy the model :returns: new copied model :rtype: optModel .. py:method:: addConstr(coefs: numpy.ndarray | torch.Tensor | list, rhs: float) -> Self A method to add a new constraint :param coefs: coefficients of new constraint :param rhs: right-hand side of new constraint :returns: new model with the added constraint :rtype: optModel