Skip to content
Merged

V0.2 #38

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
09efbca
Refactor backend ops to use Array API Compat
Pavlo3P May 19, 2026
80abf4d
Polish BackendOps behavior for v0.2
Pavlo3P May 19, 2026
6114eef
Merge pull request #34 from Pavlo3P/migrate-to-array-api
Pavlo3P May 20, 2026
bae5446
Add lazy LinOp algebra foundation
Pavlo3P May 20, 2026
d5cf139
Fix LinOp base equality protocol
Pavlo3P May 20, 2026
c454332
Document Space membership check convention
Pavlo3P May 20, 2026
2d54d64
Simplify scaled zero LinOps
Pavlo3P May 20, 2026
57283f8
Add dense materialization for LinOps
Pavlo3P May 20, 2026
89f007b
Add algebra layer regression tests
Pavlo3P May 20, 2026
5e81657
Polish LinOp dense materialization
Pavlo3P May 20, 2026
26c6515
Merge pull request #35 from Pavlo3P/implement-linop-algebra
Pavlo3P May 20, 2026
ecbdd29
Add CuPy backend support
Pavlo3P May 20, 2026
2778c5d
Add backend loop tests
Pavlo3P May 20, 2026
bf00af7
Add jittable linalg solvers
Pavlo3P May 21, 2026
d3ab7dd
Improve linalg guide and linop representations
Pavlo3P May 21, 2026
d28aa09
Add batched linop lifting
Pavlo3P May 22, 2026
82ac1b9
Optimize batched dense and sparse linops
Pavlo3P May 22, 2026
2185952
Merge pull request #36 from Pavlo3P/batched_apply
Pavlo3P May 22, 2026
cff5d83
Add functional abstractions
Pavlo3P May 22, 2026
a37b3c3
Generalize power iteration dispatch
Pavlo3P May 22, 2026
27c7e72
Merge pull request #37 from Pavlo3P/add-functionals
Pavlo3P May 22, 2026
d0f58bf
Refactor contextual checks and Lanczos geometry
Pavlo3P May 22, 2026
21c4d71
Refactor contextual checks and Lanczos geometry
Pavlo3P May 22, 2026
f958cc0
Enrich docstrings and backend docs
Pavlo3P May 22, 2026
9197c23
Fix contextual import cycle
Pavlo3P May 22, 2026
f7eb7c8
Fix contextual import cycle
Pavlo3P May 22, 2026
b3ab5ad
Prepare v0.2 API cleanup
Pavlo3P May 26, 2026
cb13ecb
Document cacheability audit
Pavlo3P May 26, 2026
68a3268
Hoist Lanczos coefficient zero template
Pavlo3P May 26, 2026
a4ddaf2
Add JIT traceability audit
Pavlo3P May 26, 2026
e90caee
Vectorize Lanczos reorthogonalization for vector spaces
Pavlo3P May 26, 2026
a32432c
Add Krylov expm_multiply
Pavlo3P May 26, 2026
727eb92
Update JIT audit for expm multiply
Pavlo3P May 26, 2026
ce375f4
Pin Lanczos weighted-space slow path
Pavlo3P May 26, 2026
3ae3d85
Run JIT audit in CI
Pavlo3P May 26, 2026
0586f86
Document JAX integration guidance
Pavlo3P May 26, 2026
d7188b6
Use checked_method for Space membership checks
Pavlo3P May 26, 2026
7d543b0
Add docstring migration tooling baseline
Pavlo3P May 27, 2026
5b99e64
Improve public API docstrings
Pavlo3P May 27, 2026
b2be421
Add linalg API docs page
Pavlo3P May 27, 2026
7dde7b8
Clarify linalg solver contracts
Pavlo3P May 27, 2026
93cb7f4
Update README and Release Notes
Pavlo3P May 27, 2026
7a7a99d
Update release notes
Pavlo3P May 27, 2026
4c26c91
Remove stochastic Lanczos alias
Pavlo3P May 27, 2026
33d1985
Add changelog
Pavlo3P May 27, 2026
cb32ce9
Remove old files
Pavlo3P May 27, 2026
9658179
Remove stochastic Lanczos
Pavlo3P May 27, 2026
de34032
Remove stochastic Lanczos
Pavlo3P May 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ jobs:

