Skip to content

Commit

Permalink
fix(edits/split): filter out inactive cross edges
Browse files Browse the repository at this point in the history
  • Loading branch information
akhileshh committed Sep 3, 2024
1 parent a74197e commit 4ad9184
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
15 changes: 14 additions & 1 deletion pychunkedgraph/graph/chunkedgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,11 @@ def copy_fake_edges(self, chunk_id: np.uint64) -> None:
self.client.write(mutations)

def get_l2_agglomerations(
self, level2_ids: np.ndarray, edges_only: bool = False
self,
level2_ids: np.ndarray,
edges_only: bool = False,
active: bool = False,
time_stamp: typing.Optional[datetime.datetime] = None,
) -> typing.Tuple[typing.Dict[int, types.Agglomeration], typing.Tuple[Edges]]:
"""
Children of Level 2 Node IDs and edges.
Expand Down Expand Up @@ -703,6 +707,15 @@ def get_l2_agglomerations(
raise ValueError("Found conflicting parents.")
sv_parent_d.update(dict(zip(svs.tolist(), [l2id] * len(svs))))

if active:
n1, n2 = all_chunk_edges.node_ids1, all_chunk_edges.node_ids2
layers = self.get_cross_chunk_edges_layer(all_chunk_edges.get_pairs())
max_layer = np.max(layers) + 1
parents1 = self.get_roots(n1, stop_layer=max_layer, time_stamp=time_stamp)
parents2 = self.get_roots(n2, stop_layer=max_layer, time_stamp=time_stamp)
mask = parents1 == parents2
all_chunk_edges = all_chunk_edges[mask]

in_edges, out_edges, cross_edges = edge_utils.categorize_edges_v2(
self.meta, all_chunk_edges, sv_parent_d
)
Expand Down
7 changes: 4 additions & 3 deletions pychunkedgraph/graph/edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def remove_edges(
cg,
*,
atomic_edges: Iterable[np.ndarray],
l2id_agglomeration_d: Dict,
operation_id: basetypes.OPERATION_ID = None,
time_stamp: datetime.datetime = None,
parent_ts: datetime.datetime = None,
Expand All @@ -323,6 +322,9 @@ def remove_edges(
roots = cg.get_roots(l2ids, assert_roots=True, time_stamp=parent_ts)
assert np.unique(roots).size == 1, "L2 IDs must belong to same root."

l2id_agglomeration_d, _ = cg.get_l2_agglomerations(
l2ids, active=True, time_stamp=parent_ts
)
new_old_id_d = defaultdict(set)
old_new_id_d = defaultdict(set)
old_hierarchy_d = _init_old_hierarchy(cg, l2ids, parent_ts=parent_ts)
Expand Down Expand Up @@ -409,7 +411,6 @@ def _get_descendants(cg, new_id):
return result



def _update_neighbor_cross_edges_single(
cg, new_id: int, cx_edges_d: dict, node_map: dict, *, parent_ts
) -> dict:
Expand Down Expand Up @@ -498,7 +499,7 @@ def _update_neighbor_cross_edges(

def _get_supervoxels(cg, node_ids):
"""Returns the first supervoxel found for each node_id."""
result = {}
result = {}
node_ids_copy = np.copy(node_ids)
children = np.copy(node_ids)
children_d = cg.get_children(node_ids)
Expand Down
10 changes: 1 addition & 9 deletions pychunkedgraph/graph/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def _apply(
operation_id=operation_id,
time_stamp=timestamp,
parent_ts=self.parent_ts,
allow_same_segment_merge=self.allow_same_segment_merge
allow_same_segment_merge=self.allow_same_segment_merge,
)
return new_roots, new_l2_ids, fake_edge_rows + new_entries

Expand Down Expand Up @@ -751,18 +751,11 @@ def _apply(
):
raise PreconditionError("Supervoxels must belong to the same object.")

with TimeIt("subgraph", self.cg.graph_id, operation_id):
l2id_agglomeration_d, _ = self.cg.get_l2_agglomerations(
self.cg.get_parents(
self.removed_edges.ravel(), time_stamp=self.parent_ts
),
)
with TimeIt("remove_edges", self.cg.graph_id, operation_id):
return edits.remove_edges(
self.cg,
operation_id=operation_id,
atomic_edges=self.removed_edges,
l2id_agglomeration_d=l2id_agglomeration_d,
time_stamp=timestamp,
parent_ts=self.parent_ts,
)
Expand Down Expand Up @@ -929,7 +922,6 @@ def _apply(
self.cg,
operation_id=operation_id,
atomic_edges=self.removed_edges,
l2id_agglomeration_d=l2id_agglomeration_d,
time_stamp=timestamp,
parent_ts=self.parent_ts,
)
Expand Down
11 changes: 9 additions & 2 deletions pychunkedgraph/repair/edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
from pychunkedgraph.graph.operation import GraphEditOperation


def _get_previous_log_ts(cg, operation):
log, previous_ts = cg.client.read_log_entry(operation - 1)
if log:
return previous_ts
return _get_previous_log_ts(cg, operation-1)


def repair_operation(
cg: ChunkedGraph,
operation_id: int,
Expand All @@ -20,8 +27,8 @@ def repair_operation(
_, current_ts = cg.client.read_log_entry(operation_id)
parent_ts = current_ts - timedelta(milliseconds=10)
if operation_id > 1 and use_preceding_edit_ts:
_, previous_ts = cg.client.read_log_entry(operation_id - 1)
parent_ts = previous_ts + timedelta(milliseconds=200)
previous_ts = _get_previous_log_ts(cg, operation_id)
parent_ts = previous_ts + timedelta(milliseconds=100)

result = operation.execute(
operation_id=operation_id,
Expand Down

0 comments on commit 4ad9184

Please sign in to comment.