Skip to main content

SpaceCore logo SpaceCore

CI PyPI Python License

Building blocks for first-order optimization: spaces, geometry, linear operators, functionals and proximal maps, on NumPy, JAX, Torch and CuPy.

The geometry lives in the space. Gradients, adjoints and proxes are taken in the space's inner product, so an algorithm written once stays correct in a weighted or operator metric, on matrices, Jordan algebras or nested trees. SpaceCore ships no optimization loops: you write them in a few lines, or use spacecore-optimize.

Install

pip install spacecore            # NumPy backend
pip install "spacecore[jax]"     # or [torch], [cupy]

Python 3.11+.

Example

import numpy as np
import spacecore as sc

ctx = sc.Context(sc.NumpyOps(), dtype=np.float64)
X = sc.DenseCoordinateSpace((2,), ctx, geometry=sc.WeightedInnerProduct(ctx.asarray([2.0, 5.0])))
A = sc.DenseLinOp(ctx.asarray([[1.0, 2.0], [0.0, 1.0]]), X, X, ctx)
b = ctx.asarray([1.0, 2.0])

print(X.inner(b, b))   # 22.0: the weighted inner product 2*1 + 5*4
print(A.rapply(b))     # [1.  2.8]: the adjoint in this geometry, not A.T @ b = [1. 4.]

# Weighted lasso, minimize 1/2 ||A x - b||^2 + 0.1 ||x||_1, by proximal gradient.
f = sc.SquaredL2NormFunctional(X) @ A - sc.InnerProductFunctional(A.rapply(b), X, ctx)
g = 0.1 * sc.L1NormFunctional(X)
x, t = X.zeros(), 0.05
for _ in range(500):
    x = g.prox(X.axpy(-t, f.grad(x), x), t)
print(x)               # about [-2.83  1.94]

The loop is the algorithm; the space supplies the geometry it runs in.

What is in it

  • Spaces: dense vectors and matrices, Hermitian matrices and Jordan algebras, stacks, and trees of any of these; Euclidean, weighted and operator metrics.
  • Operators: dense, sparse, diagonal, matrix-free and block operators, with lazy sums, scaling and composition; rapply is always the metric adjoint.
  • Functionals: linear, quadratic and norm functionals, sums, products and pull-backs; gradients in the space's geometry; prox and conjugate_prox; sets and indicators.
  • Sub-step solvers: CG, LSQR, Lanczos, power iteration, expm_multiply.
  • Backends: NumPy, JAX, Torch, CuPy; the objects run inside jax.jit and torch.compile.

Extending

A new space, operator or functional implements check-free cores (_add_core, _inner_core, _apply_core, _grad_core, ...). The public methods (add, inner, apply, grad, ...) are inherited wrappers that run the checks and call the cores, and composites call cores, so each object checks once. See Extending.

Checks

Every object has a check_level: "none", "cheap" (shape, dtype), "standard" (membership, e.g. Hermiticity) or "strict" (+ probes). Set it per object, or once with sc.set_check_level / sc.use_check_level. Failures raise sc.SpaceValidationError. Inside jax.jit / torch.compile checks are capped by sc.set_traced_check_level (default "none").

Docs

Tutorials · Design · API · Release notes

Experimental (0.x): the API may change before 1.0. Contributions welcome — see CONTRIBUTING.md. Apache 2.0.

@software{spacecore,
  author = {Pavlo Pelikh},
  title = {SpaceCore: Spaces, geometry and operators for first-order optimization},
  url = {https://github.com/Pavlo3P/SpaceCore},
  year = {2026},
}

Metadata

Release files for spacecore 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spacecore 0.5.0
File Size Uploaded Provenance
spacecore-0.5.0.tar.gz 502.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for spacecore 0.5.0
File Interpreter ABI Platform
spacecore-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 693.5 kB

Release files / spacecore-0.5.0.tar.gz

Download URL spacecore-0.5.0.tar.gz
Size 502.5 kB
Tags Source
SHA-256 checksum
How to use checksums
15f6bbf3ee6ca7987a94f530ea035d07a4479dd657ee5dc3c395545e70b62fbf
BLAKE2b-256 checksum
How to use checksums
7a1dbba9bc59ddf2fe941ddf42e662cb5277b3798ef207415193da361a510cca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / spacecore-0.5.0-py3-none-any.whl

Download URL spacecore-0.5.0-py3-none-any.whl
Size 191.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea1c91f1280768e8d256d51deacc965e8a13480b9a7916afd6d5aea25edd5b01
BLAKE2b-256 checksum
How to use checksums
b9ea8bbbde0908b8427065fe8e45caf94eb6dea97cf1f275bf68bc631420f37a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Security for spacecore 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spacecore-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page