Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
@@ -9,6 +10,7 @@ import terrain_costs as costs
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
parser.add_argument("--terrain", type=Path)
|
||||
args = parser.parse_args()
|
||||
assert costs._NATIVE is not None, "Compiled implementation must be installed"
|
||||
engine = costs._NATIVE
|
||||
@@ -27,5 +29,52 @@ for points in cases:
|
||||
expected = costs.connected_grade(points)
|
||||
costs._NATIVE = engine
|
||||
assert costs.connected_grade(points) == expected
|
||||
args.output.write_text(json.dumps({"passed": True, "cases": len(cases)}))
|
||||
print(json.dumps({"passed": True, "cases": len(cases)}))
|
||||
neighborhood_cases = 0
|
||||
for dtype in (np.float32, np.float64):
|
||||
for offset in (0, -240, 1000):
|
||||
points = rng.uniform(-2, 2, (600, 4)).astype(dtype)
|
||||
points[:, :2] += offset
|
||||
# Include exact radius/cell boundaries, negative cells and duplicates.
|
||||
points[:7, :3] = (
|
||||
np.array(
|
||||
[
|
||||
[0, 0, 0],
|
||||
[0.4, 0, 0],
|
||||
[-0.4, 0, 0],
|
||||
[0.399999, 0, 0],
|
||||
[0.400001, 0, 0],
|
||||
[0, 0.4, 0],
|
||||
[0, 0, 0],
|
||||
],
|
||||
dtype=dtype,
|
||||
)
|
||||
+ offset
|
||||
)
|
||||
reference = costs._reference_neighborhoods(points)
|
||||
native = costs._NativeNeighborhoods(points)
|
||||
for index in range(len(points)):
|
||||
assert np.array_equal(native(index), reference(index)), (dtype, offset, index)
|
||||
neighborhood_cases += 1
|
||||
costs._NATIVE = None
|
||||
expected, count = costs.supported_slope_costs(points)
|
||||
costs._NATIVE = engine
|
||||
actual, native_count = costs.supported_slope_costs(points)
|
||||
assert native_count == count and np.array_equal(actual, expected)
|
||||
timings = {}
|
||||
if args.terrain:
|
||||
terrain = np.load(args.terrain)
|
||||
for name, implementation in (("reference", None), ("native", engine)):
|
||||
costs._NATIVE = implementation
|
||||
normalize = costs.TerrainCostNormalizer()
|
||||
timings[name] = []
|
||||
for _ in range(5):
|
||||
started = time.monotonic()
|
||||
result, corrected = normalize(terrain)
|
||||
timings[name].append((time.monotonic() - started) * 1000)
|
||||
if name == "reference":
|
||||
expected, count = result, corrected
|
||||
else:
|
||||
assert np.array_equal(result, expected) and count == corrected
|
||||
report = dict(passed=True, cases=len(cases), neighborhoods=neighborhood_cases, timings_ms=timings)
|
||||
args.output.write_text(json.dumps(report))
|
||||
print(json.dumps(report))
|
||||
|
||||
Reference in New Issue
Block a user