diffct 2.5.0__py3-none-any.whl → 2.5.2__py3-none-any.whl
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.
- diffct/__init__.py +1 -1
- diffct/_solver_state.py +13 -2
- diffct/analytical_execution.py +24 -6
- diffct/backends.py +251 -137
- diffct/chunking.py +14 -10
- diffct/distribution.py +27 -0
- diffct/geometry.py +15 -8
- diffct/kernels/__init__.py +6 -0
- diffct/kernels/parallel3d_beam.py +357 -0
- diffct/operators.py +193 -104
- diffct/projectors.py +32 -15
- diffct/solvers.py +11 -3
- diffct/streaming.py +36 -5
- diffct/utils.py +52 -6
- {diffct-2.5.0.dist-info → diffct-2.5.2.dist-info}/METADATA +2 -2
- diffct-2.5.2.dist-info/RECORD +35 -0
- {diffct-2.5.0.dist-info → diffct-2.5.2.dist-info}/WHEEL +1 -1
- diffct-2.5.0.dist-info/RECORD +0 -34
- {diffct-2.5.0.dist-info → diffct-2.5.2.dist-info}/licenses/LICENSE +0 -0
- {diffct-2.5.0.dist-info → diffct-2.5.2.dist-info}/licenses/NOTICE +0 -0
diffct/__init__.py
CHANGED
diffct/_solver_state.py
CHANGED
|
@@ -288,6 +288,11 @@ def save_checkpoint(operator, directory, states, metadata, iteration, history, m
|
|
|
288
288
|
step = Path(directory).resolve() / f"step-{iteration:06d}"
|
|
289
289
|
step.mkdir(parents=True, exist_ok=True)
|
|
290
290
|
rank = step / f"rank-{getattr(operator, 'rank', 0):05d}"
|
|
291
|
+
if rank.exists():
|
|
292
|
+
# Replacing a published step in place could destroy it on a
|
|
293
|
+
# failed write, and ranks cannot roll back together.
|
|
294
|
+
raise ValueError(f"checkpoint {rank} already exists; use a new checkpoint_directory "
|
|
295
|
+
"or pass resume= to continue from it")
|
|
291
296
|
rank.mkdir()
|
|
292
297
|
for name, source in states.items():
|
|
293
298
|
source = TensorStore(source.detach()) if isinstance(source, torch.Tensor) else source
|
|
@@ -323,10 +328,16 @@ def callbacks_enabled(operator, callback):
|
|
|
323
328
|
world_size=getattr(operator, "world_size", 1))[0])
|
|
324
329
|
|
|
325
330
|
|
|
326
|
-
def callback_stop(operator, callback, iteration, residual, volume
|
|
331
|
+
def callback_stop(operator, callback, iteration, residual, volume, *, readonly=False,
|
|
332
|
+
block_elements=1048576):
|
|
327
333
|
error, stop = None, False
|
|
328
334
|
try:
|
|
329
|
-
|
|
335
|
+
if callback is not None:
|
|
336
|
+
before = (fingerprint(volume, block_elements), getattr(volume, "device", None)) if readonly else None
|
|
337
|
+
stop = callback(iteration, residual, volume) is False
|
|
338
|
+
if readonly and ((isinstance(volume, torch.Tensor) and not torch.is_floating_point(volume))
|
|
339
|
+
or (fingerprint(volume, block_elements), getattr(volume, "device", None)) != before):
|
|
340
|
+
raise ValueError("CGLS callback iterate is read-only")
|
|
330
341
|
except Exception as caught:
|
|
331
342
|
error = caught
|
|
332
343
|
failed, stop = control_status((int(error is not None), int(stop)),
|
diffct/analytical_execution.py
CHANGED
|
@@ -21,7 +21,9 @@ from .chunking import _memory_budget, _pixel_tiles
|
|
|
21
21
|
from .distribution import Partition, preflight
|
|
22
22
|
from .operators import _detector_spacing, _normalize_devices, _positive_int, _shape, _validate_trajectory
|
|
23
23
|
from .reconstruction import _angles, _cosine, _filter, _fixed, _parker_setup
|
|
24
|
-
from .streaming import _as_store,
|
|
24
|
+
from .streaming import (_as_store, _backing_store, _backing_tensor, _store_phase,
|
|
25
|
+
_store_rounds, _tensor_overlap, _validate_stores)
|
|
26
|
+
from .storage import NpyStore
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
def _weight(value, shape, name, *, exact=False):
|
|
@@ -351,7 +353,7 @@ class AnalyticalExecution:
|
|
|
351
353
|
return cone_weighted_backproject(data, *geometry, *shape, *self.pitch,
|
|
352
354
|
self.voxel_spacing, isocenter=isocenter)
|
|
353
355
|
|
|
354
|
-
def _tile(self, spatial):
|
|
356
|
+
def _tile(self, spatial, *, reduce=True):
|
|
355
357
|
shape = tuple(part.stop - part.start for part in spatial)
|
|
356
358
|
value = torch.zeros(shape, device=self.output_device, dtype=self.dtype)
|
|
357
359
|
if self.input_dependency is not None:
|
|
@@ -361,7 +363,7 @@ class AnalyticalExecution:
|
|
|
361
363
|
partial = (self._native_gather(filtered, geometry, spatial) if self.backend == "numba"
|
|
362
364
|
else self._portable_gather(filtered, geometry, views, spatial))
|
|
363
365
|
value = value + partial.to(self.output_device)
|
|
364
|
-
return _sum(value, self.partition.view_group, self.partition.view_world_size)
|
|
366
|
+
return _sum(value, self.partition.view_group, self.partition.view_world_size) if reduce else value
|
|
365
367
|
|
|
366
368
|
def _prepare_gradients(self):
|
|
367
369
|
partition = self.partition
|
|
@@ -426,17 +428,33 @@ class AnalyticalExecution:
|
|
|
426
428
|
error, source, sink = None, None, None
|
|
427
429
|
try:
|
|
428
430
|
source, sink = _validate_stores(self, self.source, output, False)
|
|
431
|
+
output_tensor = _backing_tensor(sink)
|
|
432
|
+
backing = _backing_store(sink)
|
|
433
|
+
if isinstance(backing, NpyStore):
|
|
434
|
+
output_tensor = torch.from_numpy(backing._array)
|
|
429
435
|
for option in (self.projection_weights, self.angular_weights, self.filter_response):
|
|
430
436
|
if isinstance(option, torch.Tensor) and option.requires_grad:
|
|
431
437
|
raise ValueError("into methods are numerical; detach autograd weights")
|
|
438
|
+
if (isinstance(option, torch.Tensor) and isinstance(output_tensor, torch.Tensor)
|
|
439
|
+
and _tensor_overlap(option, output_tensor)):
|
|
440
|
+
raise ValueError("analytical weights and output stores overlap")
|
|
432
441
|
except (ValueError, TypeError, RuntimeError, OSError) as caught:
|
|
433
442
|
error = caught
|
|
434
443
|
self.partition.preflight(error)
|
|
435
444
|
self.source = source
|
|
436
445
|
with torch.no_grad():
|
|
437
|
-
for
|
|
438
|
-
|
|
439
|
-
|
|
446
|
+
for job in _store_rounds(_pixel_tiles(self.volume_shape, self.chunk_shape), self.partition):
|
|
447
|
+
with _store_phase(self.partition):
|
|
448
|
+
if job is not None:
|
|
449
|
+
spatial, _ = job
|
|
450
|
+
value = self._tile(spatial, reduce=False)
|
|
451
|
+
if job is not None:
|
|
452
|
+
value = _sum(value, self.partition.view_group, self.partition.view_world_size)
|
|
453
|
+
with _store_phase(self.partition):
|
|
454
|
+
if job is not None:
|
|
455
|
+
sink.write(spatial, value)
|
|
456
|
+
with _store_phase(self.partition):
|
|
457
|
+
sink.flush()
|
|
440
458
|
return original
|
|
441
459
|
|
|
442
460
|
|