Skip to main content

Torch-first optimization protocols and CuPy linear-solver helpers for numerical experiments.

Project description

What It Is

Peach is a Torch-based toolbox for optimization and linear-solver experiments. It keeps problem definitions small: optimizers ask concrete problem objects for objective hooks, and linear solvers ask for matrix-vector hooks.

It contains:

  • Protocol-based optimizer and linear-system interfaces.
  • A preconditioned nonlinear conjugate-gradient optimizer with Armijo backtracking, adaptive diagonal Hessian damping, and optional problem hooks for callbacks and step-size limits.
  • CuPy-backed conjugate-gradient and MINRES wrappers for torch tensors, with residual diagnostics.
  • A SciPy optimizer adapter and a Rosenbrock problem for tests and examples.

Install

uv add liblaf-peach

Example

import torch

from liblaf.peach.optim.pncg import Pncg


class QuadraticProblem:
    def __init__(self, target):
        self.target = target

    def update(self, state, params, /):
        state.copy_(params)

    def fun(self, state, /):
        residual = state - self.target
        return 0.5 * torch.dot(residual, residual)

    def grad(self, state, /):
        return state - self.target

    def hess_diag(self, state, /):
        return torch.ones_like(state)

    def hess_quad(self, state, direction, /):
        return torch.dot(direction, direction)


params = torch.tensor([0.0])
model_state = params.clone()
problem = QuadraticProblem(target=torch.tensor([3.0]))
solution = Pncg().minimize(problem, model_state, params)

print(solution.params)
print(model_state)

Local Development

gh repo clone liblaf/peach
cd peach
mise run install
uv run pytest

License

liblaf-peach is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

liblaf_peach-0.10.1.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

liblaf_peach-0.10.1-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file liblaf_peach-0.10.1.tar.gz.

File metadata

  • Download URL: liblaf_peach-0.10.1.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for liblaf_peach-0.10.1.tar.gz
Algorithm Hash digest
SHA256 7e611532b95be59e2a9a0bcd18cab36293556fc1d0632236baedba53dc9aaca1
MD5 84577c7c062225e908a03e39e7552fb2
BLAKE2b-256 b5648579f5820d9ae5050635a7954f66d6d76b83be9ed56d4ecd90b2a6619de3

See more details on using hashes here.

Provenance

The following attestation bundles were made for liblaf_peach-0.10.1.tar.gz:

Publisher: python-release.yaml on liblaf/peach

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file liblaf_peach-0.10.1-py3-none-any.whl.

File metadata

  • Download URL: liblaf_peach-0.10.1-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for liblaf_peach-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c52a14e33876969cd915ce7cee445a8725bf573ebbceedd8efd5d1ee3083ddf
MD5 ab20abac03eb985055b8348e569f46bc
BLAKE2b-256 8f6004ed62f0ab9e543d8f3a04606055a80e1260707eb92c024f848c710626ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for liblaf_peach-0.10.1-py3-none-any.whl:

Publisher: python-release.yaml on liblaf/peach

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page