flux-constraint 0.1.0__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.
- flux_constraint-0.1.0/PKG-INFO +7 -0
- flux_constraint-0.1.0/README.md +17 -0
- flux_constraint-0.1.0/flux_constraint/__init__.py +38 -0
- flux_constraint-0.1.0/flux_constraint.egg-info/PKG-INFO +7 -0
- flux_constraint-0.1.0/flux_constraint.egg-info/SOURCES.txt +7 -0
- flux_constraint-0.1.0/flux_constraint.egg-info/dependency_links.txt +1 -0
- flux_constraint-0.1.0/flux_constraint.egg-info/top_level.txt +1 -0
- flux_constraint-0.1.0/setup.cfg +4 -0
- flux_constraint-0.1.0/setup.py +8 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Flux Constraint Python
|
|
2
|
+
|
|
3
|
+
Python bindings matching FM's constraint engine API. INT8 saturated arithmetic, Constraint/ConstraintSet/ConstraintResult types, industry presets (aviation, medical, maritime, automotive).
|
|
4
|
+
|
|
5
|
+
Matches:
|
|
6
|
+
- `flux_constraint.rs` — Rust constraint struct and saturate
|
|
7
|
+
- `flux_check.wgsl` — WebGPU compute shader API
|
|
8
|
+
- `flux_production_v2.cu` — CUDA kernel patterns
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
from flux_constraint import load_preset, Constraint
|
|
12
|
+
|
|
13
|
+
aviation = load_preset("aviation")
|
|
14
|
+
results = aviation.evaluate([100, 30000, 5])
|
|
15
|
+
for r in results:
|
|
16
|
+
print(f"{r.constraint.name}: {r.value} {'PASS' if r.passed else 'FAIL'} mask={r.error_mask}")
|
|
17
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Flux Constraint Python — Python bindings for FM's constraint engine."""
|
|
2
|
+
INT8_MIN = -127; INT8_MAX = 127
|
|
3
|
+
|
|
4
|
+
def saturate(val):
|
|
5
|
+
if val < INT8_MIN: return INT8_MIN
|
|
6
|
+
if val > INT8_MAX: return INT8_MAX
|
|
7
|
+
return val
|
|
8
|
+
|
|
9
|
+
class Constraint:
|
|
10
|
+
def __init__(self, name, lo, hi, severity="critical"):
|
|
11
|
+
self.name, self.lo, self.hi, self.severity = name, lo, hi, severity
|
|
12
|
+
def check(self, value):
|
|
13
|
+
c = saturate(value)
|
|
14
|
+
return ConstraintResult(self, c, self.lo <= c <= self.hi, c < self.lo, c > self.hi)
|
|
15
|
+
|
|
16
|
+
class ConstraintResult:
|
|
17
|
+
def __init__(self, constraint, value, passed, vl, vh):
|
|
18
|
+
self.constraint, self.value, self.passed, self.violated_lo, self.violated_hi = constraint, value, passed, vl, vh
|
|
19
|
+
@property
|
|
20
|
+
def error_mask(self):
|
|
21
|
+
return (1 if self.violated_lo else 0) | (2 if self.violated_hi else 0)
|
|
22
|
+
|
|
23
|
+
class ConstraintSet:
|
|
24
|
+
def __init__(self, constraints=None, name="default"):
|
|
25
|
+
self.constraints = constraints or []; self.name = name
|
|
26
|
+
def add(self, c): self.constraints.append(c)
|
|
27
|
+
def evaluate(self, values):
|
|
28
|
+
return [c.check(v) for c in self.constraints for v in values]
|
|
29
|
+
|
|
30
|
+
PRESETS = {
|
|
31
|
+
"aviation": [Constraint("altitude",-100,50000), Constraint("speed",0,250), Constraint("vspeed",-20,20,"warning")],
|
|
32
|
+
"medical": [Constraint("hr",30,220), Constraint("bpsys",70,200), Constraint("bpdia",40,120,"warning"), Constraint("spo2",85,100)],
|
|
33
|
+
"maritime": [Constraint("depth",0,12000), Constraint("heading",0,360,"warning"), Constraint("speed",0,60,"warning")],
|
|
34
|
+
"automotive": [Constraint("rpm",0,8000,"warning"), Constraint("coolant",-40,120), Constraint("oil",0,100)],
|
|
35
|
+
}
|
|
36
|
+
def load_preset(name):
|
|
37
|
+
if name in PRESETS: return ConstraintSet(PRESETS[name], name=name)
|
|
38
|
+
raise ValueError(f"Unknown preset: {name}")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
flux_constraint
|