Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.11", "3.12", "3.13", "3.14"]
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
1.3.0.dev0
51 changes: 51 additions & 0 deletions docs/python314-numeric-20260930.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Python 3.14 numerical checkpoint
================================

Parent integration owner, 2026-09-30. PR1 source base is
29f0a327d2069324f13d0c6fa0809a5c7566a6d4. No production code or dependency
installation changed. Existing Python 3.14.7 and installed scientific packages
were used directly with this isolated worktree's ``src`` on PYTHONPATH.

Actual packages: JAX/JAXlib0.9.2, NumPy2.5.3, SciPy1.18.1,
scikit-image0.26.0, Pydantic2.13.5, pooch1.9.0. CPU platform, BLAS/OpenMP
threads1, disabled pytest plugin autoload and source bytecode/cache writing.
Fit process affinity is one CPU. No datasets, downloads, providers or GUI.

Real checks
-----------

* Existing public JAX inverse-DCT/SciPy comparisons and odd/even 1D/2D/3D
round trips: 3PASS,9.83s pytest,10.72s process,545160KiB peakRSS.
* New bounded 24-observation32x32 synthetic checks: 3PASS,7.83s pytest,
9.15s process,450640KiB peakRSS. Real 2D/3D fit-transform preserves
floating measurement units and shapes, fitted field RMSE<0.15, zero
disabled darkfield, saved model/settings/profiles reload and correction
agree. Stationary biology produces materially worse recovered shading
than moving objects, exposing identifiability rather than promising it.

Original logs/XML and process resource measurements are retained at
``/home/ts/wt/openhcs-issue-batch-20260929/basicpy-parent-numeric-20260930/``.
Each process exited0. Final published-test rerun: 6PASS,13.96s pytest,
15.97s process,690508KiB peakRSS, zero swaps, covering both suites in one
process. The tests use existing model declared attributes directly (BOUND-7).
No new model, field store,
registry, solver, fallback or compatibility layer is introduced (BOUND-2,
IMPL-13, TIME-1). Tests exercise the original BaSiC and JaxDCT owners.

Reproduce from this worktree using the existing interpreter::

PYTHONPATH=$PWD/src PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 JAX_PLATFORMS=cpu \
OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 \
XLA_FLAGS=--xla_cpu_multi_thread_eigen=false \
python3.14 -B -m pytest -p no:cacheprovider \
tests/test_public_jax_dct.py tests/test_python314_fit.py -q

Boundaries
----------

This proves real import and bounded CPU numerical behavior on the existing
Python3.14 environment, including persisted profiles. It does not prove a
fresh dependency resolver, minimum-version matrix, CUDA, autotuning, fitted
additive darkfield, real acquisitions, or OpenHCS compiled/MCP execution.
No installed user entrypoint or blind harness changed. PR217 and paired
ArrayBridge integration remain separate acceptance boundaries.
95 changes: 95 additions & 0 deletions docs/python314-openhcs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# JAX prototype modernization for OpenHCS

Current parent checkpoint: real Python 3.14 CPU fits, persisted model reload,
stationary-signal control and public DCT comparisons passed. See the canonical
[numerical receipt](python314-numeric-20260930.rst). Nothing has been installed;
OpenHCS compiled/MCP acceptance is still separate.

