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.0.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.0-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: liblaf_peach-0.10.0.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.0.tar.gz
Algorithm Hash digest
SHA256 7372c2818d4b10f4dc1a1b7858bc2c9acb2597a7588e589dbafe921da347cf54
MD5 91721cdc5da0189d788419577be3477e
BLAKE2b-256 c09bb35a88053bb79a594319bee3e4ca020ead48252904adeef16b7ec2c3673d

See more details on using hashes here.

Provenance

The following attestation bundles were made for liblaf_peach-0.10.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: liblaf_peach-0.10.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d384d011c80675b9dd09f184da7c75167af94d9d70c1f595b6948d6b57a196d
MD5 c2a2ff9022af7173f65c7aad260a6c04
BLAKE2b-256 7e89b05d40d0061a62d7fb1c4eedc0bc9eb7dd598ad6418b5daf7ca2691c90f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for liblaf_peach-0.10.0-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