- run: python -m pip install --upgrade pip
- run: pip install -e ".[jax,torch,dev]"
- run: pytest
- run: pytest --cov=spacecore --cov-report=term-missing --cov-fail-under=70
- run: python scripts/jit_audit.py --check
- run: ruff check .
- run: ruff check --select D spacecore/ || true
- run: python scripts/docstring_audit.py || true

publish:
if: startsWith(github.ref, 'refs/tags/')
Expand Down
184 changes: 184 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# Changelog

All notable changes to SpaceCore are documented in this file.

The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and the project adheres to [Semantic Versioning](https://semver.org/).

## [0.2.0]

SpaceCore 0.2.0 is a major API expansion. The backend layer now sits on the
Array API standard. Operators gained a lazy algebra with adjoint views,
composition, sums, and scaling. A new `Functional` hierarchy provides
scalar-valued maps with gradients and pull-backs. A new `spacecore.linalg`
module ships four JIT-compatible iterative solvers. Spaces, operators, and
functionals share a single validation pattern via `checked_method`, and the
public API is documented to numpydoc standard with doctest coverage.

This release introduces breaking changes; see [Migration](#migration-from-01x).

### Added

#### Backend

- Migrated `BackendOps` to the Array API standard via `array-api-compat`.
- `CuPyOps` and the `cupy` backend family as an optional install
(`pip install 'spacecore[cupy]'`).
- `BackendOps.is_complex_dtype` for backend-aware complex detection.
- `BackendOps.real_dtype` for extracting the real dtype matching a complex one.
- Broadened backend coverage for array creation, dtype conversion, sparse
conversion, indexing, reductions, linear algebra, loop primitives
(`fori_loop`, `while_loop`, `cond`), tree helpers, and vectorized mapping.
- JAX pytree registration for operator, space, and functional types so they
pass through `jax.jit`, `jax.vmap`, and `jax.grad` boundaries.

#### Context and checking

- Public free-function API in `spacecore._contextual`: `set_context`,
`get_context`, `resolve_context_priority`, `register_ops`, and the
resolution-policy accessors.
- Extended `checked_method` to support validation against `self` and multiple
input argument positions.
- Reusable space-validation checks: backend, dtype, shape, Hermitian,
square-matrix, product-structure, and product-component checks. Documented
at `docs/source/design/checking_policy.rst`.

#### Spaces

- `BatchSpace` for batched elements with explicit batch shape and batch-axis
metadata.

#### Linear operators

- Lazy operator algebra:
- `A @ B` composes operators.
- `A + B` sums operators.
- `alpha * A` scales an operator.
- `A.H` returns a cached adjoint view satisfying `A.H.H is A`.
- Algebraic simplification eliminates `I`, `Zero`, `alpha = 0`, `alpha = 1`,
and flattens nested sums.
- New operator types: `IdentityLinOp`, `ZeroLinOp`, `MatrixFreeLinOp`,
`DiagonalLinOp`.
- Structural `LinOp.is_hermitian()` reporting `True`, `False`, or `None`
(unknown) without applying incorrect Euclidean assumptions for custom space
geometries.
- `LinOp.to_dense()` for materializing operators as backend arrays.
- Product-structured operators and batched lifting:
- `ProductLinOp`
- `BlockDiagonalLinOp`
- `StackedLinOp`
- `SumToSingleLinOp`
- `vapply` / `rvapply` paths for batched operator application.

#### Functionals

- `Functional` as an abstract base for scalar-valued maps on spaces, with
`value`, `grad`, `hess_apply`, and batched counterparts.
- Linear functionals: `LinearFunctional`, `InnerProductFunctional`,
`MatrixFreeLinearFunctional`.
- Quadratic forms: `QuadraticForm`, `LinOpQuadraticForm`.
- `Functional.compose` and `ComposedFunctional` for pull-backs along linear
operators, with specializations that preserve the concrete functional type
when possible.

#### Linear algebra

The `spacecore.linalg` module is new in 0.2.0. It provides JIT-compatible
iterative solvers and structured result types.

- Iterative solvers:
- `cg` for Hermitian positive-definite systems.
- `lsqr` for rectangular least-squares problems.
- `power_iteration` for dominant-eigenpair estimates of a `LinOp` or
`QuadraticForm`.
- `lanczos_smallest` for smallest-Ritz-eigenpair estimates of Hermitian
operators.
- `expm_multiply` for Krylov matrix-exponential actions `exp(t A) v` on
Hermitian operators, with complex `t` supported for Schrodinger-type
evolution.
- Structured result types `CGResult`, `LSQRResult`, `PowerIterationResult`,
`LanczosResult`, and `ExpmMultiplyResult`, each carrying convergence
diagnostics and a compact `__repr__`.
- Solvers are geometry-aware: norms, inner products, and the default initial
vector use `Space.inner` and `Space.norm` rather than assuming Euclidean
geometry. This makes the solvers correct on custom inner products such as
RKHS or weighted spaces.

#### Documentation

- Numpydoc-standard public docstrings with runnable doctests for solvers,
spaces, operators, functionals, backends, and contextual helpers.
- API reference pages for backend ops, spaces, linear operators, functionals,
and linear algebra.
- JAX integration design note at `docs/source/design/jax_integration.rst`
covering trace-time operator algebra and recommended JIT usage.
- Tutorials for backend operations, linear operators, and matrix-free linalg
workflows.

#### Tooling

- Optional dependency groups: `[jax]`, `[torch]`, `[cupy]`, `[examples]`,
`[docs]`, `[dev]`.
- Explicit `__all__` at the top level covering new backends, operators,
functionals, solvers, result types, validation checks, and contextual
helpers.
- CI runs a JIT-traceability audit in `--check` mode and enforces a 70%
coverage floor via `pytest-cov`.
- Cross-backend tests covering NumPy, JAX, Torch, and optional CuPy.

### Changed

- Restructured `_contextual` to hide implementation details while preserving
the public API via free functions.
- Replaced manual `if self._enable_checks` guards with `checked_method` across
`Space`, `LinOp`, and `Functional`. Inline guards are now reserved for
non-membership checks such as dense-array assertions and custom output-shape
checks.
- Improved `VectorSpace`, `HermitianSpace`, and `ProductSpace` conversion
behavior, validation, batching support, and docstrings.
- Improved linear-operator equality, representation, conversion, and JAX
pytree behavior.
- `spacecore.__version__` now resolves from package metadata via
`importlib.metadata` instead of a hand-maintained constant.
- Bumped the package version to `0.2.0`.

### Fixed

- `LinOp.__eq__` returns `NotImplemented` instead of raising
`NotImplementedError` on the base class, so `op == None` and
`op in some_list` no longer raise.
- `DenseLinOp.is_hermitian` and `SparseLinOp.is_hermitian` return `None` for
custom space geometries instead of applying an incorrect Euclidean
matrix-symmetry test.

### Migration from 0.1.x

- `BackendOps.eps` is now a method `eps(dtype)` rather than a property.
Callers must pass a dtype, typically `ctx.dtype`.
- The implementation attribute `DenseLinOp.A` is now a `cached_property`
backed by `_A`. The public attribute access `op.A` is unchanged.
- `LinOp.__eq__` returns `NotImplemented` rather than raising; downstream code
relying on the exception should be updated to handle the new behavior.
- Several module-internal helpers in `spacecore._contextual` moved to private
modules. Use the public functions re-exported from `spacecore._contextual`
(`set_context`, `get_context`, `resolve_context_priority`, `register_ops`,
`set_resolution_policy`, and the dtype-policy accessors) rather than
importing from internal modules.

### Known limitations

- `cg`, `lsqr`, and `power_iteration` do not structurally validate operator
properties (positive-definiteness, full Hermiticity) and may silently
produce incorrect results on inputs that violate their preconditions. See
each function's `Notes` section for details.
- Operator algebra runs Python-level simplification at construction time. For
maximum JIT efficiency, assemble operator expressions outside the
`jax.jit` boundary; see the JAX integration design note.
- `MatrixFreeLinOp` stores its callables in pytree auxiliary data.
Constructing one inside a JIT-traced function with a new lambda each call
triggers retracing. Construct outside the traced region with a stable
callable reference.
- The CuPy backend is provided as a preview. Coverage of non-standard
operations and sparse handling may evolve in a subsequent release.

[0.2.0]: https://github.com/Pavlo3P/SpaceCore/releases/tag/v0.2.0
Loading
Loading