1
0

fix: use circuit compute trait in lut resolver

This commit is contained in:
2026-06-25 12:40:29 +08:00
parent 826dda9841
commit 21a625b054

View File

@@ -1,10 +1,9 @@
import bisect
from itertools import chain, product
from functools import cached_property
from itertools import chain
from .common import Resolver
from .bfs import BfsResolver
from ..dataset import DatasetCollection, Dataset
from ..common import Circuit, DeviceKind, JointKind, CircuitValueTrait
from ..common import Circuit, DeviceKind, CircuitValueTrait
from ..query import Request, Response
@@ -91,6 +90,7 @@ class LutResolver(Resolver):
# target. This guarantees items are visited in strictly increasing
# difference order, so the first N items within tolerance are exactly
# the N best matches.
cv_trait = CircuitValueTrait(request.device_kind, target)
while left >= 0 or right < len(lut):
if len(bucket) >= count_limit:
break
@@ -100,7 +100,15 @@ class LutResolver(Resolver):
elif right >= len(lut):
go_left = True
else:
go_left = (target - lut[left].value) <= (lut[right].value - target)
left_instance = lut[left]
left_diff = cv_trait.unsigned_difference(
left_instance.circuit, value=left_instance.value
)
right_instance = lut[right]
right_diff = cv_trait.unsigned_difference(
right_instance.circuit, value=right_instance.value
)
go_left = left_diff <= right_diff
if go_left:
item = lut[left]
@@ -109,7 +117,7 @@ class LutResolver(Resolver):
item = lut[right]
right += 1
diff = abs(target - item.value)
diff = cv_trait.unsigned_difference(item.circuit, value=item.value)
# Since the LUT is sorted, values on each side only move further
# from target as we advance. Once one side exceeds tolerance,
# the rest of that side is guaranteed out of range — disable it.