The following records the historical 2026-09-29 source-only checkpoint and its
then-pending checks; it must not be read as today's package availability.
Original integration owner: Linnaeus (OpenHCS backend/dependencies, issue
[OpenHCS #213](https://github.com/OpenHCSDev/openhcs/issues/213)).

## Provenance and API

Reuses the clean `trissim/BaSiCPy` JAX prototype at `ae2c647`, including Tristan's
`fc9da06` dependency change and `ae2c647` public `functools.wraps` change.
The LADMAP/approximate optimization and correction formula are not replaced.
`BaSiC.fit_transform(images, timelapse=False)`, `FittingMode`, `flatfield`,
`darkfield`, model settings and saved profile names retain their existing owners.
Images are independent observations `(N,Y,X)` or `(N,Z,Y,X)`, never a mixture
of channels. No pseudo-BaSiC algorithm or permissive alternate import is added.

Current [peng-lab 2.x](https://github.com/peng-lab/BaSiCPy) uses PyTorch and a
different model/API, including `is_timelapse` rather than `timelapse`.
Its [PR #174](https://github.com/peng-lab/BaSiCPy/pull/174) already addresses
modern SciPy for that implementation; [PR #170](https://github.com/peng-lab/BaSiCPy/pull/170)
targets Python 3.12/3.13. This fork preserves the existing JAX implementation
instead of duplicating those PyTorch changes or accidentally calling its API.

## Candidate dependency matrix

The running OpenHCS venv is Python 3.12.3 with JAX/JAXlib 0.9.2; BaSiCPy is not
installed. `/usr/bin/python3.14` is Python 3.14.7, linux-x86_64. Neither this
fork's dependencies nor its model have been imported on 3.14 yet.

| Owner | Source/metadata basis | Draft constraint |
| --- | --- | --- |
| JAX | [0.9.2 metadata](https://pypi.org/pypi/jax/0.9.2/json); [JAXlib cp314 wheels](https://pypi.org/pypi/jaxlib/0.9.2/json) | `jax>=0.9.2,<0.10`; JAX owns matching JAXlib |
| NumPy | JAX 0.9.2 requires NumPy 2 | `numpy>=2.0` |
| SciPy | [1.16.2 cp314 wheels](https://pypi.org/pypi/scipy/1.16.2/json) | `scipy>=1.16.2`; no old `scipy<1.13` cap |
| scikit-image | [0.26.0 cp314 wheels](https://pypi.org/pypi/scikit-image/0.26.0/json); 0.25.2 has none | `scikit-image>=0.26.0,<0.27` |
| Pydantic | [2.12 adds Python 3.14 support](https://pydantic.dev/articles/pydantic-v2-12-release) | `pydantic>=2.12,<3` |

Wheel availability and syntax are not import, numerical, GPU, or application
readiness evidence. These ranges are reviewable candidates pending a real
isolated Python 3.14 resolve/import/fit. Autotuning's old Hyperactive dependency
is owned by the existing `autotune` method and optional extra, not imported to
perform an ordinary fit. Autotuning is not part of the readiness claim.

## Focused ownership audit

Scope: changed JAX inverse-DCT owner, model/Pydantic boundary, dependency/test
configuration. This is source/AST/catalog review, not a full NRA proof/scan.

- IMPL-13 / TIME-1: existing `JaxDCT` now delegates to JAX's
[public `idctn`](https://docs.jax.dev/en/latest/_autosummary/jax.scipy.fft.idctn.html).
The copied private-JAX helper and its tests are deleted in place; no fallback.
- TIME-6: removed nonexistent module-level DCT exports, not new aliases.
- BOUND-2: model settings and JAX pytree metadata use Pydantic's current
`model_dump`/`model_copy`/`model_dump_json`, with existing model types retained.
- New-case check: another DCT backend belongs to the existing `DCT` family and
derived `DCT_BACKENDS`. It needs no caller-side roster or copied inverse-DCT
implementation. A new model field remains declared on `BaSiC`/`BaseFit`; their
dumps project it without another schema list. The wrapper must deliberately
expose a useful new user parameter, not mirror the entire model.

Inherited resize/fitting-mode dispatch and the unfinished historical CLI are
outside this focused patch. No claim of a globally clean codebase is made.

## Evidence and pending acceptance

Executed with no numerical imports or environment changes:

```
/usr/bin/python3.14 scripts/check_source_contracts.py
```

Four source tests pass (0.052 seconds): syntax, public inverse-DCT owner,
dependency contract and current Pydantic owner API. This does not execute DCT
or fit. `tests/test_public_jax_dct.py` contains the real SciPy comparison and
round-trip regression for odd/even 1D/2D/3D arrays; execution is pending.

Next shared slot, after parent #151/#212 acceptance and explicit handoff:

1. Verify isolated import paths, resolve actual cp314 dependencies and import.
2. Bound CPU threads, use synthetic independent same-channel shaded fields,
run real DCT regressions and fit-transform; inspect both fitted fields and
report elapsed time, peak/RSS/PSS/private/swap memory.
3. Compare recovered shading and moving synthetic objects; include a stationary
object negative control to expose biological leakage/identifiability limits.
4. Verify paired OpenHCS compiled execution and real MCP discovery/signature/
execute/artifact inspection. No blind biology inputs or installed changes.

All PRs remain draft; no installation, Python 3.14 fit, CUDA support or
OpenHCS entrypoint acceptance is claimed here.
14 changes: 2 additions & 12 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
"""Nox automation file."""

import platform
import shutil
from pathlib import Path

from nox import Session, session

python_versions = ["3.11", "3.10", "3.9", "3.8"]
python_versions = ["3.11", "3.12", "3.13", "3.14"]


@session(python=python_versions)
def tests(session: Session) -> None:
"""Run the test suite."""
if platform.system() == "Windows":
session.install(
"jax[cpu]==0.4.11",
"-f",
"https://whls.blob.core.windows.net/unstable/index.html",
"--use-deprecated",
"legacy-resolver",
)
session.install("ml-dtypes==0.2.0")
session.install(".")
session.install(".[autotune]")
session.install(
"dask",
"pytest",
Expand Down
60 changes: 60 additions & 0 deletions scripts/check_source_contracts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Light source-only checks; deliberately do not import numerical backends."""

from __future__ import annotations

import ast
import configparser
from pathlib import Path
import unittest

ROOT = Path(__file__).resolve().parents[1]


class SourceContractTests(unittest.TestCase):
def test_source_parses_on_running_interpreter(self):
for path in (ROOT / "src").rglob("*.py"):
with self.subTest(path=path.relative_to(ROOT)):
ast.parse(path.read_text(), filename=str(path))

def test_inverse_dct_uses_public_owner(self):
path = ROOT / "src/basicpy/tools/dct_tools.py"
tree = ast.parse(path.read_text())
owner = next(
node for node in tree.body
if isinstance(node, ast.ClassDef) and node.name == "JaxDCT"
)
inverse = next(
node for node in owner.body
if isinstance(node, ast.FunctionDef) and node.name == "idctnd"
)
self.assertEqual(ast.unparse(inverse.body[0].value.func), "jax.scipy.fft.idctn")
self.assertFalse((ROOT / "src/basicpy/tools/_jax_idct.py").exists())
for path in (ROOT / "src").rglob("*.py"):
for node in ast.walk(ast.parse(path.read_text())):
if isinstance(node, ast.ImportFrom):
self.assertFalse((node.module or "").startswith("jax._"), path)
self.assertNotIn("_jax_idct", node.module or "", path)

def test_python314_dependency_contract(self):
config = configparser.ConfigParser()
config.read(ROOT / "setup.cfg")
dependencies = config["options"]["install_requires"].split()
self.assertEqual(config["options"]["python_requires"], ">=3.11")
self.assertIn("jax>=0.9.2,<0.10", dependencies)
self.assertIn("scipy>=1.16.2", dependencies)
self.assertIn("pydantic>=2.12.0,<3.0.0", dependencies)
self.assertFalse(any(dep.startswith("hyperactive") for dep in dependencies))
self.assertIn("autotune", config["options.extras_require"])

def test_supported_pydantic_owner_api(self):
for relative in ("src/basicpy/basicpy.py", "src/basicpy/_jax_routines.py"):
tree = ast.parse((ROOT / relative).read_text())
for node in ast.walk(tree):
if isinstance(node, ast.Attribute):
self.assertNotIn(node.attr, ("dict", "json", "__fields__"), relative)
if isinstance(node, ast.ClassDef):
self.assertNotEqual(node.name, "Config", relative)


if __name__ == "__main__":
unittest.main(verbosity=2)
24 changes: 14 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = file: VERSION
description = A python package for background and shading correction of optical microscopy images
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/peng-lab/BaSiCPy
url = https://github.com/OpenHCSDev/BaSiCPy
author = Nicholas Schaub, Tim Morello, Tingying Peng, Yohsuke T. Fukai
author_email = nick.schaub@nih.gov, timothy.morello@downstate.edu, tingying.peng@helmholtz-muenchen.de, ysk@yfukai.net
license = MIT
Expand All @@ -15,22 +15,24 @@ classifiers =
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Programming Language :: Python :: 3.14
keywords = background shading flatfield darkfield biology optical microscopy image illumination
project_urls =
Bug Tracker = https://github.com/peng-lab/BaSiCPy/issues
Bug Tracker = https://github.com/OpenHCSDev/BaSiCPy/issues

[options]
packages = find:
install_requires =
hyperactive>=4.4.0
jax>=0.4.38,<0.6.0
jaxlib>=0.4.38,<0.6.0
numpy
jax>=0.9.2,<0.10
numpy>=2.0
pooch
pydantic>=2.7.0,<3.0.0
scikit-image
scipy<1.13
python_requires = >=3.8
pydantic>=2.12.0,<3.0.0
scikit-image>=0.26.0,<0.27
scipy>=1.16.2
python_requires = >=3.11
package_dir =
= src

Expand All @@ -42,6 +44,8 @@ console_scripts =
basicpy = basicpy.__main__:main

[options.extras_require]
autotune =
hyperactive>=4.4.0,<5
dask =
dask
dev =
Expand Down
8 changes: 3 additions & 5 deletions src/basicpy/_jax_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from jax import jit, lax
from jax import numpy as jnp
from jax.tree_util import register_pytree_node_class
from pydantic import BaseModel, Field, PrivateAttr
from pydantic import BaseModel, ConfigDict, Field, PrivateAttr

from basicpy.tools.dct_tools import JaxDCT

Expand Down Expand Up @@ -57,9 +57,7 @@ class BaseFit(BaseModel):
description="Maximum number of iterations for single optimization.",
)

class Config:
frozen = True
extra = "ignore"
model_config = ConfigDict(frozen=True, extra="ignore")

def _cond(self, vals):
k = vals[0]
Expand Down Expand Up @@ -200,7 +198,7 @@ def fit_baseline(
def tree_flatten(self):
# all of the fields are treated as "static" values for JAX
children = []
aux_data = self.dict()
aux_data = self.model_dump()
return (children, aux_data)

@classmethod
Expand Down
Loading
Loading