Installation¶
Setup Access¶
Moreau is distributed via Gemfury and requires an access token.
Request access to get your token
Add to
~/.pip/pip.conf:[global] index-url = https://<your-token>:@pypi.fury.io/optimalintellect/ extra-index-url = https://pypi.org/simple/
Quick Install¶
pip install moreau
Pure Python interface with Rust-based CPU solver.
pip install moreau[cuda]
CUDA 12 by default, or moreau[cuda13] for CUDA 13. Requires Python 3.12+.
Choose Your Framework¶
pip install moreau[torch]
Requirements: PyTorch >= 2.0
Provides moreau.torch.Solver for neural network integration with autograd support.
pip install jax
Requirements: JAX >= 0.4.0
Provides moreau.jax.Solver compatible with jax.grad, jax.vmap, and jax.jit.
pip install moreau[all]
Install CPU + CUDA + PyTorch. Install JAX separately.
Verify Installation¶
import moreau
import numpy as np
from scipy import sparse
# Simple QP
P = sparse.diags([1.0, 1.0], format='csr')
q = np.array([1.0, 1.0])
A = sparse.csr_matrix([[1.0, 0.0], [0.0, 1.0]])
b = np.array([0.5, 0.5])
cones = moreau.Cones(num_nonneg_cones=2)
solver = moreau.Solver(P, q, A, b, cones=cones)
solution = solver.solve()
print(f"Solution: {solution.x}")
print(f"Status: {solver.info.status}")
print("Installation successful!")
import torch
from moreau.torch import Solver
import moreau
cones = moreau.Cones(num_nonneg_cones=2)
solver = Solver(
n=2, m=2,
P_row_offsets=torch.tensor([0, 1, 2]),
P_col_indices=torch.tensor([0, 1]),
A_row_offsets=torch.tensor([0, 1, 2]),
A_col_indices=torch.tensor([0, 1]),
cones=cones,
)
P_values = torch.tensor([1.0, 1.0], dtype=torch.float64)
A_values = torch.tensor([1.0, 1.0], dtype=torch.float64)
solver.setup(P_values, A_values)
q = torch.tensor([1.0, 1.0], dtype=torch.float64, requires_grad=True)
b = torch.tensor([0.5, 0.5], dtype=torch.float64)
solution = solver.solve(q, b)
print(f"Solution: {solution.x}")
print(f"Device: {solver.device}")
print("PyTorch installation successful!")
import jax.numpy as jnp
from moreau.jax import Solver
import moreau
cones = moreau.Cones(num_nonneg_cones=2)
solver = Solver(
n=2, m=2,
P_row_offsets=jnp.array([0, 1, 2]),
P_col_indices=jnp.array([0, 1]),
A_row_offsets=jnp.array([0, 1, 2]),
A_col_indices=jnp.array([0, 1]),
cones=cones,
)
P_data = jnp.array([1.0, 1.0])
A_data = jnp.array([1.0, 1.0])
q = jnp.array([1.0, 1.0])
b = jnp.array([0.5, 0.5])
solution = solver.solve(P_data, A_data, q, b)
print(f"Solution: {solution.x}")
print(f"Device: {solver.device}")
print("JAX installation successful!")
GPU Acceleration¶
CUDA Support
For NVIDIA GPUs, the CUDA backend provides significant speedups, especially for batched problems.
Check GPU availability:
import moreau
print(f"Available devices: {moreau.available_devices()}")
print(f"Default device: {moreau.default_device()}")
print(f"CUDA available: {moreau.device_available('cuda')}")
Force GPU usage:
settings = moreau.Settings(device='cuda')
solver = moreau.Solver(P, q, A, b, cones=cones, settings=settings)
Dependencies¶
Core Dependencies
Package |
Version |
Purpose |
|---|---|---|
Python |
>= 3.9 |
Runtime |
NumPy |
>= 1.19.0 |
Array operations |
SciPy |
>= 1.6.0 |
Sparse matrices |
Pydantic |
>= 2.0.0 |
Data validation |
moreau-cpu |
>= 0.1.0 |
CPU solver backend |
Optional Dependencies
Package |
Version |
Purpose |
|---|---|---|
moreau-cuda12 |
>= 0.1.0 (Python >= 3.12) |
GPU solver backend |
moreau-cuda13 |
>= 0.1.0 (Python >= 3.12) |
GPU solver backend |
PyTorch |
>= 2.0 |
PyTorch integration |
JAX |
>= 0.4.0 |
JAX integration |
Troubleshooting¶
ImportError: moreau-cpu not found
The core CPU backend is required. Install it with:
pip install moreau-cpu
Or reinstall moreau:
pip install --force-reinstall moreau
CUDA not detected
Ensure you have:
An NVIDIA GPU with CUDA support
CUDA drivers installed
The CUDA backend:
pip install moreau[cuda]
Check CUDA availability:
import moreau
print(moreau.device_available('cuda'))
PyTorch/JAX import errors
Install the framework-specific extras:
pip install moreau[torch] # For PyTorch
pip install jax # For JAX