lx-ai-core 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AG-Lux
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: lx-ai-core
3
+ Version: 0.0.1
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Intended Audience :: Science/Research
6
+ Classifier: Programming Language :: Python :: 3.12
7
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
8
+ Requires-Dist: pydantic>=2.10
9
+ Requires-Dist: pyyaml>=6.0
10
+ Requires-Dist: pytest>=8.3 ; extra == 'dev'
11
+ Requires-Dist: numpy>=2.2 ; extra == 'dev'
12
+ Requires-Dist: pillow>=11.0 ; extra == 'dev'
13
+ Requires-Dist: torch>=2.5,<3 ; extra == 'dev'
14
+ Requires-Dist: make>=0.1.6.post2 ; extra == 'dev'
15
+ Requires-Dist: maturin>=1.13.1 ; extra == 'dev'
16
+ Requires-Dist: ziglang>=0.16.0 ; extra == 'dev'
17
+ Requires-Dist: numpy>=2.2 ; extra == 'torch'
18
+ Requires-Dist: pillow>=11.0 ; extra == 'torch'
19
+ Requires-Dist: torch>=2.5,<3 ; extra == 'torch'
20
+ Provides-Extra: dev
21
+ Provides-Extra: torch
22
+ License-File: LICENSE
23
+ Summary: Standalone local AI runtime core for LX medical model workflows.
24
+ Author: WG Lux
25
+ Requires-Python: >=3.12, <3.13
26
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
27
+
28
+ # lx-active-learning
29
+
30
+ Standalone AI runtime and deployment core for the LX ecosystem.
31
+
32
+ This is a inference module that provides active learning functionalities on data imported into endoreg-db. It provides optimizations for various types of models and will be ready to host models and efficiently run them while actively updating their weights if that is possible.
33
+
34
+ This package intentionally contains no Django models, no Celery tasks, no direct
35
+ database access, and no network transfer logic. Integrating callers such as
36
+ `endoreg-db` own storage, provenance persistence, queueing, and security policy.
37
+
@@ -0,0 +1,9 @@
1
+ # lx-active-learning
2
+
3
+ Standalone AI runtime and deployment core for the LX ecosystem.
4
+
5
+ This is a inference module that provides active learning functionalities on data imported into endoreg-db. It provides optimizations for various types of models and will be ready to host models and efficiently run them while actively updating their weights if that is possible.
6
+
7
+ This package intentionally contains no Django models, no Celery tasks, no direct
8
+ database access, and no network transfer logic. Integrating callers such as
9
+ `endoreg-db` own storage, provenance persistence, queueing, and security policy.
@@ -0,0 +1,58 @@
1
+ [project]
2
+ name = "lx-ai-core"
3
+ version = "0.0.1"
4
+ description = "Standalone local AI runtime core for LX medical model workflows."
5
+ readme = "README.md"
6
+ requires-python = ">=3.12,<3.13"
7
+ authors = [
8
+ { name = "WG Lux" },
9
+ ]
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Intended Audience :: Science/Research",
13
+ "Programming Language :: Python :: 3.12",
14
+ "Topic :: Scientific/Engineering :: Medical Science Apps.",
15
+ ]
16
+ dependencies = [
17
+ "pydantic>=2.10",
18
+ "pyyaml>=6.0",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ torch = [
23
+ "numpy>=2.2",
24
+ "pillow>=11.0",
25
+ "torch>=2.5,<3",
26
+ ]
27
+
28
+ dev = [
29
+ "pytest>=8.3",
30
+ "numpy>=2.2",
31
+ "pillow>=11.0",
32
+ "torch>=2.5,<3",
33
+ "make>=0.1.6.post2",
34
+ "maturin>=1.13.1",
35
+ "ziglang>=0.16.0",
36
+ ]
37
+
38
+ [project.scripts]
39
+ lx-ai-core = "lx_ai_core.cli:main"
40
+
41
+ [build-system]
42
+ requires = ["maturin>=1.7,<2"]
43
+ build-backend = "maturin"
44
+
45
+ [tool.maturin]
46
+ manifest-path = "rust/lx_ai_core_native/Cargo.toml"
47
+ module-name = "lx_ai_core._native"
48
+ bindings = "pyo3"
49
+ python-source = "src"
50
+ features = ["pyo3/extension-module"]
51
+ include = [
52
+ { path = "LICENSE", format = "sdist" },
53
+ ]
54
+
55
+ [tool.pytest.ini_options]
56
+ pythonpath = ["src"]
57
+ testpaths = ["tests"]
58
+ addopts = "-q"
@@ -0,0 +1,180 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.5.0"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
10
+
11
+ [[package]]
12
+ name = "cfg-if"
13
+ version = "1.0.4"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
16
+
17
+ [[package]]
18
+ name = "heck"
19
+ version = "0.5.0"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
22
+
23
+ [[package]]
24
+ name = "indoc"
25
+ version = "2.0.7"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
28
+ dependencies = [
29
+ "rustversion",
30
+ ]
31
+
32
+ [[package]]
33
+ name = "libc"
34
+ version = "0.2.186"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
37
+
38
+ [[package]]
39
+ name = "lx_ai_core_native"
40
+ version = "0.1.0"
41
+ dependencies = [
42
+ "pyo3",
43
+ ]
44
+
45
+ [[package]]
46
+ name = "memoffset"
47
+ version = "0.9.1"
48
+ source = "registry+https://github.com/rust-lang/crates.io-index"
49
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
50
+ dependencies = [
51
+ "autocfg",
52
+ ]
53
+
54
+ [[package]]
55
+ name = "once_cell"
56
+ version = "1.21.4"
57
+ source = "registry+https://github.com/rust-lang/crates.io-index"
58
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
59
+
60
+ [[package]]
61
+ name = "portable-atomic"
62
+ version = "1.13.1"
63
+ source = "registry+https://github.com/rust-lang/crates.io-index"
64
+ checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
65
+
66
+ [[package]]
67
+ name = "proc-macro2"
68
+ version = "1.0.106"
69
+ source = "registry+https://github.com/rust-lang/crates.io-index"
70
+ checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
71
+ dependencies = [
72
+ "unicode-ident",
73
+ ]
74
+
75
+ [[package]]
76
+ name = "pyo3"
77
+ version = "0.22.6"
78
+ source = "registry+https://github.com/rust-lang/crates.io-index"
79
+ checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884"
80
+ dependencies = [
81
+ "cfg-if",
82
+ "indoc",
83
+ "libc",
84
+ "memoffset",
85
+ "once_cell",
86
+ "portable-atomic",
87
+ "pyo3-build-config",
88
+ "pyo3-ffi",
89
+ "pyo3-macros",
90
+ "unindent",
91
+ ]
92
+
93
+ [[package]]
94
+ name = "pyo3-build-config"
95
+ version = "0.22.6"
96
+ source = "registry+https://github.com/rust-lang/crates.io-index"
97
+ checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38"
98
+ dependencies = [
99
+ "once_cell",
100
+ "target-lexicon",
101
+ ]
102
+
103
+ [[package]]
104
+ name = "pyo3-ffi"
105
+ version = "0.22.6"
106
+ source = "registry+https://github.com/rust-lang/crates.io-index"
107
+ checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636"
108
+ dependencies = [
109
+ "libc",
110
+ "pyo3-build-config",
111
+ ]
112
+
113
+ [[package]]
114
+ name = "pyo3-macros"
115
+ version = "0.22.6"
116
+ source = "registry+https://github.com/rust-lang/crates.io-index"
117
+ checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453"
118
+ dependencies = [
119
+ "proc-macro2",
120
+ "pyo3-macros-backend",
121
+ "quote",
122
+ "syn",
123
+ ]
124
+
125
+ [[package]]
126
+ name = "pyo3-macros-backend"
127
+ version = "0.22.6"
128
+ source = "registry+https://github.com/rust-lang/crates.io-index"
129
+ checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe"
130
+ dependencies = [
131
+ "heck",
132
+ "proc-macro2",
133
+ "pyo3-build-config",
134
+ "quote",
135
+ "syn",
136
+ ]
137
+
138
+ [[package]]
139
+ name = "quote"
140
+ version = "1.0.45"
141
+ source = "registry+https://github.com/rust-lang/crates.io-index"
142
+ checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
143
+ dependencies = [
144
+ "proc-macro2",
145
+ ]
146
+
147
+ [[package]]
148
+ name = "rustversion"
149
+ version = "1.0.22"
150
+ source = "registry+https://github.com/rust-lang/crates.io-index"
151
+ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
152
+
153
+ [[package]]
154
+ name = "syn"
155
+ version = "2.0.117"
156
+ source = "registry+https://github.com/rust-lang/crates.io-index"
157
+ checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
158
+ dependencies = [
159
+ "proc-macro2",
160
+ "quote",
161
+ "unicode-ident",
162
+ ]
163
+
164
+ [[package]]
165
+ name = "target-lexicon"
166
+ version = "0.12.16"
167
+ source = "registry+https://github.com/rust-lang/crates.io-index"
168
+ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
169
+
170
+ [[package]]
171
+ name = "unicode-ident"
172
+ version = "1.0.24"
173
+ source = "registry+https://github.com/rust-lang/crates.io-index"
174
+ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
175
+
176
+ [[package]]
177
+ name = "unindent"
178
+ version = "0.2.4"
179
+ source = "registry+https://github.com/rust-lang/crates.io-index"
180
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
@@ -0,0 +1,11 @@
1
+ [package]
2
+ name = "lx_ai_core_native"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [lib]
7
+ name = "lx_ai_core_native"
8
+ crate-type = ["cdylib"]
9
+
10
+ [dependencies]
11
+ pyo3 = { version = "0.22", features = ["extension-module"] }
@@ -0,0 +1,94 @@
1
+ use pyo3::prelude::*;
2
+
3
+ #[pyfunction]
4
+ #[pyo3(signature = (values, threshold, min_length=None))]
5
+ fn threshold_runs(values: Vec<f64>, threshold: f64, min_length: Option<usize>) -> PyResult<Vec<(usize, usize)>> {
6
+ let min_len = min_length.unwrap_or(1).max(1);
7
+ let mut runs: Vec<(usize, usize)> = Vec::new();
8
+ let mut start: Option<usize> = None;
9
+
10
+ for (index, value) in values.iter().enumerate() {
11
+ if *value >= threshold {
12
+ if start.is_none() {
13
+ start = Some(index);
14
+ }
15
+ } else if let Some(run_start) = start {
16
+ let end = index - 1;
17
+ if end - run_start + 1 >= min_len {
18
+ runs.push((run_start, end));
19
+ }
20
+ start = None;
21
+ }
22
+ }
23
+
24
+ if let Some(run_start) = start {
25
+ let end = values.len() - 1;
26
+ if end - run_start + 1 >= min_len {
27
+ runs.push((run_start, end));
28
+ }
29
+ }
30
+
31
+ Ok(runs)
32
+ }
33
+
34
+ #[pyfunction]
35
+ fn smooth_scores(values: Vec<f64>, window: usize) -> PyResult<Vec<f64>> {
36
+ if window <= 1 {
37
+ return Ok(values);
38
+ }
39
+ let radius = window / 2;
40
+ let mut out: Vec<f64> = Vec::with_capacity(values.len());
41
+ for index in 0..values.len() {
42
+ let start = index.saturating_sub(radius);
43
+ let end = (index + radius + 1).min(values.len());
44
+ let mut total = 0.0;
45
+ for value in values[start..end].iter() {
46
+ total += *value;
47
+ }
48
+ out.push(total / ((end - start) as f64));
49
+ }
50
+ Ok(out)
51
+ }
52
+
53
+ #[pyfunction]
54
+ fn mask_rle_encode(mask: Vec<u8>) -> PyResult<Vec<usize>> {
55
+ let mut counts: Vec<usize> = Vec::new();
56
+ let mut current: u8 = 0;
57
+ let mut run_len: usize = 0;
58
+
59
+ for raw in mask.iter() {
60
+ let value = if *raw == 0 { 0 } else { 1 };
61
+ if value == current {
62
+ run_len += 1;
63
+ } else {
64
+ counts.push(run_len);
65
+ current = value;
66
+ run_len = 1;
67
+ }
68
+ }
69
+
70
+ counts.push(run_len);
71
+ Ok(counts)
72
+ }
73
+
74
+ #[pyfunction]
75
+ fn mask_rle_decode(counts: Vec<usize>) -> PyResult<Vec<u8>> {
76
+ let mut out: Vec<u8> = Vec::new();
77
+ let mut value: u8 = 0;
78
+ for count in counts.iter() {
79
+ for _ in 0..*count {
80
+ out.push(value);
81
+ }
82
+ value = 1 - value;
83
+ }
84
+ Ok(out)
85
+ }
86
+
87
+ #[pymodule]
88
+ fn _native(m: &Bound<'_, PyModule>) -> PyResult<()> {
89
+ m.add_function(wrap_pyfunction!(threshold_runs, m)?)?;
90
+ m.add_function(wrap_pyfunction!(smooth_scores, m)?)?;
91
+ m.add_function(wrap_pyfunction!(mask_rle_encode, m)?)?;
92
+ m.add_function(wrap_pyfunction!(mask_rle_decode, m)?)?;
93
+ Ok(())
94
+ }
@@ -0,0 +1,131 @@
1
+ from importlib.metadata import PackageNotFoundError, version as _package_version
2
+
3
+ from lx_ai_core.contracts import (
4
+ BackendName,
5
+ InferenceInput,
6
+ InferenceRequest,
7
+ InferenceResult,
8
+ LatentMetric,
9
+ LatentNormalization,
10
+ LatentSpaceSpec,
11
+ LatentVector,
12
+ MaskArtifact,
13
+ Modality,
14
+ ModelSpec,
15
+ RunMetrics,
16
+ Score,
17
+ ScoreVector,
18
+ TaskKind,
19
+ TemporalSegment,
20
+ )
21
+ from lx_ai_core.active_learning import (
22
+ ActiveLearningCandidate,
23
+ ActiveLearningConfig,
24
+ ActiveLearningSelection,
25
+ ScoredActiveLearningCandidate,
26
+ select_active_learning_candidates,
27
+ select_active_learning_frame_indices,
28
+ )
29
+ from lx_ai_core.latent import (
30
+ build_latent_vectors,
31
+ l2_normalize,
32
+ latent_space_from_options,
33
+ mean_pool_latent_vectors,
34
+ metadata_sequence,
35
+ normalize_latent_rows,
36
+ validate_latent_rows,
37
+ )
38
+ from lx_ai_core.postprocessing import (
39
+ hysteresis_runs,
40
+ smooth_scores,
41
+ temporal_segments_from_scores,
42
+ threshold_runs,
43
+ )
44
+ from lx_ai_core.runtime import (
45
+ ModelCache,
46
+ ModelLoadError,
47
+ RuntimeRegistry,
48
+ UnsupportedBackendError,
49
+ UnsupportedTaskError,
50
+ default_registry,
51
+ run_inference,
52
+ )
53
+ from lx_ai_core.temporal import (
54
+ binary_markov_smooth_scores,
55
+ normalize_transition_matrix,
56
+ state_path_to_segments,
57
+ sticky_transition_matrix,
58
+ viterbi_decode_state_scores,
59
+ )
60
+ from lx_ai_core.training import (
61
+ TrainingArtifact,
62
+ TrainingArtifactKind,
63
+ TrainingDatasetManifest,
64
+ TrainingParameters,
65
+ TrainingRequest,
66
+ TrainingResult,
67
+ TrainingSample,
68
+ TrainingStatus,
69
+ )
70
+
71
+ try:
72
+ __version__ = _package_version("lx-ai-core")
73
+ except PackageNotFoundError:
74
+ __version__ = "0.0.0+unknown"
75
+
76
+ __all__ = [
77
+ "ActiveLearningCandidate",
78
+ "ActiveLearningConfig",
79
+ "ActiveLearningSelection",
80
+ "BackendName",
81
+ "InferenceInput",
82
+ "InferenceRequest",
83
+ "InferenceResult",
84
+ "LatentMetric",
85
+ "LatentNormalization",
86
+ "LatentSpaceSpec",
87
+ "LatentVector",
88
+ "MaskArtifact",
89
+ "ModelCache",
90
+ "ModelLoadError",
91
+ "Modality",
92
+ "ModelSpec",
93
+ "RunMetrics",
94
+ "RuntimeRegistry",
95
+ "ScoredActiveLearningCandidate",
96
+ "Score",
97
+ "ScoreVector",
98
+ "TaskKind",
99
+ "TemporalSegment",
100
+ "TrainingArtifact",
101
+ "TrainingArtifactKind",
102
+ "TrainingDatasetManifest",
103
+ "TrainingParameters",
104
+ "TrainingRequest",
105
+ "TrainingResult",
106
+ "TrainingSample",
107
+ "TrainingStatus",
108
+ "UnsupportedBackendError",
109
+ "UnsupportedTaskError",
110
+ "__version__",
111
+ "binary_markov_smooth_scores",
112
+ "build_latent_vectors",
113
+ "default_registry",
114
+ "hysteresis_runs",
115
+ "l2_normalize",
116
+ "latent_space_from_options",
117
+ "mean_pool_latent_vectors",
118
+ "metadata_sequence",
119
+ "normalize_transition_matrix",
120
+ "normalize_latent_rows",
121
+ "run_inference",
122
+ "select_active_learning_candidates",
123
+ "select_active_learning_frame_indices",
124
+ "smooth_scores",
125
+ "state_path_to_segments",
126
+ "sticky_transition_matrix",
127
+ "temporal_segments_from_scores",
128
+ "threshold_runs",
129
+ "validate_latent_rows",
130
+ "viterbi_decode_state_scores",
131
+ ]