Core API

The core API provides NumPy-based solvers for conic optimization.

Solver

class moreau.Solver(P, q, A, b, cones, settings=None)

Single-problem conic optimization solver.

All problem data is provided in the constructor, then call solve().

Problem Formulation:

minimize    (1/2)x'Px + q'x
subject to  Ax + s = b
            s in K
Parameters:
  • P – Quadratic objective matrix (scipy sparse or numpy array). Must be full symmetric (both triangles).

  • q – Linear objective vector, shape (n,)

  • A – Constraint matrix (scipy sparse or numpy array), shape (m, n)

  • b – Constraint RHS vector, shape (m,)

  • cones – Cone specification (moreau.Cones object)

  • settings – Optional solver settings (moreau.Settings object)

Example:

import moreau
from scipy import sparse
import numpy as np

P = sparse.diags([1.0, 1.0], format='csr')
q = np.array([2.0, 1.0])
A = sparse.csr_matrix([[1.0, 1.0], [1.0, 0.0], [0.0, 1.0]])
b = np.array([1.0, 0.7, 0.7])
cones = moreau.Cones(num_zero_cones=1, num_nonneg_cones=2)

solver = moreau.Solver(P, q, A, b, cones)
solution = solver.solve()
print(solution.x, solver.info.status)
solve()

Solve the optimization problem.

Returns:

Solution object with primal/dual solution vectors (x, z, s)

Return type:

Solution

info: SolveInfo

Metadata from the last solve() call. Contains status, objective value, iterations, and timing information.

device: str

The active device (‘cpu’ or ‘cuda’).

n: int

Number of primal variables.

m: int

Number of constraints.

CompiledSolver

class moreau.CompiledSolver(n, m, P_row_offsets, P_col_indices, A_row_offsets, A_col_indices, cones, settings=None)

Compiled solver for batched problems with shared structure.

Uses a three-step API: construct with structure, setup() matrix values, then solve() with parameters.

Parameters:
  • n – Number of primal variables

  • m – Number of constraints

  • P_row_offsets – CSR row pointers for P matrix

  • P_col_indices – CSR column indices for P matrix

  • A_row_offsets – CSR row pointers for A matrix

  • A_col_indices – CSR column indices for A matrix

  • cones – Cone specification (moreau.Cones object)

  • settings – Solver settings (moreau.Settings object)

Example:

import moreau
import numpy as np

cones = moreau.Cones(num_zero_cones=1, num_nonneg_cones=2)
settings = moreau.Settings(batch_size=4)

solver = moreau.CompiledSolver(
    n=2, m=3,
    P_row_offsets=[0, 1, 2], P_col_indices=[0, 1],
    A_row_offsets=[0, 2, 3, 4], A_col_indices=[0, 1, 0, 1],
    cones=cones, settings=settings
)

solver.setup(P_values=[1., 1.], A_values=[1., 1., 1., 1.])
solution = solver.solve(qs=[[2., 1.]]*4, bs=[[1., 0.7, 0.7]]*4)
print(solution.x.shape)  # (4, 2)
setup(P_values, A_values)

Set P and A matrix values for the batch.

Parameters:
  • P_values – P matrix values. Shape (batch, nnz_P) or (nnz_P,) if shared.

  • A_values – A matrix values. Shape (batch, nnz_A) or (nnz_A,) if shared.

solve(qs, bs)

Solve a batch of problems.

Parameters:
  • qs – Linear cost vectors, shape (batch, n)

  • bs – Constraint RHS vectors, shape (batch, m)

Returns:

Batched solution with arrays of shape (batch, n) or (batch, m)

Return type:

BatchedSolution

info: BatchedSolveInfo

Metadata from the last solve() call.

batch_size: int

The batch size.

Cones

class moreau.Cones(num_zero_cones=0, num_nonneg_cones=0, num_so_cones=0, num_exp_cones=0, power_alphas=None)

Specification for the cone structure K in the constraint s in K.

Constraints must be ordered in A and b to match: zero cones, then nonnegative, then second-order, then exponential, then power.

Parameters:
  • num_zero_cones – Number of equality constraints (zero cone, any dimension)

  • num_nonneg_cones – Number of inequality constraints (nonnegative cone)

  • num_so_cones – Number of second-order cones (fixed dimension 3)

  • num_exp_cones – Number of exponential cones (dimension 3)

  • power_alphas – List of alpha values for power cones (dimension 3 each, alpha in (0,1))

total_constraints()

Total number of scalar constraints.

Returns:

Sum of all cone dimensions

Settings

class moreau.Settings(device='auto', batch_size=1, verbose=False, max_iter=200, enable_grad=False, ipm_settings=None)

Solver configuration.

Parameters:
  • device – Device selection (‘auto’, ‘cpu’, ‘cuda’)

  • batch_size – Batch size for CompiledSolver

  • verbose – Print solver progress

  • max_iter – Maximum IPM iterations

  • enable_grad – Enable gradient computation

  • ipm_settings – Fine-grained IPM settings (IPMSettings object)

IPMSettings

class moreau.IPMSettings(tol_gap_abs=1e-8, tol_gap_rel=1e-8, tol_feas=1e-8, ...)

Interior-point method settings.

Parameters:
  • tol_gap_abs – Absolute duality gap tolerance

  • tol_gap_rel – Relative duality gap tolerance

  • tol_feas – Feasibility tolerance

  • tol_infeas_abs – Absolute infeasibility detection tolerance

  • tol_infeas_rel – Relative infeasibility detection tolerance

  • tol_ktratio – KKT ratio tolerance

Data Types

Solution

class moreau.Solution

Single-problem solution.

x: numpy.ndarray

Primal solution, shape (n,)

z: numpy.ndarray

Dual variables, shape (m,)

s: numpy.ndarray

Slack variables, shape (m,)

BatchedSolution

class moreau.BatchedSolution

Batched solution with array outputs.

x: numpy.ndarray

Primal solutions, shape (batch, n)

z: numpy.ndarray

Dual variables, shape (batch, m)

s: numpy.ndarray

Slack variables, shape (batch, m)

Supports indexing: solution[i] returns a Solution for problem i.

SolveInfo

class moreau.SolveInfo

Metadata from a solve.

status: SolverStatus

Solve outcome

obj_val: float

Objective value at solution

iterations: int

Number of IPM iterations

solve_time: float

Time in IPM iterations (seconds)

setup_time: float

Time setting matrix values (seconds)

construction_time: float

Time constructing solver (seconds)

SolverStatus

class moreau.SolverStatus

Enum indicating solve outcome.

Solved

Optimal solution found

AlmostSolved

Near-optimal solution (relaxed tolerances)

PrimalInfeasible

Problem has no feasible solution

DualInfeasible

Problem is unbounded

MaxIterations

Iteration limit reached

NumericalError

Numerical issues encountered

Device Functions

moreau.available_devices()

List all available devices.

Returns:

List of device names (e.g., [‘cpu’, ‘cuda’])

Return type:

list[str]

moreau.device_available(device)

Check if a specific device is available.

Parameters:

device – Device name (‘cpu’ or ‘cuda’)

Returns:

True if available

Return type:

bool

moreau.default_device()

Return the effective default device (after applying priority and overrides).

Returns:

Device name (e.g., ‘cpu’, ‘cuda’)

Return type:

str

moreau.get_default_device()

Get the current default device override.

Returns:

Device name if an override is set, otherwise None

Return type:

str or None

moreau.set_default_device(device)

Set the global default device.

Parameters:

device – Device name (‘cpu’ or ‘cuda’)